vici: Check for closed connection in Python bindings

The Python VICI library does not check if the socket is closed.
If the daemon closes the connection, _recvall() spins forever.

Closes strongswan/strongswan#56.
This commit is contained in:
Weilu Jia 2016-12-12 18:17:10 -08:00 committed by Tobias Brunner
parent 564a199674
commit 351179d4dc
1 changed files with 4 additions and 1 deletions

View File

@ -33,7 +33,10 @@ class Transport(object):
"""Ensure to read count bytes from the socket"""
data = b""
while len(data) < count:
data += self.socket.recv(count - len(data))
buf = self.socket.recv(count - len(data))
if not buf:
raise socket.error('Connection closed')
data += buf
return data