Set reuse address option (fixes #1043)

When the server is killed there may still be client-sockets connected in
the TIME_WAIT state, causing the bind() call to fail. With the
REUSEADDR option we can reuse the address immediately unless another
process is actually *listening* on the same address.
that we want to reuse the address
This commit is contained in:
Andy Kittner 2013-11-12 21:39:03 +01:00 committed by Oskar Hahn
parent 506d9a256d
commit 0d4c48a9c0

View File

@ -296,6 +296,7 @@ def get_port(address, port):
""" """
s = socket.socket() s = socket.socket()
try: try:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((address, port)) s.bind((address, port))
s.listen(-1) s.listen(-1)
except socket.error: except socket.error: