| 482 | 'prefix': self._prefix} |
| 483 | |
| 484 | def _sendfile_cb(self, fut, out_fd, in_fd, offset, count, loop, |
| 485 | registered): |
| 486 | if registered: |
| 487 | loop.remove_writer(out_fd) |
| 488 | try: |
| 489 | n = os.sendfile(out_fd, in_fd, offset, count) |
| 490 | if n == 0: # EOF reached |
| 491 | n = count |
| 492 | except (BlockingIOError, InterruptedError): |
| 493 | n = 0 |
| 494 | except Exception as exc: |
| 495 | fut.set_exception(exc) |
| 496 | return |
| 497 | |
| 498 | if n < count: |
| 499 | loop.add_writer(out_fd, self._sendfile_cb, fut, out_fd, in_fd, |
| 500 | offset + n, count - n, loop, True) |
| 501 | else: |
| 502 | fut.set_result(None) |
| 503 | |
| 504 | @asyncio.coroutine |
| 505 | def _sendfile_system(self, req, resp, fobj, count): |