MCPcopy
hub / github.com/aio-libs/aiohttp / _sendfile_system

Method _sendfile_system

aiohttp/web_urldispatcher.py:505–535  ·  view source on GitHub ↗

Write `count` bytes of `fobj` to `resp` starting from `offset` using the ``sendfile`` system call. `req` should be a :obj:`aiohttp.web.Request` instance. `resp` should be a :obj:`aiohttp.web.StreamResponse` instance. `fobj` should be an open file object.

(self, req, resp, fobj, count)

Source from the content-addressed store, hash-verified

503
504 @asyncio.coroutine
505 def _sendfile_system(self, req, resp, fobj, count):
506 """
507 Write `count` bytes of `fobj` to `resp` starting from `offset` using
508 the ``sendfile`` system call.
509
510 `req` should be a :obj:`aiohttp.web.Request` instance.
511
512 `resp` should be a :obj:`aiohttp.web.StreamResponse` instance.
513
514 `fobj` should be an open file object.
515
516 `offset` should be an integer >= 0.
517
518 `count` should be an integer > 0.
519 """
520 transport = req.transport
521
522 if transport.get_extra_info("sslcontext"):
523 yield from self._sendfile_fallback(req, resp, fobj, count)
524 return
525
526 yield from resp.drain()
527
528 loop = req.app.loop
529 out_fd = transport.get_extra_info("socket").fileno()
530 in_fd = fobj.fileno()
531 fut = asyncio.Future(loop=loop)
532
533 self._sendfile_cb(fut, out_fd, in_fd, 0, count, loop, False)
534
535 yield from fut
536
537 @asyncio.coroutine
538 def _sendfile_fallback(self, req, resp, fobj, count):

Callers

nothing calls this directly

Calls 3

_sendfile_fallbackMethod · 0.95
_sendfile_cbMethod · 0.95
drainMethod · 0.80

Tested by

no test coverage detected