MCPcopy Index your code
hub / github.com/python/cpython / _sendfile_use_send

Method _sendfile_use_send

Lib/socket.py:434–468  ·  view source on GitHub ↗
(self, file, offset=0, count=None)

Source from the content-addressed store, hash-verified

432 "os.sendfile() not available on this platform")
433
434 def _sendfile_use_send(self, file, offset=0, count=None):
435 self._check_sendfile_params(file, offset, count)
436 if self.gettimeout() == 0:
437 raise ValueError("non-blocking sockets are not supported")
438 if offset:
439 file.seek(offset)
440 blocksize = min(count, 8192) if count else 8192
441 total_sent = 0
442 # localize variable access to minimize overhead
443 file_read = file.read
444 sock_send = self.send
445 try:
446 while True:
447 if count:
448 blocksize = min(count - total_sent, blocksize)
449 if blocksize <= 0:
450 break
451 data = memoryview(file_read(blocksize))
452 if not data:
453 break # EOF
454 while True:
455 try:
456 sent = sock_send(data)
457 except BlockingIOError:
458 continue
459 else:
460 total_sent += sent
461 if sent < len(data):
462 data = data[sent:]
463 else:
464 break
465 return total_sent
466 finally:
467 if total_sent > 0 and hasattr(file, 'seek'):
468 file.seek(offset + total_sent)
469
470 def _check_sendfile_params(self, file, offset, count):
471 if 'b' not in getattr(file, 'mode', 'b'):

Callers 2

sendfileMethod · 0.95
sendfileMethod · 0.80

Calls 3

gettimeoutMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected