diff options
author | Yury Selivanov <yury@magic.io> | 2016-09-15 19:46:16 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2016-09-15 19:46:16 (GMT) |
commit | 1b984ffd44f036cf5c0ce1933c0fb9ba6e94948a (patch) | |
tree | a49d511a8b2dffc3afcd443d0a91254ea55c6f5d /Lib/asyncio | |
parent | d070154fb5f35c33fd03ce941ec19ca15de32263 (diff) | |
parent | 5587d7c071e5725d8aaf565b985441011cb1449f (diff) | |
download | cpython-1b984ffd44f036cf5c0ce1933c0fb9ba6e94948a.zip cpython-1b984ffd44f036cf5c0ce1933c0fb9ba6e94948a.tar.gz cpython-1b984ffd44f036cf5c0ce1933c0fb9ba6e94948a.tar.bz2 |
Merge 3.5 (issue #28174)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/base_events.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 53f5f02..ac6e8f2 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -76,6 +76,17 @@ def _format_pipe(fd): return repr(fd) +def _set_reuseport(sock): + if not hasattr(socket, 'SO_REUSEPORT'): + raise ValueError('reuse_port not supported by socket module') + else: + try: + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) + except OSError: + raise ValueError('reuse_port not supported by socket module, ' + 'SO_REUSEPORT defined but not implemented.') + + # Linux's sock.type is a bitmask that can include extra info about socket. _SOCKET_TYPE_MASK = 0 if hasattr(socket, 'SOCK_NONBLOCK'): @@ -874,12 +885,7 @@ class BaseEventLoop(events.AbstractEventLoop): sock.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if reuse_port: - if not hasattr(socket, 'SO_REUSEPORT'): - raise ValueError( - 'reuse_port not supported by socket module') - else: - sock.setsockopt( - socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) + _set_reuseport(sock) if allow_broadcast: sock.setsockopt( socket.SOL_SOCKET, socket.SO_BROADCAST, 1) @@ -1002,12 +1008,7 @@ class BaseEventLoop(events.AbstractEventLoop): sock.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, True) if reuse_port: - if not hasattr(socket, 'SO_REUSEPORT'): - raise ValueError( - 'reuse_port not supported by socket module') - else: - sock.setsockopt( - socket.SOL_SOCKET, socket.SO_REUSEPORT, True) + _set_reuseport(sock) # Disable IPv4/IPv6 dual stack support (enabled by # default on Linux) which makes a single socket # listen on both address families. |