@@ -113,20 +113,17 @@ def __enter__(self):
113113
114114 def __exit__ (self , exc_type , exc_val , exc_tb ):
115115 self .disconnect ()
116+ stamp = time .monotonic ()
116117 while self .status == adafruit_wiznet5k .SNSR_SOCK_FIN_WAIT :
117- pass
118+ if time .monotonic () - stamp > 1000 :
119+ raise RuntimeError ("Failed to disconnect socket" )
118120 self .close ()
119121
120122 @property
121123 def socknum (self ):
122124 """Returns the socket object's socket number."""
123125 return self ._socknum
124126
125- @socknum .setter
126- def socknum (self , socknum ):
127- """Sets the socket object's socket number."""
128- self ._socknum = socknum
129-
130127 @property
131128 def status (self ):
132129 """Returns the status of the socket"""
@@ -186,9 +183,10 @@ def listen(self, backlog=None):
186183 self ._buffer = b""
187184
188185 def accept (self ):
189- """Mimic python socket accept for compatibility. The socket where the
190- connection originated is returned while a new socket is allocated and begins
191- listening.
186+ """Accept a connection. The socket must be bound to an address and listening for
187+ connections. The return value is a pair (conn, address) where conn is a new
188+ socket object usable to send and receive data on the connection, and address is
189+ the address bound to the socket on the other end of the connection.
192190 """
193191 stamp = time .monotonic ()
194192 while self .status not in (
@@ -205,12 +203,12 @@ def accept(self):
205203 current_socknum = self .socknum
206204 # Create a new socket object and swap socket nums so we can continue listening
207205 client_sock = socket ()
208- client_sock .socknum = current_socknum
209- self .socknum = new_listen_socknum
206+ client_sock ._socknum = current_socknum # pylint: disable=protected-access
207+ self ._socknum = new_listen_socknum # pylint: disable=protected-access
210208 self .bind ((None , self ._listen_port ))
211209 self .listen ()
212210 while self .status != adafruit_wiznet5k .SNSR_SOCK_LISTEN :
213- print ( "Waiting for socket to listen " )
211+ raise RuntimeError ( "Failed to open new listening socket " )
214212 return client_sock , addr
215213
216214 def connect (self , address , conntype = None ):
0 commit comments