adafruit / Adafruit_CircuitPython_Wiznet5k

Pure-Python interface for WIZNET 5k Ethernet modules
Other
15 stars 35 forks source link

Fix DHCP socket leak #122

Closed BiffoBear closed 1 year ago

BiffoBear commented 1 year ago

Closes #121. Moved all references to hardware sockets in the DHCP module to _handle_dhcp_message and _receive_dhcp_response. Added try… finally block to ensure that the hardware socket is always closed. Made the socket number a local method attribute since it doesn't need to be stored. Removed unused methods to initialise and release hardware sockets. Refactored DHCP module to use higher level calls to the WIZNET5K instance. Renamed several methods in WIZNET5K as they are private and no longer called from outside WIZNET5K. Added _read_socket_reservations and _read_sndport methods to WIZNET5K to help dumping of socket state for troubleshooting. Tested with a DHCP server and without a DHCP server to force a TimeoutError. Hardware socket closed in both cases. Tests carried out with wiznet5k_simpletest.py on w5100s, w5500 and w6100 chips.