[Zope-Checkins] CVS: ZODB3/ZEO - runsvr.py:1.7
Guido van Rossum
guido@python.org
Tue, 19 Nov 2002 15:34:37 -0500
Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv1450
Modified Files:
runsvr.py
Log Message:
Refacto check_socket() so that the address test is reusable.
=== ZODB3/ZEO/runsvr.py 1.6 => 1.7 ===
--- ZODB3/ZEO/runsvr.py:1.6 Tue Nov 19 15:32:16 2002
+++ ZODB3/ZEO/runsvr.py Tue Nov 19 15:34:36 2002
@@ -212,17 +212,18 @@
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("")):