Commit 2eeafe30 authored by Vincent Pelletier's avatar Vincent Pelletier

Use kernel facilities to find free ports.

This is most efficient (kernel knows what's available) & cleaner.

Of course, this is not perfect either. Still, it solved many "port already
in use" happening for me with previous implementation, for some reason.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2372 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 436e3a5c
...@@ -224,21 +224,17 @@ class NEOCluster(object): ...@@ -224,21 +224,17 @@ class NEOCluster(object):
NEOProcess(command, uuid, arguments)) NEOProcess(command, uuid, arguments))
def __allocatePort(self): def __allocatePort(self):
for i in range(10): port_set = self.port_set
port = random.randrange(30000, 40000)
if port in self.port_set:
continue
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try: s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try: while True:
s.connect(('localhost', port)) s.bind(('127.0.0.1', 0))
except socket.error: port = s.getsockname()[1]
# Perhaps we should check value of error too. if port not in port_set:
self.port_set.add(port) break
return port
finally:
s.close() s.close()
raise RuntimeError, "Can't find port" port_set.add(port)
return port
def __allocateUUID(self): def __allocateUUID(self):
uuid = os.urandom(16) uuid = os.urandom(16)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment