From c6a242d225ccab42450bf640832121fee52c7fc5 Mon Sep 17 00:00:00 2001 From: Daniel Alexander <5389473+DAlexanderNZ@users.noreply.github.com> Date: Sun, 10 May 2026 10:38:32 +1200 Subject: [PATCH] Handle port reuse errors when port reuse isn't allowed on target platform. --- src/receive.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/receive.rs b/src/receive.rs index fc373eab..15f4141e 100644 --- a/src/receive.rs +++ b/src/receive.rs @@ -1387,7 +1387,13 @@ fn create_unix_socket(addr: SocketAddr) -> Result { let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))?; // Multiple different processes might want to listen to the sACN stream so therefore need to allow re-using the ACN port. - socket.set_reuse_port(true)?; + // If the OS doesn't support SO_REUSEPORT then ignore the error and continue. + // FreeRTOS on ESP32 doesn't support SO_REUSEPORT and so this allows the library to be used on the platform without issue. + if let Err(e) = socket.set_reuse_port(true) { + if e.raw_os_error() != Some(libc::ENOPROTOOPT) { + return Err(e.into()); + } + } socket.set_reuse_address(true)?; let socket_addr = @@ -1398,7 +1404,11 @@ fn create_unix_socket(addr: SocketAddr) -> Result { let socket = Socket::new(Domain::IPV6, Type::DGRAM, Some(Protocol::UDP))?; // Multiple different processes might want to listen to the sACN stream so therefore need to allow re-using the ACN port. - socket.set_reuse_port(true)?; + if let Err(e) = socket.set_reuse_port(true) { + if e.raw_os_error() != Some(libc::ENOPROTOOPT) { + return Err(e.into()); + } + } socket.set_reuse_address(true)?; let socket_addr =