Skip to content

Commit 3bdbba0

Browse files
committed
Don't wait for the timeout in recv when we've received some bytes
1 parent 71d42ff commit 3bdbba0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

adafruit_esp32spi/adafruit_esp32spi_socket.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def readline(self):
105105
return firstline
106106

107107
def recv(self, bufsize=0):
108-
"""Reads some bytes from the connected remote address.
108+
"""Reads some bytes from the connected remote address. Will only return
109+
an empty string after the configured timeout.
109110
:param int bufsize: maximum number of bytes to receive
110111
"""
111112
# print("Socket read", bufsize)
@@ -134,6 +135,10 @@ def recv(self, bufsize=0):
134135
received.append(recv)
135136
to_read -= len(recv)
136137
gc.collect()
138+
elif received:
139+
# We've received some bytes but no more are available. So return
140+
# what we have.
141+
break
137142
if self._timeout > 0 and time.monotonic() - stamp > self._timeout:
138143
break
139144
# print(received)

0 commit comments

Comments
 (0)