uasyncio: open_connection: Initial hackish SSL support.

It performs handshake in blocking manner, hopes that writes
work without short writes, and hopes that non-blocking read
is implemented properly by ussl module (there're known issues
with axTLS module for example).
pull/234/merge
Paul Sokolovsky 2017-12-09 18:07:32 +02:00
rodzic a7f8eaa6ed
commit 04c0110319
1 zmienionych plików z 8 dodań i 1 usunięć

Wyświetl plik

@ -199,7 +199,7 @@ class StreamWriter:
return "<StreamWriter %r>" % self.s
def open_connection(host, port):
def open_connection(host, port, ssl=False):
if DEBUG and __debug__:
log.debug("open_connection(%s, %s)", host, port)
s = _socket.socket()
@ -218,6 +218,13 @@ def open_connection(host, port):
# assert s2.fileno() == s.fileno()
if DEBUG and __debug__:
log.debug("open_connection: After iowait: %s", s)
if ssl:
print("Warning: uasyncio SSL support is alpha")
import ussl
s.setblocking(True)
s2 = ussl.wrap_socket(s)
s.setblocking(False)
return StreamReader(s, s2), StreamWriter(s2, {})
return StreamReader(s), StreamWriter(s, {})