15
15
import gc
16
16
import time
17
17
from micropython import const
18
- from adafruit_wiznet5k import adafruit_wiznet5k
18
+ import adafruit_wiznet5k as wiznet5k
19
19
20
20
_the_interface = None # pylint: disable=invalid-name
21
21
@@ -115,12 +115,12 @@ def __exit__(self, exc_type, exc_val, exc_tb):
115
115
if self ._sock_type == SOCK_STREAM :
116
116
self .disconnect ()
117
117
stamp = time .monotonic ()
118
- while self .status == adafruit_wiznet5k .SNSR_SOCK_FIN_WAIT :
118
+ while self .status == wiznet5k . adafruit_wiznet5k .SNSR_SOCK_FIN_WAIT :
119
119
if time .monotonic () - stamp > 1000 :
120
120
raise RuntimeError ("Failed to disconnect socket" )
121
121
self .close ()
122
122
stamp = time .monotonic ()
123
- while self .status != adafruit_wiznet5k .SNSR_SOCK_CLOSED :
123
+ while self .status != wiznet5k . adafruit_wiznet5k .SNSR_SOCK_CLOSED :
124
124
if time .monotonic () - stamp > 1000 :
125
125
raise RuntimeError ("Failed to close socket" )
126
126
@@ -140,16 +140,19 @@ def connected(self):
140
140
if self .socknum >= _the_interface .max_sockets :
141
141
return False
142
142
status = _the_interface .socket_status (self .socknum )[0 ]
143
- if status == adafruit_wiznet5k .SNSR_SOCK_CLOSE_WAIT and self .available () == 0 :
143
+ if (
144
+ status == wiznet5k .adafruit_wiznet5k .SNSR_SOCK_CLOSE_WAIT
145
+ and self .available () == 0
146
+ ):
144
147
result = False
145
148
else :
146
149
result = status not in (
147
- adafruit_wiznet5k .SNSR_SOCK_CLOSED ,
148
- adafruit_wiznet5k .SNSR_SOCK_LISTEN ,
149
- adafruit_wiznet5k .SNSR_SOCK_TIME_WAIT ,
150
- adafruit_wiznet5k .SNSR_SOCK_FIN_WAIT ,
150
+ wiznet5k . adafruit_wiznet5k .SNSR_SOCK_CLOSED ,
151
+ wiznet5k . adafruit_wiznet5k .SNSR_SOCK_LISTEN ,
152
+ wiznet5k . adafruit_wiznet5k .SNSR_SOCK_TIME_WAIT ,
153
+ wiznet5k . adafruit_wiznet5k .SNSR_SOCK_FIN_WAIT ,
151
154
)
152
- if not result and status != adafruit_wiznet5k .SNSR_SOCK_LISTEN :
155
+ if not result and status != wiznet5k . adafruit_wiznet5k .SNSR_SOCK_LISTEN :
153
156
self .close ()
154
157
return result
155
158
@@ -195,12 +198,12 @@ def accept(self):
195
198
"""
196
199
stamp = time .monotonic ()
197
200
while self .status not in (
198
- adafruit_wiznet5k .SNSR_SOCK_SYNRECV ,
199
- adafruit_wiznet5k .SNSR_SOCK_ESTABLISHED ,
201
+ wiznet5k . adafruit_wiznet5k .SNSR_SOCK_SYNRECV ,
202
+ wiznet5k . adafruit_wiznet5k .SNSR_SOCK_ESTABLISHED ,
200
203
):
201
204
if self ._timeout > 0 and time .monotonic () - stamp > self ._timeout :
202
205
return None
203
- if self .status == adafruit_wiznet5k .SNSR_SOCK_CLOSED :
206
+ if self .status == wiznet5k . adafruit_wiznet5k .SNSR_SOCK_CLOSED :
204
207
self .close ()
205
208
self .listen ()
206
209
@@ -212,7 +215,7 @@ def accept(self):
212
215
self ._socknum = new_listen_socknum # pylint: disable=protected-access
213
216
self .bind ((None , self ._listen_port ))
214
217
self .listen ()
215
- while self .status != adafruit_wiznet5k .SNSR_SOCK_LISTEN :
218
+ while self .status != wiznet5k . adafruit_wiznet5k .SNSR_SOCK_LISTEN :
216
219
raise RuntimeError ("Failed to open new listening socket" )
217
220
return client_sock , addr
218
221
0 commit comments