Skip to content

Commit 18b3f89

Browse files
authored
Merge pull request #112 from tannewt/return_earlier
Return from `recv` after we've read all available bytes
2 parents 71d42ff + 98f31ad commit 18b3f89

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

adafruit_esp32spi/adafruit_esp32spi_socket.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ def readline(self):
105105
return firstline
106106

107107
def recv(self, bufsize=0):
108-
"""Reads some bytes from the connected remote address.
109-
:param int bufsize: maximum number of bytes to receive
108+
"""Reads some bytes from the connected remote address. Will only return
109+
an empty string after the configured timeout.
110+
111+
:param int bufsize: maximum number of bytes to receive
110112
"""
111113
# print("Socket read", bufsize)
112114
if bufsize == 0: # read as much as we can at the moment
@@ -134,6 +136,10 @@ def recv(self, bufsize=0):
134136
received.append(recv)
135137
to_read -= len(recv)
136138
gc.collect()
139+
elif received:
140+
# We've received some bytes but no more are available. So return
141+
# what we have.
142+
break
137143
if self._timeout > 0 and time.monotonic() - stamp > self._timeout:
138144
break
139145
# print(received)

0 commit comments

Comments
 (0)