mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
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
(cherry picked from commit dbf102271f
)
Co-authored-by: Yury Selivanov <yury@magic.io>
This commit is contained in:
parent
f8fdb368e3
commit
bc3a002e7d
13 changed files with 382 additions and 69 deletions
|
@ -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.')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue