MCPcopy Index your code
hub / github.com/RustPython/RustPython / _sendfile_use_send

Method _sendfile_use_send

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

Source from the content-addressed store, hash-verified

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

Callers 2

sendfileMethod · 0.95
sendfileMethod · 0.80

Calls 6

minFunction · 0.85
lenFunction · 0.85
hasattrFunction · 0.85
gettimeoutMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected