Skip to content

Commit 2cf98c0

Browse files
authored
Correct number of bytes to read math, add param to docstring
1 parent e480277 commit 2cf98c0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

adafruit_esp32spi/adafruit_esp32spi_socket.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,16 @@ def recv_into(self, buffer, nbytes=None):
165165
"""Read some bytes from the connected remote address into a given buffer
166166
167167
:param bytearray buffer: The buffer to read into
168+
:param int nbytes: (Optional) Number of bytes to receive
169+
default is as many as possible before filling the
170+
buffer or timing out
168171
"""
169172

170173
stamp = time.monotonic()
171-
to_read = len(buffer) if nbytes is None else nbytes
174+
to_read = len(buffer)
175+
nbytes = to_read if nbytes is None else to_read - nbytes
172176
received = []
173-
while to_read > 0:
177+
while to_read > len(buffer) - nbytes:
174178
# print("Bytes to read:", to_read)
175179
avail = self.available()
176180
if avail:

0 commit comments

Comments
 (0)