mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-09 06:17:08 +00:00
Do not crash on discovery on WSL (#283)
This commit is contained in:
parent
a817d9cab1
commit
723fca9d08
@ -46,9 +46,14 @@ class _DiscoverProtocol(asyncio.DatagramProtocol):
|
|||||||
def connection_made(self, transport) -> None:
|
def connection_made(self, transport) -> None:
|
||||||
"""Set socket options for broadcasting."""
|
"""Set socket options for broadcasting."""
|
||||||
self.transport = transport
|
self.transport = transport
|
||||||
|
|
||||||
sock = transport.get_extra_info("socket")
|
sock = transport.get_extra_info("socket")
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||||
|
try:
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
|
except OSError as ex: # WSL does not support SO_REUSEADDR, see #246
|
||||||
|
_LOGGER.debug("Unable to set SO_REUSEADDR: %s", ex)
|
||||||
|
|
||||||
if self.interface is not None:
|
if self.interface is not None:
|
||||||
sock.setsockopt(
|
sock.setsockopt(
|
||||||
socket.SOL_SOCKET, socket.SO_BINDTODEVICE, self.interface.encode()
|
socket.SOL_SOCKET, socket.SO_BINDTODEVICE, self.interface.encode()
|
||||||
|
Loading…
Reference in New Issue
Block a user