Browse Source

Check if the socket was closed.

Raise an exception if the socket was closed (recv returned 0 bytes).
Steven Engler 5 years ago
parent
commit
a1b131ac66
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/basic_protocols.py

+ 8 - 0
src/basic_protocols.py

@@ -34,6 +34,10 @@ class ProtocolHelper():
 		"""
 		#
 		data = socket.recv(num_bytes-len(self._buffer))
+		#
+		if len(data) == 0:
+			raise ProtocolException('The socket was closed.')
+		#
 		self._buffer += data
 		if len(self._buffer) == num_bytes:
 			return True
@@ -293,6 +297,10 @@ class PullDataProtocol(Protocol):
 				block_size = min(self.recv_buffer_len, bytes_remaining)
 				#
 				data = self.socket.recv(block_size)
+				#
+				if len(data) == 0:
+					raise ProtocolException('The socket was closed.')
+				#
 				self.bytes_read += len(data)
 				#
 				if self.bytes_read != 0 and self._time_of_first_byte is None: