Skip to content

Commit 711e927

Browse files
author
BiffoBear
committed
Renamed a global from socket.
1 parent 527c254 commit 711e927

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@
8282
_SNSR_SOCK_SYNSENT = const(0x15)
8383
SNSR_SOCK_SYNRECV = const(0x16)
8484
SNSR_SOCK_ESTABLISHED = const(0x17)
85-
_SNSR_SOCK_FIN_WAIT = const(0x18)
85+
SNSR_SOCK_FIN_WAIT = const(0x18)
8686
_SNSR_SOCK_CLOSING = const(0x1A)
87-
_SNSR_SOCK_TIME_WAIT = const(0x1B)
88-
_SNSR_SOCK_CLOSE_WAIT = const(0x1C)
87+
SNSR_SOCK_TIME_WAIT = const(0x1B)
88+
SNSR_SOCK_CLOSE_WAIT = const(0x1C)
8989
_SNSR_SOCK_LAST_ACK = const(0x1D)
9090
_SNSR_SOCK_UDP = const(0x22)
9191
_SNSR_SOCK_IPRAW = const(0x32)
@@ -814,9 +814,9 @@ def socket_open(self, socket_num: int, conn_mode: int = _SNMR_TCP) -> int:
814814
status = self._read_snsr(socket_num)[0]
815815
if status in (
816816
SNSR_SOCK_CLOSED,
817-
_SNSR_SOCK_TIME_WAIT,
818-
_SNSR_SOCK_FIN_WAIT,
819-
_SNSR_SOCK_CLOSE_WAIT,
817+
SNSR_SOCK_TIME_WAIT,
818+
SNSR_SOCK_FIN_WAIT,
819+
SNSR_SOCK_CLOSE_WAIT,
820820
_SNSR_SOCK_CLOSING,
821821
_SNSR_SOCK_UDP,
822822
):
@@ -893,7 +893,7 @@ def socket_read(
893893
if ret == 0:
894894
# no data on socket?
895895
status = self._read_snmr(socket_num)
896-
if status in (SNSR_SOCK_LISTEN, SNSR_SOCK_CLOSED, _SNSR_SOCK_CLOSE_WAIT):
896+
if status in (SNSR_SOCK_LISTEN, SNSR_SOCK_CLOSED, SNSR_SOCK_CLOSE_WAIT):
897897
# remote end closed its side of the connection, EOF state
898898
ret = 0
899899
resp = 0
@@ -993,7 +993,7 @@ def socket_write(
993993
while free_size < ret:
994994
free_size = self._get_tx_free_size(socket_num)
995995
status = self.socket_status(socket_num)[0]
996-
if status not in (SNSR_SOCK_ESTABLISHED, _SNSR_SOCK_CLOSE_WAIT) or (
996+
if status not in (SNSR_SOCK_ESTABLISHED, SNSR_SOCK_CLOSE_WAIT) or (
997997
timeout and time.monotonic() - stamp > timeout
998998
):
999999
ret = 0
@@ -1038,9 +1038,9 @@ def socket_write(
10381038
) != _SNIR_SEND_OK:
10391039
if self.socket_status(socket_num)[0] in (
10401040
SNSR_SOCK_CLOSED,
1041-
_SNSR_SOCK_TIME_WAIT,
1042-
_SNSR_SOCK_FIN_WAIT,
1043-
_SNSR_SOCK_CLOSE_WAIT,
1041+
SNSR_SOCK_TIME_WAIT,
1042+
SNSR_SOCK_FIN_WAIT,
1043+
SNSR_SOCK_CLOSE_WAIT,
10441044
_SNSR_SOCK_CLOSING,
10451045
) or (timeout and time.monotonic() - stamp > timeout):
10461046
# self.socket_close(socket_num)

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ def htons(x: int) -> int:
6969
return (((x) << 8) & 0xFF00) | (((x) >> 8) & 0xFF)
7070

7171

72-
SOCK_STREAM = const(0x21) # TCP
73-
TCP_MODE = 80
72+
_SOCK_STREAM = const(0x21) # TCP
73+
_TCP_MODE = 80
7474
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)
7777

7878

7979
# pylint: disable=too-many-arguments, unused-argument
@@ -103,8 +103,8 @@ def getaddrinfo(
103103
if not isinstance(port, int):
104104
raise RuntimeError("Port must be an integer")
105105
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))]
108108

