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