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