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

Method _sendfile_fallback

Lib/asyncio/base_events.py:1296–1319  ·  view source on GitHub ↗
(self, transp, file, offset, count)

Source from the content-addressed store, hash-verified

1294 "sendfile syscall is not supported")
1295
1296 async def _sendfile_fallback(self, transp, file, offset, count):
1297 if offset:
1298 file.seek(offset)
1299 blocksize = min(count, 16384) if count else 16384
1300 buf = bytearray(blocksize)
1301 total_sent = 0
1302 proto = _SendfileFallbackProtocol(transp)
1303 try:
1304 while True:
1305 if count:
1306 blocksize = min(count - total_sent, blocksize)
1307 if blocksize <= 0:
1308 return total_sent
1309 view = memoryview(buf)[:blocksize]
1310 read = await self.run_in_executor(None, file.readinto, view)
1311 if not read:
1312 return total_sent # EOF
1313 transp.write(view[:read])
1314 await proto.drain()
1315 total_sent += read
1316 finally:
1317 if total_sent > 0 and hasattr(file, 'seek'):
1318 file.seek(offset + total_sent)
1319 await proto.restore()
1320
1321 async def start_tls(self, transport, protocol, sslcontext, *,
1322 server_side=False,

Callers 1

sendfileMethod · 0.95

Calls 6

run_in_executorMethod · 0.95
seekMethod · 0.45
writeMethod · 0.45
drainMethod · 0.45
restoreMethod · 0.45

Tested by

no test coverage detected