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