mirror of
https://github.com/python/cpython.git
synced 2024-11-25 10:54:51 +08:00
asyncio, Tulip issue 180: Make Server attributes and methods private
- loop, waiters and active_count attributes are now private - attach(), detach() and wakeup() methods are now private The sockets attribute remains public.
This commit is contained in:
parent
7aee3ecd57
commit
b28dbac86d
@ -89,43 +89,44 @@ def _raise_stop_error(*args):
|
||||
class Server(events.AbstractServer):
|
||||
|
||||
def __init__(self, loop, sockets):
|
||||
self.loop = loop
|
||||
self._loop = loop
|
||||
self.sockets = sockets
|
||||
self.active_count = 0
|
||||
self.waiters = []
|
||||
self._active_count = 0
|
||||
self._waiters = []
|
||||
|
||||
def attach(self, transport):
|
||||
def _attach(self):
|
||||
assert self.sockets is not None
|
||||
self.active_count += 1
|
||||
self._active_count += 1
|
||||
|
||||
def detach(self, transport):
|
||||
assert self.active_count > 0
|
||||
self.active_count -= 1
|
||||
if self.active_count == 0 and self.sockets is None:
|
||||
def _detach(self):
|
||||
assert self._active_count > 0
|
||||
self._active_count -= 1
|
||||
if self._active_count == 0 and self.sockets is None:
|
||||
self._wakeup()
|
||||
|
||||
def close(self):
|
||||
sockets = self.sockets
|
||||
if sockets is not None:
|
||||
self.sockets = None
|
||||
for sock in sockets:
|
||||
self.loop._stop_serving(sock)
|
||||
if self.active_count == 0:
|
||||
self._wakeup()
|
||||
if sockets is None:
|
||||
return
|
||||
self.sockets = None
|
||||
for sock in sockets:
|
||||
self._loop._stop_serving(sock)
|
||||
if self._active_count == 0:
|
||||
self._wakeup()
|
||||
|
||||
def _wakeup(self):
|
||||
waiters = self.waiters
|
||||
self.waiters = None
|
||||
waiters = self._waiters
|
||||
self._waiters = None
|
||||
for waiter in waiters:
|
||||
if not waiter.done():
|
||||
waiter.set_result(waiter)
|
||||
|
||||
@coroutine
|
||||
def wait_closed(self):
|
||||
if self.sockets is None or self.waiters is None:
|
||||
if self.sockets is None or self._waiters is None:
|
||||
return
|
||||
waiter = futures.Future(loop=self.loop)
|
||||
self.waiters.append(waiter)
|
||||
waiter = futures.Future(loop=self._loop)
|
||||
self._waiters.append(waiter)
|
||||
yield from waiter
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin,
|
||||
self._closing = False # Set when close() called.
|
||||
self._eof_written = False
|
||||
if self._server is not None:
|
||||
self._server.attach(self)
|
||||
self._server._attach()
|
||||
self._loop.call_soon(self._protocol.connection_made, self)
|
||||
if waiter is not None:
|
||||
# wait until protocol.connection_made() has been called
|
||||
@ -91,7 +91,7 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin,
|
||||
self._sock.close()
|
||||
server = self._server
|
||||
if server is not None:
|
||||
server.detach(self)
|
||||
server._detach()
|
||||
self._server = None
|
||||
|
||||
def get_write_buffer_size(self):
|
||||
|
@ -417,7 +417,7 @@ class _SelectorTransport(transports._FlowControlMixin,
|
||||
self._conn_lost = 0 # Set when call to connection_lost scheduled.
|
||||
self._closing = False # Set when close() called.
|
||||
if self._server is not None:
|
||||
self._server.attach(self)
|
||||
self._server._attach()
|
||||
|
||||
def abort(self):
|
||||
self._force_close(None)
|
||||
@ -464,7 +464,7 @@ class _SelectorTransport(transports._FlowControlMixin,
|
||||
self._loop = None
|
||||
server = self._server
|
||||
if server is not None:
|
||||
server.detach(self)
|
||||
server._detach()
|
||||
self._server = None
|
||||
|
||||
def get_write_buffer_size(self):
|
||||
|
Loading…
Reference in New Issue
Block a user