@@ -69,11 +69,11 @@ def htons(x: int) -> int:
69
69
return (((x ) << 8 ) & 0xFF00 ) | (((x ) >> 8 ) & 0xFF )
70
70
71
71
72
- SOCK_STREAM = const (0x21 ) # TCP
73
- TCP_MODE = 80
72
+ _SOCK_STREAM = const (0x21 ) # TCP
73
+ _TCP_MODE = 80
74
74
SOCK_DGRAM = const (0x02 ) # UDP
75
- AF_INET = const (3 )
76
- SOCKET_INVALID = const (255 )
75
+ _AF_INET = const (3 )
76
+ _SOCKET_INVALID = const (255 )
77
77
78
78
79
79
# pylint: disable=too-many-arguments, unused-argument
@@ -103,8 +103,8 @@ def getaddrinfo(
103
103
if not isinstance (port , int ):
104
104
raise RuntimeError ("Port must be an integer" )
105
105
if is_ipv4 (host ):
106
- return [(AF_INET , socktype , proto , "" , (host , port ))]
107
- return [(AF_INET , socktype , proto , "" , (gethostbyname (host ), port ))]
106
+ return [(_AF_INET , socktype , proto , "" , (host , port ))]
107
+ return [(_AF_INET , socktype , proto , "" , (gethostbyname (host ), port ))]
108
108
109
109
110
110
def gethostbyname (hostname : str ) -> str :
@@ -147,8 +147,8 @@ class socket:
147
147
# pylint: disable=redefined-builtin,unused-argument
148
148
def __init__ (
149
149
self ,
150
- family : int = AF_INET ,
151
- type : int = SOCK_STREAM ,
150
+ family : int = _AF_INET ,
151
+ type : int = _SOCK_STREAM ,
152
152
proto : int = 0 ,
153
153
fileno : Optional [int ] = None ,
154
154
socknum : Optional [int ] = None ,
@@ -161,25 +161,25 @@ def __init__(
161
161
:param Optional[int] fileno: Unused, retained for compatibility.
162
162
:param Optional[int] socknum: Unused, retained for compatibility.
163
163
"""
164
- if family != AF_INET :
164
+ if family != _AF_INET :
165
165
raise RuntimeError ("Only AF_INET family supported by W5K modules." )
166
166
self ._sock_type = type
167
167
self ._buffer = b""
168
168
self ._timeout = 0
169
169
self ._listen_port = None
170
170
171
171
self ._socknum = _the_interface .get_socket ()
172
- if self ._socknum == SOCKET_INVALID :
172
+ if self ._socknum == _SOCKET_INVALID :
173
173
raise RuntimeError ("Failed to allocate socket." )
174
174
175
175
def __enter__ (self ):
176
176
return self
177
177
178
178
def __exit__ (self , exc_type , exc_val , exc_tb ) -> None :
179
- if self ._sock_type == SOCK_STREAM :
179
+ if self ._sock_type == _SOCK_STREAM :
180
180
self .disconnect ()
181
181
stamp = time .monotonic ()
182
- while self .status == wiznet5k .adafruit_wiznet5k ._SNSR_SOCK_FIN_WAIT :
182
+ while self .status == wiznet5k .adafruit_wiznet5k .SNSR_SOCK_FIN_WAIT :
183
183
if time .monotonic () - stamp > 1000 :
184
184
raise RuntimeError ("Failed to disconnect socket" )
185
185
self .close ()
@@ -219,16 +219,16 @@ def connected(self) -> bool:
219
219
return False
220
220
status = _the_interface .socket_status (self .socknum )[0 ]
221
221
if (
222
- status == wiznet5k .adafruit_wiznet5k ._SNSR_SOCK_CLOSE_WAIT
222
+ status == wiznet5k .adafruit_wiznet5k .SNSR_SOCK_CLOSE_WAIT
223
223
and self .available () == 0
224
224
):
225
225
result = False
226
226
else :
227
227
result = status not in (
228
228
wiznet5k .adafruit_wiznet5k .SNSR_SOCK_CLOSED ,
229
229
wiznet5k .adafruit_wiznet5k .SNSR_SOCK_LISTEN ,
230
- wiznet5k .adafruit_wiznet5k ._SNSR_SOCK_TIME_WAIT ,
231
- wiznet5k .adafruit_wiznet5k ._SNSR_SOCK_FIN_WAIT ,
230
+ wiznet5k .adafruit_wiznet5k .SNSR_SOCK_TIME_WAIT ,
231
+ wiznet5k .adafruit_wiznet5k .SNSR_SOCK_FIN_WAIT ,
232
232
)
233
233
if not result and status != wiznet5k .adafruit_wiznet5k .SNSR_SOCK_LISTEN :
234
234
self .close ()
@@ -405,7 +405,7 @@ def recv(
405
405
while True :
406
406
avail = self .available ()
407
407
if avail :
408
- if self ._sock_type == SOCK_STREAM :
408
+ if self ._sock_type == _SOCK_STREAM :
409
409
self ._buffer += _the_interface .socket_read (self .socknum , avail )[
410
410
1
411
411
]
@@ -427,7 +427,7 @@ def recv(
427
427
avail = self .available ()
428
428
if avail :
429
429
stamp = time .monotonic ()
430
- if self ._sock_type == SOCK_STREAM :
430
+ if self ._sock_type == _SOCK_STREAM :
431
431
recv = _the_interface .socket_read (
432
432
self .socknum , min (to_read , avail )
433
433
)[1 ]
@@ -468,7 +468,7 @@ def embed_recv(
468
468
ret = None
469
469
avail = self .available ()
470
470
if avail :
471
- if self ._sock_type == SOCK_STREAM :
471
+ if self ._sock_type == _SOCK_STREAM :
472
472
self ._buffer += _the_interface .socket_read (self .socknum , avail )[1 ]
473
473
elif self ._sock_type == SOCK_DGRAM :
474
474
self ._buffer += _the_interface .read_udp (self .socknum , avail )[1 ]
@@ -550,7 +550,7 @@ def readline(self) -> bytes:
550
550
while b"\r \n " not in self ._buffer :
551
551
avail = self .available ()
552
552
if avail :
553
- if self ._sock_type == SOCK_STREAM :
553
+ if self ._sock_type == _SOCK_STREAM :
554
554
self ._buffer += _the_interface .socket_read (self .socknum , avail )[1 ]
555
555
elif self ._sock_type == SOCK_DGRAM :
556
556
self ._buffer += _the_interface .read_udp (self .socknum , avail )[1 ]
@@ -567,7 +567,7 @@ def readline(self) -> bytes:
567
567
568
568
def disconnect (self ) -> None :
569
569
"""Disconnect a TCP socket."""
570
- assert self ._sock_type == SOCK_STREAM , "Socket must be a TCP socket."
570
+ assert self ._sock_type == _SOCK_STREAM , "Socket must be a TCP socket."
571
571
_the_interface .socket_disconnect (self .socknum )
572
572
573
573
def close (self ) -> None :
0 commit comments