Commit 013116ab authored by Guido van Rossum's avatar Guido van Rossum

Refacto check_socket() so that the address test is reusable.

parent a0fb33da
......@@ -212,17 +212,18 @@ class ZEOServer:
self.clear_socket()
def check_socket(self):
if isinstance(self.opts.address, type("")):
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
else:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self.can_connect(self.opts.family, self.opts.address):
self.opts.usage("address %r already in use" % self.opts.address)
def can_connect(self, family, address):
s = socket.socket(family, socket.SOCK_STREAM)
try:
s.connect(self.opts.address)
s.connect(address)
except socket.error:
pass
return 0
else:
s.close()
self.opts.usage("address %r already in use" % self.opts.address)
return 1
def clear_socket(self):
if isinstance(self.opts.address, type("")):
......
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