Skip to content

Commit 759f5a6

Browse files
committed
socket.recv can return less data than requested
closes #OPENTAR-33
1 parent a0b3f75 commit 759f5a6

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/tarantool/connection.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,21 @@ def _read_response(self):
9999
:return: tuple of the form (header, body)
100100
:rtype: tuple of two byte arrays
101101
'''
102-
# Read response header
103-
buff_header = ctypes.create_string_buffer(12)
104-
nbytes = self._socket.recv_into(buff_header, 12)
105-
106-
# Immediately raises an exception if the data cannot be read
107-
if nbytes != 12:
108-
raise socket.error(socket.errno.ECONNABORTED, "Software caused connection abort")
109-
110-
# Extract body lenght from header
111-
body_length = struct_L.unpack(buff_header[4:8])[0]
112-
113-
# Unpack body if it is not empty (i.e. not PING)
114-
if body_length != 0:
115-
buff_body = ctypes.create_string_buffer(body_length)
116-
nbytes = self._socket.recv_into(buff_body)
117-
# Immediately raises an exception if the data cannot be read
118-
if nbytes != body_length:
119-
raise socket.error(socket.errno.ECONNABORTED, "Software caused connection abort")
120-
else:
121-
buff_body = b""
122102

123-
return buff_header, buff_body
103+
buf = ''
104+
l = 12
105+
106+
while 1:
107+
buf += self._socket.recv(l - len(buf))
108+
if len(buf) < l:
109+
continue
110+
111+
l = 12 + struct_L.unpack(buf[4:8])[0]
112+
113+
if len(buf) < l:
114+
continue
115+
116+
return buf[0:12], buf[12:]
124117

125118

126119

0 commit comments

Comments
 (0)