Skip to content

Commit 57ca18b

Browse files
committed
Fix getting stuck in loop in socket_listen
If `socket_listen` was called, and a connection was made right away, it was possible that the state of the socket would change to `SNSR_SOCK_ESTABLISHED` before the check ever saw it enter `SNSR_SOCK_LISTEN`, and the code would be stuck in an endless loop. This fixes the issue by accepting both `SNSR_SOCK_LISTEN` and `SNSR_SOCK_ESTABLISHED` as valid states to continue.
1 parent 25f7cd2 commit 57ca18b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def socket_listen(self, socket_num, port):
563563
self._send_socket_cmd(socket_num, CMD_SOCK_LISTEN)
564564
# Wait until ready
565565
status = [SNSR_SOCK_CLOSED]
566-
while status[0] != SNSR_SOCK_LISTEN:
566+
while status[0] not in (SNSR_SOCK_LISTEN, SNSR_SOCK_ESTABLISHED):
567567
status = self._read_snsr(socket_num)
568568
if status[0] == SNSR_SOCK_CLOSED:
569569
raise RuntimeError("Listening socket closed.")

0 commit comments

Comments
 (0)