|
@@ -74,7 +74,6 @@ class Server:
|
|
|
self._ssl_context = ssl_context
|
|
|
|
|
|
async def run_reader(self, reader: asyncio.StreamReader, connection_token):
|
|
|
- received_bytes = 0
|
|
|
while 1:
|
|
|
try:
|
|
|
# Wait one second if buffer is full
|
|
@@ -82,7 +81,6 @@ class Server:
|
|
|
await asyncio.sleep(1)
|
|
|
continue
|
|
|
input_data = await reader.read(self.buffer_chunk_size)
|
|
|
- received_bytes += len(input_data)
|
|
|
if connection_token not in self.buffers:
|
|
|
break
|
|
|
self.buffers[connection_token].append(input_data)
|
|
@@ -91,12 +89,10 @@ class Server:
|
|
|
break
|
|
|
except Exception as e:
|
|
|
logging.error(f"Unexpected exception:\n{e}", exc_info=True)
|
|
|
- print(f"received_bytes: {received_bytes}")
|
|
|
|
|
|
- async def run_writer(self, writer, connection_token):
|
|
|
+ async def run_writer(self, writer: asyncio.StreamWriter, connection_token):
|
|
|
consecutive_interruptions = 0
|
|
|
errors = 0
|
|
|
- r = 0
|
|
|
while connection_token in self.buffers:
|
|
|
try:
|
|
|
input_data = self.buffers[connection_token].popleft()
|
|
@@ -104,15 +100,13 @@ class Server:
|
|
|
# Slow down if buffer is empty; after 1.5 s of silence, break
|
|
|
consecutive_interruptions += 1
|
|
|
if consecutive_interruptions > 3:
|
|
|
- print("Too many interruptions")
|
|
|
+ logging.error("Too many interruptions...")
|
|
|
break
|
|
|
await asyncio.sleep(.5)
|
|
|
continue
|
|
|
else:
|
|
|
consecutive_interruptions = 0
|
|
|
- r += len(input_data)
|
|
|
if not input_data:
|
|
|
- print(f"Sent bytes: {r}")
|
|
|
break
|
|
|
try:
|
|
|
writer.write(input_data)
|