-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-31819: Add AbstractEventLoop.sock_recv_into() #4051
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
Conversation
| raise ValueError("the socket must be non-blocking") | ||
| fut = self.create_future() | ||
| self._sock_recv_into(fut, False, sock, buf) | ||
| return fut |
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.
If you want, you can further optimize this by transforming sock_recv_into into an async def coroutine, and creating the fut object only when sock.recv_into(buf) fails with a BlockingError.
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.
I don't think that's very useful, as people will mainly want to use that for large data. Right now the implementation mirrors that of sock_recv, which is easier to understand.
Mirrors asyncio PR: python/cpython#4051
|
@pitrou FWIW I've added |
|
Great! Thank you @1st1. |
| else: | ||
| ov.ReadFileInto(conn.fileno(), buf) | ||
| except BrokenPipeError: | ||
| return self._result(b'') |
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.
The doc says "The return value is the number of bytes written." but here an empty byte string is returned! I created https://bugs.python.org/issue41467 to track this bug.
Mirrors asyncio PR: python/cpython#4051
https://bugs.python.org/issue31819