diff options
author | Yury Selivanov <yury@magic.io> | 2016-07-12 22:24:25 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2016-07-12 22:24:25 (GMT) |
commit | e824315e2b17b6d82c9c5f64b044369cd1f0b8a9 (patch) | |
tree | 9f63cc2a90adfe261f7503f2dfb2c23fa00c22b5 /Lib/asyncio | |
parent | b133bb4977858882bb8a08b6aee330a864245cd5 (diff) | |
parent | 252e9ed9744b32fc9f21eae2d58c1afcdb1fd524 (diff) | |
download | cpython-e824315e2b17b6d82c9c5f64b044369cd1f0b8a9.zip cpython-e824315e2b17b6d82c9c5f64b044369cd1f0b8a9.tar.gz cpython-e824315e2b17b6d82c9c5f64b044369cd1f0b8a9.tar.bz2 |
Merge 3.5 (issue #27392)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/base_events.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index f55a36e..0916da8 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -708,8 +708,6 @@ class BaseEventLoop(events.AbstractEventLoop): raise ValueError( 'host and port was not specified and no sock specified') - sock.setblocking(False) - transport, protocol = yield from self._create_connection_transport( sock, protocol_factory, ssl, server_hostname) if self._debug: @@ -722,14 +720,17 @@ class BaseEventLoop(events.AbstractEventLoop): @coroutine def _create_connection_transport(self, sock, protocol_factory, ssl, - server_hostname): + server_hostname, server_side=False): + + sock.setblocking(False) + protocol = protocol_factory() waiter = self.create_future() if ssl: sslcontext = None if isinstance(ssl, bool) else ssl transport = self._make_ssl_transport( sock, protocol, sslcontext, waiter, - server_side=False, server_hostname=server_hostname) + server_side=server_side, server_hostname=server_hostname) else: transport = self._make_socket_transport(sock, protocol, waiter) @@ -981,6 +982,25 @@ class BaseEventLoop(events.AbstractEventLoop): return server @coroutine + def connect_accepted_socket(self, protocol_factory, sock, *, ssl=None): + """Handle an accepted connection. + + This is used by servers that accept connections outside of + asyncio but that use asyncio to handle connections. + + This method is a coroutine. When completed, the coroutine + returns a (transport, protocol) pair. + """ + transport, protocol = yield from self._create_connection_transport( + sock, protocol_factory, ssl, '', server_side=True) + if self._debug: + # Get the socket from the transport because SSL transport closes + # the old socket and creates a new SSL socket + sock = transport.get_extra_info('socket') + logger.debug("%r handled: (%r, %r)", sock, transport, protocol) + return transport, protocol + + @coroutine def connect_read_pipe(self, protocol_factory, pipe): protocol = protocol_factory() waiter = self.create_future() |