Skip to content

Commit

Permalink
Fix for missing IPPROTO_V6 on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgosmann authored and tcstewar committed Nov 2, 2017
1 parent 1d0459d commit 86f3c27
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion nengo_gui/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
WS_MAGIC = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'


if socket.has_ipv6:
if hasattr(socket, 'IPPROTO_IPV6'):
IPPROTO_IPV6 = socket.IPPROTO_IPV6
elif sys.platform.startswith('win'):
# See <https://bugs.python.org/issue29515>.
IPPROTO_IPV6 = 41
else:
raise RuntimeError(
"System does not define IPPROTO_IPV6 despite IPv6 support.")
else:
IPPROTO_IPV6 = None


class SocketClosedError(IOError):
pass

Expand Down Expand Up @@ -120,7 +133,7 @@ def __init__(self, address_family, address):
self.address_family, socket.SOCK_STREAM)
if self.address_family is socket.AF_INET6:
self.socket.setsockopt(
socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)

def bind(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Expand Down

0 comments on commit 86f3c27

Please sign in to comment.