[Zodb-checkins] CVS: ZEO/ZEO/zrpc - client.py:1.1.2.8
Tim Peters
tim.one@home.com
Sun, 27 Jan 2002 14:09:13 -0500
Update of /cvs-repository/ZEO/ZEO/zrpc
In directory cvs.zope.org:/tmp/cvs-serv3077/zrpc
Modified Files:
Tag: Standby-branch
client.py
Log Message:
XXX comments for Jeremy.
Minor docstring repair and code cleanup.
=== ZEO/ZEO/zrpc/client.py 1.1.2.7 => 1.1.2.8 ===
def attempt_connects(self):
- "Return true if any connect attempt succeeds."
- self.sockets = {}
+ """Try connecting to all self.addrs addresses.
+
+ If at least one succeeds, pick a success arbitrarily, close all other
+ successes (if any), and return true. If none succeed, return false.
+ """
+
+ self.sockets = {} # {open socket: connection address}
log("attempting connection on %d sockets" % len(self.addrs))
try:
@@ -224,8 +229,9 @@
s = socket.socket(domain, socket.SOCK_STREAM)
s.setblocking(0)
self.sockets[s] = addr
+ # connect() raises Connected iff it succeeds
# XXX can still block for a while if addr requires DNS
- e = self.connect(s)
+ self.connect(s)
# next wait until they actually connect
while self.sockets:
@@ -237,8 +243,8 @@
except select.error:
continue
for s in w:
- # connect() will raise Connected if it succeeds
- e = self.connect(s)
+ # connect() raises Connected iff it succeeds
+ self.connect(s)
except Connected, container:
s = container.sock
del self.sockets[s] # don't close the newly connected socket
@@ -247,7 +253,7 @@
return 0
def connect(self, s):
- """Call s.connect_ex(addr) and return true if loop should continue.
+ """Call s.connect_ex(addr); raise Connected iff connection succeeds.
We have to handle several possible return values from
connect_ex(). If the socket is connected and the initial ZEO
@@ -258,6 +264,9 @@
If the socket sonnects and the initial ZEO setup fails or the
connect_ex() returns an error, we close the socket and ignore it.
+ XXX If test_connection() fails (I assume that's what's meant by
+ XXX "the initial ZEO setup fails", the code below doesn't do anything
+ XXX with the socket. So the comment or the code is wrong.
When the socket is closed, it is removed from self.sockets.
If connect_ex() returns EINPROGRESS, we need to try again later.
@@ -265,7 +274,7 @@
addr = self.sockets[s]
e = s.connect_ex(addr)
if e in _CONNECT_IN_PROGRESS:
- return 1
+ pass
elif e in _CONNECT_OK:
c = self.test_connection(s, addr)
log("connected to %s" % repr(addr), level=zLOG.DEBUG)
@@ -286,6 +295,9 @@
log("error connecting to server: %s" % str(addr),
level=zLOG.ERROR, error=sys.exc_info())
c.close()
+ # XXX what's the state of s at this point? If s got closed,
+ # XXX self.sockets contains a closed socket, and the
+ # XXX next attempt_connects() select() will blow up.
return 0
self.mgr.connect_done(c)
return 1