Skip to content

Commit df4efb2

Browse files
author
BiffoBear
committed
Fixed potential infinite loop in WIZNET5K.socket_close.
1 parent da2a88a commit df4efb2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,11 +906,28 @@ def socket_close(self, socket_num: int) -> None:
906906
:param int socket_num: The socket to close.
907907
"""
908908
debug_msg("*** Closing socket {}".format(socket_num), self._debug)
909+
timeout = time.monotonic() + 5.0
909910
self.write_sncr(socket_num, _CMD_SOCK_CLOSE)
911+
debug_msg(" Waiting for close command to process…", self._debug)
910912
while self.read_sncr(socket_num):
913+
if time.monotonic() < timeout:
914+
raise RuntimeError(
915+
"Wiznet5k failed to complete command, status = {}.".format(
916+
self.read_sncr(socket_num)
917+
)
918+
)
911919
time.sleep(0.0001)
920+
debug_msg(" Waiting for socket to close…", self._debug)
921+
timeout = time.monotonic() + 5.0
912922
while self.read_snsr(socket_num) != SNSR_SOCK_CLOSED:
923+
if time.monotonic() > timeout:
924+
raise RuntimeError(
925+
"Wiznet5k failed to close socket, status = {}.".format(
926+
self.read_snsr(socket_num)
927+
)
928+
)
913929
time.sleep(0.0001)
930+
debug_msg(" Socket has closed.", self._debug)
914931

915932
def socket_disconnect(self, socket_num: int) -> None:
916933
"""

0 commit comments

Comments
 (0)