@@ -310,9 +310,18 @@ def bind(self, address: Tuple[Optional[str], int]) -> None:
310
310
:raises ValueError: If the IPv4 address specified is not the address
311
311
assigned to the WIZNET5K interface.
312
312
"""
313
- # Check to see if the socket is bound is disabled to allow socket.accept to swap sockets.
314
- # if self._listen_port:
315
- # raise ConnectionError("The socket is already bound.")
313
+ # Check to see if the socket is bound.
314
+ if self ._listen_port :
315
+ raise ConnectionError ("The socket is already bound." )
316
+ self ._bind (address )
317
+
318
+ def _bind (self , address : Tuple [Optional [str ], int ]) -> None :
319
+ """
320
+ Helper function to allow bind() to check for an existing connection and for
321
+ accept() to generate a new socket connection.
322
+
323
+ :param Tuple[Optional[str], int] address: Address as a (host, port) tuple.
324
+ """
316
325
if address [0 ]:
317
326
if gethostbyname (address [0 ]) != _the_interface .pretty_ip (
318
327
_the_interface .ip_address
@@ -373,7 +382,7 @@ def accept(
373
382
client_sock = socket ()
374
383
client_sock ._socknum = current_socknum # pylint: disable=protected-access
375
384
self ._socknum = new_listen_socknum
376
- self .bind ((None , self ._listen_port ))
385
+ self ._bind ((None , self ._listen_port ))
377
386
self .listen ()
378
387
while self ._status != wiznet5k .adafruit_wiznet5k .SNSR_SOCK_LISTEN :
379
388
raise RuntimeError ("Failed to open new listening socket" )
0 commit comments