mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Bail out correctly if socket.recv gets nothing (indicating a closed socket)
This commit is contained in:
parent
86f01965cd
commit
4b552457e7
2 changed files with 12 additions and 3 deletions
|
@ -85,11 +85,17 @@ class Connection(object):
|
|||
header_len = 8 # size of a packed unsigned long long
|
||||
data = b""
|
||||
while len(data) < header_len:
|
||||
data += self.conn.recv(1024)
|
||||
d = self.conn.recv(1024)
|
||||
if not d:
|
||||
return None
|
||||
data += d
|
||||
data_len = struct.unpack('Q',data[:header_len])[0]
|
||||
data = data[header_len:]
|
||||
while len(data) < data_len:
|
||||
data += self.conn.recv(1024)
|
||||
d = self.conn.recv(1024)
|
||||
if not d:
|
||||
return None
|
||||
data += d
|
||||
return data
|
||||
|
||||
def exec_command(self, cmd, tmp_path, sudo_user, sudoable=False, executable='/bin/sh'):
|
||||
|
|
|
@ -163,7 +163,10 @@ class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
|
|||
data_len = struct.unpack('Q',data[:header_len])[0]
|
||||
data = data[header_len:]
|
||||
while len(data) < data_len:
|
||||
data += self.request.recv(1024)
|
||||
d = self.request.recv(1024)
|
||||
if not d:
|
||||
return None
|
||||
data += d
|
||||
return data
|
||||
|
||||
def handle(self):
|
||||
|
|
Loading…
Reference in a new issue