Skip to content

Commit 157d931

Browse files
author
Onur Keskin
committed
Set SO_REUSEPORT on multicast input sockets for Apple platforms
OpenAndBindInputSocket() only enabled SO_REUSEPORT for QNX (#272, #350). On Darwin, SO_REUSEADDR alone is not enough for two processes to share a UDP multicast port: the second bind fails with EADDRINUSE, the failure is not surfaced, and that DomainParticipant never receives SPDP multicast. Extend the existing QNX conditional to __APPLE__ in UDPv4 and UDPv6 transports. Linux intentionally unchanged: SO_REUSEPORT there load-balances datagrams instead of duplicating delivery. Signed-off-by: Onur Keskin <keskinonur@me.com>
1 parent dd66ef2 commit 157d931

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/cpp/rtps/transport/UDPv4Transport.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,14 @@ eProsimaUDPSocket UDPv4Transport::OpenAndBindInputSocket(
426426
if (is_multicast)
427427
{
428428
getSocketPtr(socket)->set_option(ip::udp::socket::reuse_address(true));
429-
#if defined(__QNX__)
429+
// QNX and Apple require SO_REUSEPORT for multiple processes to all
430+
// receive the same multicast datagrams; SO_REUSEADDR alone makes the
431+
// second bind fail (EADDRINUSE) on Darwin. Linux deliberately omitted:
432+
// there SO_REUSEPORT load-balances instead of duplicating delivery.
433+
#if defined(__QNX__) || defined(__APPLE__)
430434
getSocketPtr(socket)->set_option(asio::detail::socket_option::boolean<
431435
ASIO_OS_DEF(SOL_SOCKET), SO_REUSEPORT>(true));
432-
#endif // if defined(__QNX__)
436+
#endif // if defined(__QNX__) || defined(__APPLE__)
433437
}
434438
else
435439
{

src/cpp/rtps/transport/UDPv6Transport.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,14 @@ eProsimaUDPSocket UDPv6Transport::OpenAndBindInputSocket(
427427
if (is_multicast)
428428
{
429429
getSocketPtr(socket)->set_option(ip::udp::socket::reuse_address(true));
430-
#if defined(__QNX__)
430+
// QNX and Apple require SO_REUSEPORT for multiple processes to all
431+
// receive the same multicast datagrams; SO_REUSEADDR alone makes the
432+
// second bind fail (EADDRINUSE) on Darwin. Linux deliberately omitted:
433+
// there SO_REUSEPORT load-balances instead of duplicating delivery.
434+
#if defined(__QNX__) || defined(__APPLE__)
431435
getSocketPtr(socket)->set_option(asio::detail::socket_option::boolean<
432436
ASIO_OS_DEF(SOL_SOCKET), SO_REUSEPORT>(true));
433-
#endif // if defined(__QNX__)
437+
#endif // if defined(__QNX__) || defined(__APPLE__)
434438
}
435439
else
436440
{

0 commit comments

Comments
 (0)