@@ -113,20 +113,17 @@ def __enter__(self):
113
113
114
114
def __exit__ (self , exc_type , exc_val , exc_tb ):
115
115
self .disconnect ()
116
+ stamp = time .monotonic ()
116
117
while self .status == adafruit_wiznet5k .SNSR_SOCK_FIN_WAIT :
117
- pass
118
+ if time .monotonic () - stamp > 1000 :
119
+ raise RuntimeError ("Failed to disconnect socket" )
118
120
self .close ()
119
121
120
122
@property
121
123
def socknum (self ):
122
124
"""Returns the socket object's socket number."""
123
125
return self ._socknum
124
126
125
- @socknum .setter
126
- def socknum (self , socknum ):
127
- """Sets the socket object's socket number."""
128
- self ._socknum = socknum
129
-
130
127
@property
131
128
def status (self ):
132
129
"""Returns the status of the socket"""
@@ -186,9 +183,10 @@ def listen(self, backlog=None):
186
183
self ._buffer = b""
187
184
188
185
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.
192
190
"""
193
191
stamp = time .monotonic ()
194
192
while self .status not in (
@@ -205,12 +203,12 @@ def accept(self):
205
203
current_socknum = self .socknum
206
204
# Create a new socket object and swap socket nums so we can continue listening
207
205
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
210
208
self .bind ((None , self ._listen_port ))
211
209
self .listen ()
212
210
while self .status != adafruit_wiznet5k .SNSR_SOCK_LISTEN :
213
- print ( "Waiting for socket to listen " )
211
+ raise RuntimeError ( "Failed to open new listening socket " )
214
212
return client_sock , addr
215
213
216
214
def connect (self , address , conntype = None ):
0 commit comments