Skip to content

Commit c59c4fd

Browse files
committed
Fix socket accept flow and timeout code
1 parent a09a95a commit c59c4fd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import gc
2828
import time
2929
from sys import byteorder
30+
from errno import ETIMEDOUT
3031

3132
from micropython import const
3233

@@ -400,12 +401,16 @@ def accept(
400401
while self._status not in (
401402
wiznet5k.adafruit_wiznet5k.SNSR_SOCK_SYNRECV,
402403
wiznet5k.adafruit_wiznet5k.SNSR_SOCK_ESTABLISHED,
404+
wiznet5k.adafruit_wiznet5k.SNSR_SOCK_LISTEN,
403405
):
404406
if self._timeout and 0 < self._timeout < time.monotonic() - stamp:
405407
raise TimeoutError("Failed to accept connection.")
406408
if self._status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSED:
407409
self.close()
408410
self.listen()
411+
if self._status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSE_WAIT:
412+
self._disconnect()
413+
self.listen()
409414

410415
_, addr = _the_interface.socket_accept(self._socknum)
411416
current_socknum = self._socknum
@@ -772,7 +777,7 @@ class timeout(TimeoutError):
772777
the timeout has elapsed and we haven't received any data yet."""
773778

774779
def __init__(self, msg):
775-
super().__init__(msg)
780+
super().__init__(ETIMEDOUT, msg)
776781

777782

778783
# pylint: enable=unused-argument, redefined-builtin, invalid-name

0 commit comments

Comments
 (0)