gh-114887: Perform bitwise comparisons with SOCK_DGRAM and SOCK_STEAM#114888
gh-114887: Perform bitwise comparisons with SOCK_DGRAM and SOCK_STEAM#114888tjhowse wants to merge 1 commit intopython:mainfrom
Conversation
|
The following commit authors need to sign the Contributor License Agreement: |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
| if sock.type != socket.SOCK_DGRAM: | ||
| if not sock.type & socket.SOCK_DGRAM: | ||
| raise ValueError( | ||
| f'A UDP Socket was expected, got {sock!r}') |
There was a problem hiding this comment.
This error message should also change.
|
I need help with this. I don’t know anything about this part of the socket API — is this assumption universally true? |
| elif type == socket.SOCK_DGRAM: | ||
| elif type & socket.SOCK_DGRAM: | ||
| proto = socket.IPPROTO_UDP | ||
| else: |
There was a problem hiding this comment.
Continuing to exclude SOCK_RAW here actually seems like the right thing to do (since raw sockets don't have IP addresses).
If omitting this part of the change doesn't fix the original bug report, then I'd suggest adding SOCK_RAW as its own branch saying something like:
elif type == socket.SOCK_RAW:
# asyncio mishandles raw sockets if `_ipaddr_info` returns `None`,
# so fib about the underlying protocol
proto = socket.IPPROTO_UDP
There was a problem hiding this comment.
This change isn't required to fix our specific problem. I feel fewer side effects would come from preserving the current behaviour.
Details in #114887
This change is technically incorrect as SOCK_STREAM and SOCK_DGRAM are not actually bitwise comparators.