From d8f3b283f85c041756aa8dc792955acd0c783081 Mon Sep 17 00:00:00 2001 From: Byron Mallett Date: Fri, 31 Aug 2018 20:36:34 +1200 Subject: [PATCH] Added SO_REUSEPORT socket option for UDP recv ports (#3237) * Added SO_REUSEPORT socket option for UDP multicast recv ports --- src/udp_engine.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/udp_engine.cpp b/src/udp_engine.cpp index e070ccb5..052b4437 100644 --- a/src/udp_engine.cpp +++ b/src/udp_engine.cpp @@ -206,10 +206,21 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) bool multicast = udp_addr->is_mcast (); if (multicast) { + // Multicast addresses should be allowed to bind to more than + // one port as all ports should receive the message +#ifdef SO_REUSEPORT + rc = setsockopt (_fd, SOL_SOCKET, SO_REUSEPORT, + reinterpret_cast (&on), sizeof (on)); +#ifdef ZMQ_HAVE_WINDOWS + wsa_assert (rc != SOCKET_ERROR); +#else + errno_assert (rc == 0); +#endif +#endif + // In multicast we should bind ANY and use the mreq struct to // specify the interface any.set_port (bind_addr->port ()); - real_bind_addr = &any; } else { real_bind_addr = bind_addr;