(self, sock, file, offset, count)
| 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'): |
no test coverage detected