Commit b84e138b authored by Tim Peters's avatar Tim Peters

_triggerbase: Make new-style class, for better debugability.

Windows trigger.__init__:  Simplify more.  The trigger can connect
after the other end has done  bind() and listen(); no need to wait
for an accept() too, and so no need to fiddle with blocking/
non-blocking or "expected" socket.error's either.
parent ebdf3a63
......@@ -52,7 +52,7 @@ from ZODB.utils import positive_id
# new data onto a channel's outgoing data queue at the same time that
# the main thread is trying to remove some]
class _triggerbase:
class _triggerbase(object):
"""OS-independent base class for OS-dependent trigger class."""
kind = None # subclass must set to "pipe" or "loopback"; used by repr
......@@ -168,23 +168,10 @@ else:
# Specifying port 0 tells Windows to pick a port for us.
a.bind(("127.0.0.1", 0))
connect_address = a.getsockname() # actual (host, port) pair
connect_address = a.getsockname() # assigned (host, port) pair
a.listen(1)
# Before connecting, set w non-blocking, because the connect can't
# succeed before we call a.accept() -- while a.accept() can't
# succeed before we try to connect. Maybe it would be clearer
# to spin off a thread to do this, but that's much more expensive
# than this hack.
w.setblocking(0)
try:
w.connect(connect_address)
except socket.error:
# Expected exception, since a.accept() hasn't been called
# yet.
pass
w.setblocking(1)
r, addr = a.accept() # r becomes asyncore's socket
w.connect(connect_address)
r, addr = a.accept() # r becomes asyncore's (self.)socket
a.close()
asyncore.dispatcher.__init__(self, r)
......
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