Skip to content

Commit 8d3ada0

Browse files
authored
Merge pull request #169 from dhalbert/recv_into_bug2
fix recv_into again
2 parents 4b003b6 + 91c4396 commit 8d3ada0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

adafruit_esp32spi/adafruit_esp32spi_socket.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def recv_into(self, buffer, nbytes: int = 0):
175175
last_read_time = time.monotonic()
176176
num_to_read = len(buffer) if nbytes == 0 else nbytes
177177
num_read = 0
178-
while num_read < num_to_read:
178+
while num_to_read > 0:
179179
num_avail = self.available()
180180
if num_avail > 0:
181181
last_read_time = time.monotonic()
@@ -184,10 +184,11 @@ def recv_into(self, buffer, nbytes: int = 0):
184184
)
185185
buffer[num_read : num_read + len(bytes_read)] = bytes_read
186186
num_read += len(bytes_read)
187+
num_to_read -= num_read
187188
elif num_read > 0:
188189
# We got a message, but there are no more bytes to read, so we can stop.
189190
break
190-
# No bytes yet, or more byte requested.
191+
# No bytes yet, or more bytes requested.
191192
if self._timeout > 0 and time.monotonic() - last_read_time > self._timeout:
192193
break
193194
return num_read

0 commit comments

Comments
 (0)