Raise an exception if recv() returned 0 bytes

See for details: https://docs.python.org/3/howto/sockets.html
"When a recv returns 0 bytes, it means the other side has closed (or is in the process of closing) the connection. You will not receive any more data on this connection. Ever."
This commit is contained in:
Dmitry D. Chernov 2017-05-20 18:34:05 +10:00 committed by Lonami
parent 3c3946e6f1
commit bbd3eb7c28

View File

@ -82,6 +82,9 @@ class TcpClient:
# This is why we need to keep checking to make sure that we receive it all
left_count = buffer_size - writer.written_count
partial = self.socket.recv(left_count)
if len(partial) == 0:
raise ConnectionResetError(
'The server has closed the connection (recv() returned 0 bytes).')
writer.write(partial)
except BlockingIOError as error: