Also except BlockingIOError on TcpClient.send()

This commit is contained in:
Lonami Exo 2017-06-12 10:44:04 +02:00
parent 769692959f
commit d8afb7e548

View File

@ -53,11 +53,15 @@ class TcpClient:
view = memoryview(data)
total_sent, total = 0, len(data)
while total_sent < total:
sent = self._socket.send(view[total_sent:])
if sent == 0:
raise ConnectionResetError(
'The server has closed the connection.')
total_sent += sent
try:
sent = self._socket.send(view[total_sent:])
if sent == 0:
raise ConnectionResetError(
'The server has closed the connection.')
total_sent += sent
except BlockingIOError:
time.sleep(self.delay)
def read(self, size, timeout=timedelta(seconds=5)):
"""Reads (receives) a whole block of 'size bytes