]> granicus.if.org Git - python/commitdiff
[Patch #982681] Apply this patch correctly; makes set_reuse_addr() work on Windows
authorAndrew M. Kuchling <amk@amk.ca>
Thu, 15 Jul 2004 16:17:07 +0000 (16:17 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Thu, 15 Jul 2004 16:17:07 +0000 (16:17 +0000)
Lib/asyncore.py

index f63a83eebadd4c32e824b9cc4ae6a02314ea82b3..5f602195be5cc4049200e3cd35c2c34df8762ac9 100644 (file)
@@ -263,14 +263,20 @@ class dispatcher:
     def set_reuse_addr(self):
         # try to re-use a server port if possible
         try:
+            # Windows SO_REUSEADDR is very broken (from a unixy perspective)
+            if sys.platform == 'win32':
+                reuse_constant = socket.SO_EXCLUSIVEADDRUSE
+            else:
+                reuse_constant = socket.SO_REUSEADDR
+                
             self.socket.setsockopt(
-                socket.SOL_SOCKET, socket.SO_REUSEADDR,
+                socket.SOL_SOCKET, reuse_constant,
                 self.socket.getsockopt(socket.SOL_SOCKET,
-                                       socket.SO_REUSEADDR) | 1
+                                       reuse_constant) | 1
                 )
         except socket.error:
             pass
-
+        
     # ==================================================
     # predicates for select()
     # these are used as filters for the lists of sockets