|
@@ -73,7 +73,7 @@ class Server:
|
|
def set_ssl_context(self, ssl_context: ssl.SSLContext):
|
|
def set_ssl_context(self, ssl_context: ssl.SSLContext):
|
|
self._ssl_context = ssl_context
|
|
self._ssl_context = ssl_context
|
|
|
|
|
|
- async def run_reader(self, reader, connection_token):
|
|
|
|
|
|
+ async def run_reader(self, reader: asyncio.StreamReader, connection_token):
|
|
while 1:
|
|
while 1:
|
|
try:
|
|
try:
|
|
# Wait one second if buffer is full
|
|
# Wait one second if buffer is full
|
|
@@ -90,7 +90,7 @@ class Server:
|
|
except Exception as e:
|
|
except Exception as e:
|
|
logging.error(f"Unexpected exception:\n{e}", exc_info=True)
|
|
logging.error(f"Unexpected exception:\n{e}", exc_info=True)
|
|
|
|
|
|
- async def run_writer(self, writer, connection_token):
|
|
|
|
|
|
+ async def run_writer(self, writer: asyncio.StreamWriter, connection_token):
|
|
consecutive_interruptions = 0
|
|
consecutive_interruptions = 0
|
|
errors = 0
|
|
errors = 0
|
|
while connection_token in self.buffers:
|
|
while connection_token in self.buffers:
|
|
@@ -100,6 +100,7 @@ class Server:
|
|
# Slow down if buffer is empty; after 1.5 s of silence, break
|
|
# Slow down if buffer is empty; after 1.5 s of silence, break
|
|
consecutive_interruptions += 1
|
|
consecutive_interruptions += 1
|
|
if consecutive_interruptions > 3:
|
|
if consecutive_interruptions > 3:
|
|
|
|
+ logging.error("Too many interruptions...")
|
|
break
|
|
break
|
|
await asyncio.sleep(.5)
|
|
await asyncio.sleep(.5)
|
|
continue
|
|
continue
|
|
@@ -166,6 +167,7 @@ class Server:
|
|
else:
|
|
else:
|
|
return 0 # On success, return 0
|
|
return 0 # On success, return 0
|
|
# On exception, disconnect and return 1
|
|
# On exception, disconnect and return 1
|
|
|
|
+ logging.error("Disconnecting...")
|
|
self.disconnect(connection_token=connection_token)
|
|
self.disconnect(connection_token=connection_token)
|
|
return 1
|
|
return 1
|
|
|
|
|