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

Method _sendfile_fallback

aiohttp/web_urldispatcher.py:538–559  ·  view source on GitHub ↗

Mimic the :meth:`_sendfile_system` method, but without using the ``sendfile`` system call. This should be used on systems that don't support the ``sendfile`` system call. To avoid blocking the event loop & to keep memory usage low, `fobj` is transferred in c

(self, req, resp, fobj, count)

Source from the content-addressed store, hash-verified

536
537 @asyncio.coroutine
538 def _sendfile_fallback(self, req, resp, fobj, count):
539 """
540 Mimic the :meth:`_sendfile_system` method, but without using the
541 ``sendfile`` system call. This should be used on systems that don't
542 support the ``sendfile`` system call.
543
544 To avoid blocking the event loop & to keep memory usage low, `fobj` is
545 transferred in chunks controlled by the `chunk_size` argument to
546 :class:`StaticRoute`.
547 """
548 chunk_size = self._chunk_size
549
550 chunk = fobj.read(chunk_size)
551 while chunk and count > chunk_size:
552 resp.write(chunk)
553 yield from resp.drain()
554 count = count - chunk_size
555 chunk = fobj.read(chunk_size)
556
557 if chunk:
558 resp.write(chunk[:count])
559 yield from resp.drain()
560
561 if hasattr(os, "sendfile"): # pragma: no cover
562 _sendfile = _sendfile_system

Callers 1

_sendfile_systemMethod · 0.95

Calls 3

drainMethod · 0.80
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected