Use async connect9) instead of feeding loop

This commit is contained in:
Pedro Ferreira 2017-08-01 19:31:24 +02:00
parent e70324ed11
commit 86bc76d495

View File

@ -109,9 +109,9 @@ class SHSClient(SHSSocket):
if not self.crypto.verify_server_accept(data): if not self.crypto.verify_server_accept(data):
raise SHSClientException('Server accept is not valid') raise SHSClientException('Server accept is not valid')
def connect(self): async def connect(self):
reader, writer = self.loop.run_until_complete(open_connection(self.host, self.port, loop=self.loop)) reader, writer = await open_connection(self.host, self.port, loop=self.loop)
self.loop.run_until_complete(self._handshake(reader, writer)) await self._handshake(reader, writer)
keys = self.crypto.get_box_keys() keys = self.crypto.get_box_keys()
self.crypto.clean() self.crypto.clean()
@ -119,4 +119,4 @@ class SHSClient(SHSSocket):
self.read_stream, self.write_stream = get_stream_pair(reader, writer, **keys) self.read_stream, self.write_stream = get_stream_pair(reader, writer, **keys)
self.writer = writer self.writer = writer
if self._on_connect: if self._on_connect:
ensure_future(self._on_connect(), loop=self.loop) await self._on_connect()