109109

110110
def gethostbyname(hostname: str) -> str:
@@ -147,8 +147,8 @@ class socket:
147147
# pylint: disable=redefined-builtin,unused-argument
148148
def __init__(
149149
self,
150-
family: int = AF_INET,
151-
type: int = SOCK_STREAM,
150+
family: int = _AF_INET,
151+
type: int = _SOCK_STREAM,
152152
proto: int = 0,
153153
fileno: Optional[int] = None,
154154
socknum: Optional[int] = None,
@@ -161,25 +161,25 @@ def __init__(
161161
:param Optional[int] fileno: Unused, retained for compatibility.
162162
:param Optional[int] socknum: Unused, retained for compatibility.
163163
"""
164-
if family != AF_INET:
164+
if family != _AF_INET:
165165
raise RuntimeError("Only AF_INET family supported by W5K modules.")
166166
self._sock_type = type
167167
self._buffer = b""
168168
self._timeout = 0
169169
self._listen_port = None
170170

171171
self._socknum = _the_interface.get_socket()
172-
if self._socknum == SOCKET_INVALID:
172+
if self._socknum == _SOCKET_INVALID:
173173
raise RuntimeError("Failed to allocate socket.")
174174

175175
def __enter__(self):
176176
return self
177177

178178
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
179-
if self._sock_type == SOCK_STREAM:
179+
if self._sock_type == _SOCK_STREAM:
180180
self.disconnect()
181181
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:
183183
if time.monotonic() - stamp > 1000:
184184
raise RuntimeError("Failed to disconnect socket")
185185
self.close()
@@ -219,16 +219,16 @@ def connected(self) -> bool:
219219
return False
220220
status = _the_interface.socket_status(self.socknum)[0]
221221
if (
222-
status == wiznet5k.adafruit_wiznet5k._SNSR_SOCK_CLOSE_WAIT
222+
status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSE_WAIT
223223
and self.available() == 0
224224
):
225225
result = False
226226
else:
227227
result = status not in (
228228
wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSED,
229229
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,
232232
)
233233
if not result and status != wiznet5k.adafruit_wiznet5k.SNSR_SOCK_LISTEN:
234234
self.close()
@@ -405,7 +405,7 @@ def recv(
405405
while True:
406406
avail = self.available()
407407
if avail:
408-
if self._sock_type == SOCK_STREAM:
408+
if self._sock_type == _SOCK_STREAM:
409409
self._buffer += _the_interface.socket_read(self.socknum, avail)[
410410
1
411411
]
@@ -427,7 +427,7 @@ def recv(
427427
avail = self.available()
428428
if avail:
429429
stamp = time.monotonic()
430-
if self._sock_type == SOCK_STREAM:
430+
if self._sock_type == _SOCK_STREAM:
431431
recv = _the_interface.socket_read(
432432
self.socknum, min(to_read, avail)
433433
)[1]
@@ -468,7 +468,7 @@ def embed_recv(
468468
ret = None
469469
avail = self.available()
470470
if avail:
471-
if self._sock_type == SOCK_STREAM:
471+
if self._sock_type == _SOCK_STREAM:
472472
self._buffer += _the_interface.socket_read(self.socknum, avail)[1]
473473
elif self._sock_type == SOCK_DGRAM:
474474
self._buffer += _the_interface.read_udp(self.socknum, avail)[1]
@@ -550,7 +550,7 @@ def readline(self) -> bytes:
550550
while b"\r\n" not in self._buffer:
551551
avail = self.available()
552552
if avail:
553-
if self._sock_type == SOCK_STREAM:
553+
if self._sock_type == _SOCK_STREAM:
554554
self._buffer += _the_interface.socket_read(self.socknum, avail)[1]
555555
elif self._sock_type == SOCK_DGRAM:
556556
self._buffer += _the_interface.read_udp(self.socknum, avail)[1]
@@ -567,7 +567,7 @@ def readline(self) -> bytes:
567567

568568
def disconnect(self) -> None:
569569
"""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."
571571
_the_interface.socket_disconnect(self.socknum)
572572

573573
def close(self) -> None:

0 commit comments

Comments
 (0)