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) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if port in self.port_set: s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
continue while True:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('127.0.0.1', 0))
try: port = s.getsockname()[1]
try: if port not in port_set:
s.connect(('localhost', port)) break
except socket.error: s.close()
# Perhaps we should check value of error too. port_set.add(port)
self.port_set.add(port) return port
return port
finally:
s.close()
raise RuntimeError, "Can't find 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