MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _sendfile_use_send

Method _sendfile_use_send

tools/python-3.11.9-amd64/Lib/socket.py:417–451  ·  view source on GitHub ↗
(self, file, offset=0, count=None)

Source from the content-addressed store, hash-verified

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

Callers 2

sendfileMethod · 0.95
sendfileMethod · 0.80

Calls 4

minFunction · 0.85
gettimeoutMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected