You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add low level UDP socket functions to asyncio #90961
The asyncio module currently has a number of low-level functions for working asynchronously with raw socket objects. Such functions for working with UDP sockets are, however, notably absent, and there is no workaround for this. You can of course use sock_receive() with UDP sockets but that would discard the sender address which is a showstopper problem. Also, having a send function that applies back pressure to the sender if the kernel buffer is full would also be prudent.
I will provide a PR if you're okay with this.
It would include the following functions:
One question: should I add the "flags" argument to the new functions? For some reason it's missing from the existing functions, so maybe I should add that in a separate PR?
Sorry, I was not clear maybe.
Newly added methods can have a flag argument from the very beginning.
Adding a flag to already existing methods requires a separate issue.
agronholm commented on Feb 20, 2022
agronholmmannequin
MannequinAuthor
More actions
Yeah, my question was specific about the new functions, so I understood that a separate PR should add that to the all the relevant functions.
I have a different problem now however: the test suite is failing in CI but not locally. It's giving me NameError about a function used by existing tests but for some reason, it's not defined in the scope of the new test functions?!?
The proactor version of sock_recvfrom_into() is giving me quite a bit of trouble, as it seems to require heavy handed changes in _overlapped.c.
I'm also not very successful in testing cases where sendto() would fill the kernel buffer and raise BlockingIOError. With TCP this is easy but with UDP near impossible to do in a controlled fashion in the test suite.
Activity
agronholm commentedon Feb 20, 2022
The asyncio module currently has a number of low-level functions for working asynchronously with raw socket objects. Such functions for working with UDP sockets are, however, notably absent, and there is no workaround for this. You can of course use sock_receive() with UDP sockets but that would discard the sender address which is a showstopper problem. Also, having a send function that applies back pressure to the sender if the kernel buffer is full would also be prudent.
I will provide a PR if you're okay with this.
It would include the following functions:
agronholm commentedon Feb 20, 2022
One question: should I add the "flags" argument to the new functions? For some reason it's missing from the existing functions, so maybe I should add that in a separate PR?
asvetlov commentedon Feb 20, 2022
A separate issue for 'flags' adding looks better. The reason for missing is an oversight I think.
asvetlov commentedon Feb 20, 2022
Sorry, I was not clear maybe.
Newly added methods can have a
flagargument from the very beginning.Adding a flag to already existing methods requires a separate issue.
agronholm commentedon Feb 20, 2022
Yeah, my question was specific about the new functions, so I understood that a separate PR should add that to the all the relevant functions.
I have a different problem now however: the test suite is failing in CI but not locally. It's giving me NameError about a function used by existing tests but for some reason, it's not defined in the scope of the new test functions?!?
The proactor version of sock_recvfrom_into() is giving me quite a bit of trouble, as it seems to require heavy handed changes in _overlapped.c.
I'm also not very successful in testing cases where sendto() would fill the kernel buffer and raise BlockingIOError. With TCP this is easy but with UDP near impossible to do in a controlled fashion in the test suite.
asvetlov commentedon Mar 13, 2022
New changeset 9f04ee5 by Alex Grönholm in branch 'main':
bpo-46805: Add low level UDP socket functions to asyncio (GH-31455)
9f04ee5