Skip to content

Commit 72fd989

Browse files
committed
Add setsockopt implementation
This is called by httpserver, and also the ssl support in the core assumes that any socket object provides setsockopt (it passes along calls on wrapped sockets, but eagerly fetches the "setsockopt" property on construction of the SSL wrapper object)
1 parent 47d5c93 commit 72fd989

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ def inet_ntoa(ip_address: Union[bytes, bytearray]) -> str:
152152

153153
_SOCKET_TYPE_TO_WIZNET = b"\0\x21\2"
154154

155+
SOL_SOCKET = 0xFFF
156+
SO_REUSEADDR = 0x0004
157+
155158
AF_INET = const(3)
156159
_SOCKET_INVALID = const(255)
157160

@@ -682,6 +685,20 @@ def _available(self) -> int:
682685
self._socknum, _SOCKET_TYPE_TO_WIZNET[self._sock_type]
683686
)
684687

688+
@_check_socket_closed
689+
def setsockopt( # pylint: disable=no-self-use
690+
self, level: int, opt: int, value: any
691+
) -> None:
692+
"""
693+
Set a socket option.
694+
695+
Only SOL_SOCKET SO_REUSEADDR is accepted (and the value is ignored).
696+
697+
Other calls result in OSError."""
698+
if level == SOL_SOCKET and opt == SO_REUSEADDR:
699+
return
700+
raise OSError
701+
685702
@_check_socket_closed
686703
def settimeout(self, value: Optional[float]) -> None:
687704
"""

0 commit comments

Comments
 (0)