Skip to content

Commit e6bbb52

Browse files
committed
Use SOCK_STREAM & SOCK_DGRAM numbers that match circuitpython core
A future enhancement to the core ssl module might require this
1 parent 3bd953e commit e6bbb52

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,13 @@ def inet_ntoa(ip_address: Union[bytes, bytearray]) -> str:
145145
return _the_interface.pretty_ip(ip_address)
146146

147147

148-
SOCK_STREAM = const(0x21) # TCP
149-
_TCP_MODE = 80
150-
SOCK_DGRAM = const(0x02) # UDP
148+
# These must match circuitpython "socketpoool" values. However, we cannot
149+
# depend on socketpool being importable, so hard-code them here.
150+
SOCK_STREAM = 1
151+
SOCK_DGRAM = 2
152+
153+
_SOCKET_TYPE_TO_WIZNET = b"\0\x21\2"
154+
151155
AF_INET = const(3)
152156
_SOCKET_INVALID = const(255)
153157

@@ -431,7 +435,7 @@ def connect(self, address: Tuple[str, int]) -> None:
431435
self._socknum,
432436
_the_interface.unpretty_ip(gethostbyname(address[0])),
433437
address[1],
434-
self._sock_type,
438+
_SOCKET_TYPE_TO_WIZNET[self._sock_type],
435439
)
436440
_the_interface.src_port = 0
437441
if not result:
@@ -674,7 +678,9 @@ def _available(self) -> int:
674678
675679
:return int: Number of bytes available.
676680
"""
677-
return _the_interface.socket_available(self._socknum, self._sock_type)
681+
return _the_interface.socket_available(
682+
self._socknum, _SOCKET_TYPE_TO_WIZNET[self._sock_type]
683+
)
678684

679685
@_check_socket_closed
680686
def settimeout(self, value: Optional[float]) -> None:

0 commit comments

Comments
 (0)