]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add a flags= option to netutil.bind_sockets
authorPhilipp Hagemeister <phihag@phihag.de>
Tue, 4 Sep 2012 10:33:38 +0000 (12:33 +0200)
committerPhilipp Hagemeister <phihag@phihag.de>
Tue, 4 Sep 2012 10:33:38 +0000 (12:33 +0200)
tornado/netutil.py

index ba0b27d25b19877441fa18189082c63a8a5b9c81..6c5a0a93793c3ed1bdebe2512c6a3e5c9b1e2135 100644 (file)
@@ -237,7 +237,7 @@ class TCPServer(object):
             logging.error("Error in connection callback", exc_info=True)
 
 
-def bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=128):
+def bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=128, flags=None):
     """Creates listening sockets bound to the given port and address.
 
     Returns a list of socket objects (multiple sockets are returned if
@@ -253,17 +253,20 @@ def bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=128):
 
     The ``backlog`` argument has the same meaning as for
     ``socket.listen()``.
+
+    ``flags`` is a bitmask of AI_* flags to ``getaddrinfo``.
     """
     sockets = []
     if address == "":
         address = None
-    flags = socket.AI_PASSIVE
-    if hasattr(socket, "AI_ADDRCONFIG"):
-        # AI_ADDRCONFIG ensures that we only try to bind on ipv6
-        # if the system is configured for it, but the flag doesn't
-        # exist on some platforms (specifically WinXP, although
-        # newer versions of windows have it)
-        flags |= socket.AI_ADDRCONFIG
+    if flags is None:
+        flags = socket.AI_PASSIVE
+        if hasattr(socket, "AI_ADDRCONFIG"):
+            # AI_ADDRCONFIG ensures that we only try to bind on ipv6
+            # if the system is configured for it, but the flag doesn't
+            # exist on some platforms (specifically WinXP, although
+            # newer versions of windows have it)
+            flags |= socket.AI_ADDRCONFIG
     for res in set(socket.getaddrinfo(address, port, family, socket.SOCK_STREAM,
                                   0, flags)):
         af, socktype, proto, canonname, sockaddr = res