Wrap socket with SSL after connecting

See https://github.com/Anorov/PySocks/issues/29
This commit is contained in:
Lonami Exo 2018-07-19 20:38:53 +02:00
parent 7f78d7ed2f
commit 4027ac6a6f

View File

@ -92,14 +92,18 @@ class TcpClient:
try:
if self._socket is None:
self._socket = self._create_socket(mode, self.proxy)
if self.ssl and port == SSL_PORT:
self._socket = ssl.wrap_socket(self._socket, **self.ssl)
wrap_ssl = self.ssl and port == SSL_PORT
else:
wrap_ssl = False
await asyncio.wait_for(
self._loop.sock_connect(self._socket, address),
timeout=self.timeout,
loop=self._loop
)
if wrap_ssl:
self._socket = ssl.wrap_socket(self._socket, **self.ssl)
self._closed.clear()
except OSError as e:
if e.errno in CONN_RESET_ERRNOS: