Skip to content

Commit

Permalink
Add setsockopt implementation
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
jepler committed Apr 17, 2024
1 parent 47d5c93 commit 72fd989
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions adafruit_wiznet5k/adafruit_wiznet5k_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def inet_ntoa(ip_address: Union[bytes, bytearray]) -> str:

_SOCKET_TYPE_TO_WIZNET = b"\0\x21\2"

SOL_SOCKET = 0xFFF
SO_REUSEADDR = 0x0004

AF_INET = const(3)
_SOCKET_INVALID = const(255)

Expand Down Expand Up @@ -682,6 +685,20 @@ def _available(self) -> int:
self._socknum, _SOCKET_TYPE_TO_WIZNET[self._sock_type]
)

@_check_socket_closed
def setsockopt( # pylint: disable=no-self-use
self, level: int, opt: int, value: any
) -> None:
"""
Set a socket option.
Only SOL_SOCKET SO_REUSEADDR is accepted (and the value is ignored).
Other calls result in OSError."""
if level == SOL_SOCKET and opt == SO_REUSEADDR:
return
raise OSError

@_check_socket_closed
def settimeout(self, value: Optional[float]) -> None:
"""
Expand Down

0 comments on commit 72fd989

Please sign in to comment.