Skip to content

Return from recv after we've read all available bytes #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions adafruit_esp32spi/adafruit_esp32spi_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ def readline(self):
return firstline

def recv(self, bufsize=0):
"""Reads some bytes from the connected remote address.
:param int bufsize: maximum number of bytes to receive
"""Reads some bytes from the connected remote address. Will only return
an empty string after the configured timeout.

:param int bufsize: maximum number of bytes to receive
"""
# print("Socket read", bufsize)
if bufsize == 0: # read as much as we can at the moment
Expand Down Expand Up @@ -134,6 +136,10 @@ def recv(self, bufsize=0):
received.append(recv)
to_read -= len(recv)
gc.collect()
elif received:
# We've received some bytes but no more are available. So return
# what we have.
break
if self._timeout > 0 and time.monotonic() - stamp > self._timeout:
break
# print(received)
Expand Down