diff options
author | Yury Selivanov <yury@magic.io> | 2018-05-28 18:31:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-28 18:31:28 (GMT) |
commit | dbf102271fcc316f353c7e0a283811b661d128f2 (patch) | |
tree | 8807a0305490616dc3b480fae5e50e98c80b4fa8 /Lib/asyncio/selector_events.py | |
parent | e549c4be5fb010f5faf12236af8faa720a1429be (diff) | |
download | cpython-dbf102271fcc316f353c7e0a283811b661d128f2.zip cpython-dbf102271fcc316f353c7e0a283811b661d128f2.tar.gz cpython-dbf102271fcc316f353c7e0a283811b661d128f2.tar.bz2 |
bpo-33654: Support BufferedProtocol in set_protocol() and start_tls() (GH-7130)
In this commit:
* Support BufferedProtocol in set_protocol() and start_tls()
* Fix proactor to cancel readers reliably
* Update tests to be compatible with OpenSSL 1.1.1
* Clarify BufferedProtocol docs
* Bump TLS tests timeouts to 60 seconds; eliminate possible race from start_serving
* Rewrite test_start_tls_server_1
Diffstat (limited to 'Lib/asyncio/selector_events.py')
-rw-r--r-- | Lib/asyncio/selector_events.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 5473c70..116c08d 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -597,8 +597,10 @@ class _SelectorTransport(transports._FlowControlMixin, self._extra['peername'] = None self._sock = sock self._sock_fd = sock.fileno() - self._protocol = protocol - self._protocol_connected = True + + self._protocol_connected = False + self.set_protocol(protocol) + self._server = server self._buffer = self._buffer_factory() self._conn_lost = 0 # Set when call to connection_lost scheduled. @@ -640,6 +642,7 @@ class _SelectorTransport(transports._FlowControlMixin, def set_protocol(self, protocol): self._protocol = protocol + self._protocol_connected = True def get_protocol(self): return self._protocol @@ -721,11 +724,7 @@ class _SelectorSocketTransport(_SelectorTransport): def __init__(self, loop, sock, protocol, waiter=None, extra=None, server=None): - if protocols._is_buffered_protocol(protocol): - self._read_ready = self._read_ready__get_buffer - else: - self._read_ready = self._read_ready__data_received - + self._read_ready_cb = None super().__init__(loop, sock, protocol, extra, server) self._eof = False self._paused = False @@ -745,6 +744,14 @@ class _SelectorSocketTransport(_SelectorTransport): self._loop.call_soon(futures._set_result_unless_cancelled, waiter, None) + def set_protocol(self, protocol): + if isinstance(protocol, protocols.BufferedProtocol): + self._read_ready_cb = self._read_ready__get_buffer + else: + self._read_ready_cb = self._read_ready__data_received + + super().set_protocol(protocol) + def is_reading(self): return not self._paused and not self._closing @@ -764,12 +771,17 @@ class _SelectorSocketTransport(_SelectorTransport): if self._loop.get_debug(): logger.debug("%r resumes reading", self) + def _read_ready(self): + self._read_ready_cb() + def _read_ready__get_buffer(self): if self._conn_lost: return try: - buf = self._protocol.get_buffer() + buf = self._protocol.get_buffer(-1) + if not len(buf): + raise RuntimeError('get_buffer() returned an empty buffer') except Exception as exc: self._fatal_error( exc, 'Fatal error: protocol.get_buffer() call failed.') |