The recv() method of socket objects return an empty string when the connection is closed. Therefore the following code:
def __recvall(self, bytes):
"""__recvall(bytes) -> data
Receive EXACTLY the number of bytes requested from the socket.
Blocks until the required number of bytes have been received.
"""
data = ""
while len(data) < bytes:
data = data + self.recv(bytes-len(data))
return data
will loop indefinitely if the remote peer closes the connection before all the expected bytes are received. A fixed version could be:
def __recvall(self, bytes):
"""__recvall(bytes) -> data
Receive EXACTLY the number of bytes requested from the socket.
Blocks until the required number of bytes have been received.
"""
data = ""
while len(data) < bytes:
d = self.recv(bytes-len(data))
if not d: raise GeneralProxyError("connection closed unexpectedly")
data = data + d
return data