Fix emulated hue SO_REUSEPORT when creating the upnp socket for proper sharing (#86916)

Co-authored-by: J. Nick Koston <nick@koston.org>
fixes undefined
This commit is contained in:
Nicklas Johnson 2023-02-05 12:57:22 -08:00 committed by GitHub
parent d389de71f5
commit 49d7bbe55d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
from contextlib import suppress
import logging import logging
import socket import socket
from typing import cast from typing import cast
@ -150,7 +151,12 @@ async def async_create_upnp_datagram_endpoint(
ssdp_socket.setblocking(False) ssdp_socket.setblocking(False)
# Required for receiving multicast # Required for receiving multicast
# Note: some code duplication from async_upnp_client/ssdp.py here.
ssdp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) ssdp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
with suppress(AttributeError):
ssdp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
ssdp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
ssdp_socket.setsockopt( ssdp_socket.setsockopt(
socket.SOL_IP, socket.IP_MULTICAST_IF, socket.inet_aton(host_ip_addr) socket.SOL_IP, socket.IP_MULTICAST_IF, socket.inet_aton(host_ip_addr)