Commit b4ecd30b authored by Jim Fulton's avatar Jim Fulton

simplify acceptor setup logic

After reading run_until_complete doc :)
parent edb198a0
...@@ -224,22 +224,19 @@ class Acceptor(object): ...@@ -224,22 +224,19 @@ class Acceptor(object):
cr = loop.create_unix_server(self.factory, addr, ssl=ssl) cr = loop.create_unix_server(self.factory, addr, ssl=ssl)
f = asyncio.async(cr, loop=loop) f = asyncio.async(cr, loop=loop)
server = loop.run_until_complete(f)
self.server = server
if isinstance(addr, tuple) and addr[1] == 0:
addrs = [s.getsockname() for s in server.sockets]
addrs = [a for a in addrs if len(a) == len(addr)]
if addrs:
self.addr = addrs[0]
else:
self.addr = server.sockets[0].getsockname()[:len(addr)]
@f.add_done_callback
def listenting(f):
server = f.result()
self.server = server
if isinstance(addr, tuple) and addr[1] == 0:
addrs = [s.getsockname() for s in server.sockets]
addrs = [a for a in addrs if len(a) == len(addr)]
if addrs:
self.addr = addrs[0]
else:
self.addr = server.sockets[0].getsockname()[:len(addr)]
logger.info("listening on %s", str(addr)) logger.info("listening on %s", str(addr))
loop.run_until_complete(f)
def factory(self): def factory(self):
try: try:
logger.debug("Accepted connection") logger.debug("Accepted connection")
......
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