]> granicus.if.org Git - python/commit
bpo-31922: Do not connect UDP sockets when broadcast is allowed (GH-423)
authorVincent Michel <vxgmichel@gmail.com>
Tue, 7 May 2019 17:18:49 +0000 (19:18 +0200)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 7 May 2019 17:18:49 +0000 (10:18 -0700)
commit63deaa5b70108ef441c57728322da6b4321db4fc
tree79e5e4911d6a0d6460d36355d394c969b98f437b
parent91cc01f40eec03ece2d6b04ad9ea786e77707d8d
bpo-31922: Do not connect UDP sockets when broadcast is allowed (GH-423)

*Moved from python/asyncio#493.*

This PR fixes issue python/asyncio#480, as explained in [this comment](https://github.com/python/asyncio/issues/480#issuecomment-278703828).

The `_SelectorDatagramTransport.sendto` method has to be modified ~~so `_sock.sendto` is used in all cases (because it is tricky to reliably tell if the socket is connected or not). Could that be an issue for connected sockets?~~ *EDIT* ... so `_sock.send` is used only if `_sock` is connected.

It also protects `socket.getsockname` against `OSError` in `_SelectorTransport`. This might happen on Windows if the socket is not connected (e.g. for UDP broadcasting).

https://bugs.python.org/issue31922
Lib/asyncio/base_events.py
Lib/asyncio/selector_events.py
Lib/test/test_asyncio/test_base_events.py
Lib/test/test_asyncio/test_selector_events.py
Misc/NEWS.d/next/Library/2018-05-30-01-05-50.bpo-31922.fobsXJ.rst [new file with mode: 0644]