Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix for binding to ::1 and/or 127.0.0.1

  • Loading branch information...
commit d0520c22e320a2965b497dfd886079fc160b2813 1 parent e555e87
@pigmej pigmej authored
Showing with 32 additions and 1 deletion.
  1. +32 −1 pyscgi/pyscgi.py
View
33 pyscgi/pyscgi.py
@@ -185,7 +185,38 @@ def process_request (self, request, client_address):
class ThreadingUnixStreamServer_Custom (ThreadingMixIn_Custom, SocketServer.UnixStreamServer): pass
-class ThreadingTCPServer_Custom (ThreadingMixIn_Custom, SocketServer.TCPServer): pass
+class ThreadingTCPServer_Custom (ThreadingMixIn_Custom, SocketServer.TCPServer):
+ def server_bind(self):
+ HOST, PORT = self.server_address
+ s = None
+ # loop over ifaces for the HOST and PORT pair
+ for res in socket.getaddrinfo(HOST,
+ PORT,
+ socket.AF_UNSPEC,
+ socket.SOCK_STREAM,
+ 0,
+ socket.AI_PASSIVE):
+ af, socktype, protocol, canonicalname, sa = res
+ try:
+ s = socket.socket(af, socktype, protocol)
+ except socket.error:
+ s = None
+ continue
+ try:
+ if self.allow_reuse_address:
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ s.bind(sa)
+ except socket.error:
+ s.close()
+ s = None
+ continue
+ break
+ # if none successfully bind report error
+ if s is None:
+ raise socket.error, "Can't open socket"
+ self.socket = s
+ # fix the server_address
+ self.server_address = self.socket.getsockname()
# TCP port
Please sign in to comment.
Something went wrong with that request. Please try again.