Skip to content

Commit

Permalink
Fix socket accept flow and timeout code
Browse files Browse the repository at this point in the history
  • Loading branch information
us3r64 committed Mar 20, 2024
1 parent a09a95a commit c59c4fd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion adafruit_wiznet5k/adafruit_wiznet5k_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import gc
import time
from sys import byteorder
from errno import ETIMEDOUT

from micropython import const

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit c59c4fd

Please sign in to comment.