This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add low level UDP socket functions to asyncio
Type: enhancement Stage: resolved
Components: asyncio Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alex.gronholm, asvetlov, yselivanov
Priority: normal Keywords: patch

Created on 2022-02-20 10:27 by alex.gronholm, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31455 merged alex.gronholm, 2022-02-20 20:46
Messages (6)
msg413579 - (view) Author: Alex Grönholm (alex.gronholm) * Date: 2022-02-20 10:27
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:

* sock_sendto()
* sock_recvfrom()
* sock_recvfrom_into()
msg413581 - (view) Author: Alex Grönholm (alex.gronholm) * Date: 2022-02-20 11:49
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?
msg413582 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-02-20 12:11
A separate issue for 'flags' adding looks better. The reason for missing is an oversight I think.
msg413616 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-02-20 23:17
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.
msg413617 - (view) Author: Alex Grönholm (alex.gronholm) * Date: 2022-02-20 23:22
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.
msg415041 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-03-13 16:42
New changeset 9f04ee569cebb8b4c6f04bea95d91a19c5403806 by Alex Grönholm in branch 'main':
bpo-46805: Add low level UDP socket functions to asyncio (GH-31455)
https://github.com/python/cpython/commit/9f04ee569cebb8b4c6f04bea95d91a19c5403806
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90961
2022-03-13 16:43:13asvetlovsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-03-13 16:42:40asvetlovsetmessages: + msg415041
2022-02-20 23:22:28alex.gronholmsetmessages: + msg413617
2022-02-20 23:17:01asvetlovsetmessages: + msg413616
2022-02-20 20:46:19alex.gronholmsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29583
2022-02-20 12:11:08asvetlovsetmessages: + msg413582
2022-02-20 11:49:18alex.gronholmsetmessages: + msg413581
2022-02-20 10:27:09alex.gronholmcreate