Add is_connected flag

This commit is contained in:
Pedro Ferreira 2018-02-04 22:19:15 +01:00
parent bdda1cd8e8
commit 43161742a9

View File

@ -35,6 +35,7 @@ class SHSDuplexStream(object):
def __init__(self): def __init__(self):
self.write_stream = None self.write_stream = None
self.read_stream = None self.read_stream = None
self.is_connected = False
def write(self, data): def write(self, data):
self.write_stream.write(data) self.write_stream.write(data)
@ -45,6 +46,7 @@ class SHSDuplexStream(object):
def close(self): def close(self):
self.write_stream.close() self.write_stream.close()
self.read_stream.close() self.read_stream.close()
self.is_connected = False
@async_generator @async_generator
async def __aiter__(self): async def __aiter__(self):
@ -148,6 +150,7 @@ class SHSClient(SHSDuplexStream, SHSEndpoint):
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
self.is_connected = True
if self._on_connect: if self._on_connect:
await self._on_connect() await self._on_connect()