@@ -147,9 +147,16 @@ def inet_ntoa(ip_address: Union[bytes, bytearray]) -> str:
147
147
return _the_interface .pretty_ip (ip_address )
148
148
149
149
150
- SOCK_STREAM = const (0x21 ) # TCP
151
- _TCP_MODE = 80
152
- SOCK_DGRAM = const (0x02 ) # UDP
150
+ # These must match circuitpython "socketpoool" values. However, we cannot
151
+ # depend on socketpool being importable, so hard-code them here.
152
+ SOCK_STREAM = 1
153
+ SOCK_DGRAM = 2
154
+
155
+ _SOCKET_TYPE_TO_WIZNET = b"\0 \x21 \2 "
156
+
157
+ SOL_SOCKET = 0xFFF
158
+ SO_REUSEADDR = 0x0004
159
+
153
160
AF_INET = const (3 )
154
161
_SOCKET_INVALID = const (255 )
155
162
@@ -440,7 +447,7 @@ def connect(self, address: Tuple[str, int]) -> None:
440
447
self ._socknum ,
441
448
_the_interface .unpretty_ip (gethostbyname (address [0 ])),
442
449
address [1 ],
443
- self ._sock_type ,
450
+ _SOCKET_TYPE_TO_WIZNET [ self ._sock_type ] ,
444
451
)
445
452
_the_interface .src_port = 0
446
453
if not result :
@@ -693,7 +700,23 @@ def _available(self) -> int:
693
700
694
701
:return int: Number of bytes available.
695
702
"""
696
- return _the_interface .socket_available (self ._socknum , self ._sock_type )
703
+ return _the_interface .socket_available (
704
+ self ._socknum , _SOCKET_TYPE_TO_WIZNET [self ._sock_type ]
705
+ )
706
+
707
+ @_check_socket_closed
708
+ def setsockopt ( # pylint: disable=no-self-use
709
+ self , level : int , opt : int , value : any
710
+ ) -> None :
711
+ """
712
+ Set a socket option.
713
+
714
+ Only SOL_SOCKET SO_REUSEADDR is accepted (and the value is ignored).
715
+
716
+ Other calls result in OSError."""
717
+ if level == SOL_SOCKET and opt == SO_REUSEADDR :
718
+ return
719
+ raise OSError
697
720
698
721
@_check_socket_closed
699
722
def settimeout (self , value : Optional [float ]) -> None :
0 commit comments