From ec4fa8b1951214759bedc6a5cdccdb1e4b210ae0 Mon Sep 17 00:00:00 2001 From: nibrag Date: Sat, 7 May 2016 12:52:32 +0300 Subject: [PATCH] Fixed: Double creation protocol and transport led to errors --- aiosocks/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/aiosocks/__init__.py b/aiosocks/__init__.py index 2a6ac95..75ffbf5 100644 --- a/aiosocks/__init__.py +++ b/aiosocks/__init__.py @@ -54,13 +54,16 @@ async def create_connection(protocol_factory, proxy, proxy_auth, dst, *, remote_ raise SocksConnectionError('[Errno %s] Can not connect to proxy %s:%d [%s]' % (exc.errno, proxy.host, proxy.port, exc.strerror)) from exc + # Wait until communication with proxy server is finished try: await protocol.negotiate_done() except SocksError as exc: raise SocksError('Can not connect to %s:%s [%s]' % (dst[0], dst[1], exc)) - sock = transport.get_extra_info('socket') + protocol = protocol_factory() + protocol.connection_made(transport) + transport._protocol = protocol + + return transport, protocol - return await loop._create_connection_transport( - sock, protocol_factory, ssl, server_hostname)