From dbf160cf65dcfdcab07fe47c39326f16f53e3714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pinkava?= Date: Sun, 3 Mar 2024 08:53:41 +0100 Subject: [PATCH] Fix hangup on reading of closed socket We cannot get more date on closed socket, return what we have, if anythink --- adafruit_wiznet5k/adafruit_wiznet5k_socket.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py index e0687a0..522fddc 100644 --- a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py +++ b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py @@ -594,6 +594,12 @@ def recv_into(self, buffer: bytearray, nbytes: int = 0, flags: int = 0) -> int: elif num_read > 0: # We got a message, but there are no more bytes to read, so we can stop. break + elif self._status in ( + wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSED, + wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSE_WAIT, + ): + # No bytes to read and we will not get more, stop. + break # No bytes yet, or more bytes requested. if self._timeout > 0 and time.monotonic() - last_read_time > self._timeout: raise timeout("timed out")