Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,13 @@ def create_datagram_endpoint(self, protocol_factory,
raise ValueError(
'reuse_port not supported by socket module')
else:
sock.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
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.'))
if allow_broadcast:
sock.setsockopt(
socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
Expand Down Expand Up @@ -946,8 +951,13 @@ def create_server(self, protocol_factory, host=None, port=None,
raise ValueError(
'reuse_port not supported by socket module')
else:
sock.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEPORT, True)
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.'))
# Disable IPv4/IPv6 dual stack support (enabled by
# default on Linux) which makes a single socket
# listen on both address families.
Expand Down
11 changes: 11 additions & 0 deletions tests/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,17 @@ def test_create_server_nosoreuseport(self, m_socket):

self.assertRaises(ValueError, self.loop.run_until_complete, f)

@patch_socket
def test_create_server_soreuseport_only_defined(self, m_socket):
m_socket.getaddrinfo = socket.getaddrinfo
m_socket.socket.return_value = mock.Mock()
m_socket.SO_REUSEPORT = -1

f = self.loop.create_server(
MyProto, '0.0.0.0', 0, reuse_port=True)

self.assertRaises(ValueError, self.loop.run_until_complete, f)

@patch_socket
def test_create_server_cant_bind(self, m_socket):

Expand Down