summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2016-10-14 14:34:11 -0600
committerBert JW Regeer <bertjw@regeer.org>2016-10-14 14:34:11 -0600
commited67c43759a2f46104582eceb3913f8e0c9e0978 (patch)
tree3eb1f44790bb568e8a2b70154b528885d0637884
parent7e807c9ecefb2388d1e696c3253085d674ac4590 (diff)
downloadwaitress-ed67c43759a2f46104582eceb3913f8e0c9e0978.tar.gz
On Windows IPPROTO_IPV6 may not be defined in socket
Unfortunately due to some reshuffling of headers on Windows, and Python defining the wrong Windows version, IPPROTO_IPV6 may not be defined on Windows. If this is the case, we set them to some magic values. If there is an OS out there that doesn't define those flags, and they are not windows, we raise a RuntimeError because we need to add some magic variables, waitress requires IPv6...
-rw-r--r--waitress/compat.py19
-rw-r--r--waitress/server.py11
2 files changed, 28 insertions, 2 deletions
diff --git a/waitress/compat.py b/waitress/compat.py
index 9e06cde..ceeb252 100644
--- a/waitress/compat.py
+++ b/waitress/compat.py
@@ -109,3 +109,22 @@ try:
MAXINT = sys.maxint
except AttributeError: # pragma: no cover
MAXINT = sys.maxsize
+
+
+# Fix for issue reported in https://github.com/Pylons/waitress/issues/138,
+# Python on Windows may not define IPPROTO_IPV6 in socket.
+import socket
+
+if hasattr(socket, 'IPPROTO_IPV6') and hasattr(socket, 'IPV6_V6ONLY'):
+ IPPROTO_IPV6 = socket.IPPROTO_IPV6
+ IPV6_V6ONLY = socket.IPV6_V6ONLY
+else: # pragma: no cover
+ import os
+ if os.name == 'nt':
+ IPPROTO_IPV6 = 41
+ IPV6_V6ONLY = 27
+ else:
+ raise RuntimeError(
+ 'OS does not support required IPv6 socket flags. This is requirement '
+ 'for Waitress. Please open an issue at https://github.com/Pylons/waitress'
+ )
diff --git a/waitress/server.py b/waitress/server.py
index 7134f86..d3fbd79 100644
--- a/waitress/server.py
+++ b/waitress/server.py
@@ -22,7 +22,14 @@ from waitress import trigger
from waitress.adjustments import Adjustments
from waitress.channel import HTTPChannel
from waitress.task import ThreadedTaskDispatcher
-from waitress.utilities import cleanup_unix_socket, logging_dispatcher
+from waitress.utilities import (
+ cleanup_unix_socket,
+ logging_dispatcher,
+ )
+from waitress.compat import (
+ IPPROTO_IPV6,
+ IPV6_V6ONLY,
+ )
def create_server(application,
map=None,
@@ -169,7 +176,7 @@ class BaseWSGIServer(logging_dispatcher, object):
if _sock is None:
self.create_socket(self.family, self.socktype)
if self.family == socket.AF_INET6: # pragma: nocover
- self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
+ self.socket.setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 1)
self.set_reuse_addr()
self.bind_server_socket()