Merge master branch

This commit is contained in:
Davte 2020-04-19 20:43:35 +02:00
parent 25cf7271f4
commit 60c87ecb19
2 changed files with 3 additions and 9 deletions

View File

@ -13,6 +13,6 @@ __author__ = "Davide Testa"
__email__ = "davide@davte.it" __email__ = "davide@davte.it"
__credits__ = [] __credits__ = []
__license__ = "GNU General Public License v3.0" __license__ = "GNU General Public License v3.0"
__version__ = "0.0.8" __version__ = "0.0.9"
__maintainer__ = "Davide Testa" __maintainer__ = "Davide Testa"
__contact__ = "t.me/davte" __contact__ = "t.me/davte"

View File

@ -74,7 +74,6 @@ class Server:
self._ssl_context = ssl_context self._ssl_context = ssl_context
async def run_reader(self, reader: asyncio.StreamReader, connection_token): async def run_reader(self, reader: asyncio.StreamReader, connection_token):
received_bytes = 0
while 1: while 1:
try: try:
# Wait one second if buffer is full # Wait one second if buffer is full
@ -82,7 +81,6 @@ class Server:
await asyncio.sleep(1) await asyncio.sleep(1)
continue continue
input_data = await reader.read(self.buffer_chunk_size) input_data = await reader.read(self.buffer_chunk_size)
received_bytes += len(input_data)
if connection_token not in self.buffers: if connection_token not in self.buffers:
break break
self.buffers[connection_token].append(input_data) self.buffers[connection_token].append(input_data)
@ -91,12 +89,10 @@ class Server:
break break
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)
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 consecutive_interruptions = 0
errors = 0 errors = 0
r = 0
while connection_token in self.buffers: while connection_token in self.buffers:
try: try:
input_data = self.buffers[connection_token].popleft() 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 # 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:
print("Too many interruptions") logging.error("Too many interruptions...")
break break
await asyncio.sleep(.5) await asyncio.sleep(.5)
continue continue
else: else:
consecutive_interruptions = 0 consecutive_interruptions = 0
r += len(input_data)
if not input_data: if not input_data:
print(f"Sent bytes: {r}")
break break
try: try:
writer.write(input_data) writer.write(input_data)