From 7d4f429e58ef424f1371db47543348d587b53e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pinkava?= Date: Sun, 3 Mar 2024 08:30:41 +0100 Subject: [PATCH] Handle SNSR_SOCK_CLOSE_WAIT during accept() If we receive SYN, ACK and the we get FIX from the other side really fast, the connection state can go straight to the closing phase. If that happends lets just finis the close and continue listening. --- adafruit_wiznet5k/adafruit_wiznet5k_socket.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py index e0687a0..d11d5b8 100644 --- a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py +++ b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py @@ -402,6 +402,9 @@ def accept( ): if self._timeout and 0 < self._timeout < time.monotonic() - stamp: raise TimeoutError("Failed to accept connection.") + if self._status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSE_WAIT: + self._disconnect() + self.listen() if self._status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSED: self.close() self.listen()