Commit 35136be9 authored by Tim Peters's avatar Tim Peters

Merge rev 30900 from 3.4 branch.

_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 c43d7912
...@@ -52,7 +52,7 @@ from ZODB.utils import positive_id ...@@ -52,7 +52,7 @@ from ZODB.utils import positive_id
# new data onto a channel's outgoing data queue at the same time that # new data onto a channel's outgoing data queue at the same time that
# the main thread is trying to remove some] # the main thread is trying to remove some]
class _triggerbase: class _triggerbase(object):
"""OS-independent base class for OS-dependent trigger class.""" """OS-independent base class for OS-dependent trigger class."""
kind = None # subclass must set to "pipe" or "loopback"; used by repr kind = None # subclass must set to "pipe" or "loopback"; used by repr
...@@ -168,23 +168,10 @@ else: ...@@ -168,23 +168,10 @@ else:
# Specifying port 0 tells Windows to pick a port for us. # Specifying port 0 tells Windows to pick a port for us.
a.bind(("127.0.0.1", 0)) 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) a.listen(1)
w.connect(connect_address)
# Before connecting, set w non-blocking, because the connect can't r, addr = a.accept() # r becomes asyncore's (self.)socket
# 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
a.close() a.close()
asyncore.dispatcher.__init__(self, r) 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