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

Method _sock_sendfile_native

Lib/asyncio/proactor_events.py:733–760  ·  view source on GitHub ↗
(self, sock, file, offset, count)

Source from the content-addressed store, hash-verified

731 return await self._proactor.accept(sock)
732
733 async def _sock_sendfile_native(self, sock, file, offset, count):
734 try:
735 fileno = file.fileno()
736 except (AttributeError, io.UnsupportedOperation):
737 raise exceptions.SendfileNotAvailableError("not a regular file")
738 try:
739 fsize = os.fstat(fileno).st_size
740 except OSError:
741 raise exceptions.SendfileNotAvailableError("not a regular file")
742 blocksize = count if count else fsize
743 if not blocksize:
744 return 0 # empty file
745
746 blocksize = min(blocksize, 0xffff_ffff)
747 end_pos = min(offset + count, fsize) if count else fsize
748 offset = min(offset, fsize)
749 total_sent = 0
750 try:
751 while True:
752 blocksize = min(end_pos - offset, blocksize)
753 if blocksize <= 0:
754 return total_sent
755 await self._proactor.sendfile(sock, file, offset, blocksize)
756 offset += blocksize
757 total_sent += blocksize
758 finally:
759 if total_sent > 0:
760 file.seek(offset)
761
762 async def _sendfile_native(self, transp, file, offset, count):
763 resume_reading = transp.is_reading()

Callers

nothing calls this directly

Calls 3

filenoMethod · 0.45
sendfileMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected