-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
bpo-32410: Implement loop.sock_sendfile() #4976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ee13d5b
8b610ad
8d658be
24c5a28
10b0b61
5f782a5
3068aa9
898766e
6e70a62
20b3778
7ed0e67
f4b61b1
6f6b94b
1c05795
f670fad
26f6d4a
87d4804
76eeef5
35071ea
92ae10b
8c451d2
921fe69
0f2a48f
1cc0e8f
272029e
fa0954e
0ddb410
c18c3c8
a4a174b
448e949
46c92ed
8dd45dc
c9112b9
b6273e4
4d88063
71b9f93
db2445e
46a6b46
2ec48f8
8a6ed3f
44da800
967408e
099dc56
f9701cb
a30acc9
f7d9bab
4d25927
e303db9
84e1057
657aa67
dd4143a
96d0032
5deb0e2
3c9abaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -653,17 +653,17 @@ async def sock_sendfile(self, sock, file, offset=0, count=None, | |
| raise ValueError("the socket must be non-blocking") | ||
| socket._check_sendfile_params(sock, file, offset, count) | ||
| try: | ||
| await self._sock_sf_fast(sock, file, offset, count) | ||
| await self._sock_sendfile_native(sock, file, offset, count) | ||
| except RuntimeError: | ||
| if fallback: | ||
| await self._sock_sf_fallback(sock, file, offset, count) | ||
| else: | ||
| raise | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proposed message text is not always correct: sometimes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case let's make the exception public. I'd rename it to |
||
|
|
||
| async def _sock_sf_fast(self, sock, file, offset=0, count=None): | ||
| async def _sock_sendfile_native(self, sock, file, offset=0, count=None): | ||
| raise RuntimeError("Fast sendfile is not available") | ||
|
|
||
| async def _sock_sf_fallback(self, sock, file, offset=0, count=None): | ||
| async def _sock_send_fallback(self, sock, file, offset=0, count=None): | ||
| if offset: | ||
| file.seek(offset) | ||
| blocksize = min(count, 16384) if count else 16384 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -309,7 +309,7 @@ async def create_unix_server( | |
| ssl_handshake_timeout=ssl_handshake_timeout) | ||
| return server | ||
|
|
||
| async def _sock_sf_fast(self, sock, file, offset=0, count=None): | ||
| async def _sock_sendfile_native(self, sock, file, offset=0, count=None): | ||
| try: | ||
| os.sendfile | ||
| except AttributeError as exc: | ||
|
|
@@ -320,12 +320,12 @@ async def _sock_sf_fast(self, sock, file, offset=0, count=None): | |
|
|
||
| fut = self.create_future() | ||
| fd = sock.fileno() | ||
| self._sock_sf_fast_impl(fut, None, fd, fileno, | ||
| offset, count, blocksize, 0) | ||
| self._sock_sendfile_native_impl(fut, None, fd, fileno, | ||
| offset, count, blocksize, 0) | ||
| return await fut | ||
|
|
||
| def _sock_sf_fast_impl(self, fut, registered_fd, fd, fileno, offset, | ||
| count, blocksize, total_sent): | ||
| def _sock_sendfile_native_impl(self, fut, registered_fd, fd, fileno, | ||
| offset, count, blocksize, total_sent): | ||
| if registered_fd is not None: | ||
| # Remove the callback early. It should be rare that the | ||
| # selector says the fd is ready but the call still returns | ||
|
|
@@ -345,7 +345,7 @@ def _sock_sf_fast_impl(self, fut, registered_fd, fd, fileno, offset, | |
| try: | ||
| sent = os.sendfile(fd, fileno, offset, blocksize) | ||
| except (BlockingIOError, InterruptedError): | ||
| self.add_writer(fd, self._sock_sf_fast_impl, fut, fd, fd, | ||
| self.add_writer(fd, self._sock_sendfile_native_impl, fut, fd, fd, | ||
| fileno, offset, count, blocksize. total_sent) | ||
| except OSError as exc: | ||
| if total_sent == 0: | ||
|
|
@@ -370,8 +370,9 @@ def _sock_sf_fast_impl(self, fut, registered_fd, fd, fileno, offset, | |
| else: | ||
| offset += sent | ||
| total_sent += sent | ||
| self.add_writer(fd, self._sock_sf_fast_impl, fut, fd, fd, | ||
| fileno, offset, count, blocksize, total_sent) | ||
| self.add_writer(fd, self._sock_sendfile_native_impl, fut, | ||
| fd, fd, fileno, | ||
| offset, count, blocksize, total_sent) | ||
|
|
||
| def _update_filepos(self, fileno, offset, total_sent): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to |
||
| if total_sent > 0: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
many things in sock_sendfile_native can cause a RuntimeError that this code will mask. I recommend to just add
hasattr(os, 'sendfile')There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or add a private exception class (not exported and with a leading underscore)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting migration.
Private exception class -> NotImplementedError -> RuntimeError -> private exception again.
I'm ok with custom exception, it is the best choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, Andrew ;) Sometimes it's hard to see the big picture when we just start working on a new big PR
Happy New Year, by the way!!