From c59c4fddc50d1f72acb3b3ad6484568aaa7dfd0d Mon Sep 17 00:00:00 2001 From: Dorin Date: Wed, 20 Mar 2024 22:16:40 +0200 Subject: [PATCH 1/2] Fix socket accept flow and timeout code --- adafruit_wiznet5k/adafruit_wiznet5k_socket.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py index 5626592..e4ca819 100644 --- a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py +++ b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py @@ -27,6 +27,7 @@ import gc import time from sys import byteorder +from errno import ETIMEDOUT from micropython import const @@ -400,12 +401,16 @@ def accept( while self._status not in ( wiznet5k.adafruit_wiznet5k.SNSR_SOCK_SYNRECV, wiznet5k.adafruit_wiznet5k.SNSR_SOCK_ESTABLISHED, + wiznet5k.adafruit_wiznet5k.SNSR_SOCK_LISTEN, ): if self._timeout and 0 < self._timeout < time.monotonic() - stamp: raise TimeoutError("Failed to accept connection.") if self._status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSED: self.close() self.listen() + if self._status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSE_WAIT: + self._disconnect() + self.listen() _, addr = _the_interface.socket_accept(self._socknum) current_socknum = self._socknum @@ -772,7 +777,7 @@ class timeout(TimeoutError): the timeout has elapsed and we haven't received any data yet.""" def __init__(self, msg): - super().__init__(msg) + super().__init__(ETIMEDOUT, msg) # pylint: enable=unused-argument, redefined-builtin, invalid-name From 6a90f759f7e5e2e792566c334889af49f93a27f8 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 22 Apr 2024 17:15:51 -0500 Subject: [PATCH 2/2] remove (now) duplicated SNSR_SOCK_CLOSE_WAIT --- adafruit_wiznet5k/adafruit_wiznet5k_socket.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py index e4ca819..8846b0d 100644 --- a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py +++ b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py @@ -408,9 +408,6 @@ def accept( if self._status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSED: self.close() self.listen() - if self._status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSE_WAIT: - self._disconnect() - self.listen() _, addr = _the_interface.socket_accept(self._socknum) current_socknum = self._socknum