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

Method _sock_sendfile_fallback

Lib/asyncio/base_events.py:970–994  ·  view source on GitHub ↗
(self, sock, file, offset, count)

Source from the content-addressed store, hash-verified

968 f"and file {file!r} combination")
969
970 async def _sock_sendfile_fallback(self, sock, file, offset, count):
971 if offset:
972 file.seek(offset)
973 blocksize = (
974 min(count, constants.SENDFILE_FALLBACK_READBUFFER_SIZE)
975 if count else constants.SENDFILE_FALLBACK_READBUFFER_SIZE
976 )
977 buf = bytearray(blocksize)
978 total_sent = 0
979 try:
980 while True:
981 if count:
982 blocksize = min(count - total_sent, blocksize)
983 if blocksize <= 0:
984 break
985 view = memoryview(buf)[:blocksize]
986 read = await self.run_in_executor(None, file.readinto, view)
987 if not read:
988 break # EOF
989 await self.sock_sendall(sock, view[:read])
990 total_sent += read
991 return total_sent
992 finally:
993 if total_sent > 0 and hasattr(file, 'seek'):
994 file.seek(offset + total_sent)
995
996 def _check_sendfile_params(self, sock, file, offset, count):
997 if 'b' not in getattr(file, 'mode', 'b'):

Callers 1

sock_sendfileMethod · 0.95

Calls 3

run_in_executorMethod · 0.95
seekMethod · 0.45
sock_sendallMethod · 0.45

Tested by

no test coverage detected