Added SO_REUSEPORT socket option for UDP recv ports (#3237)

* Added SO_REUSEPORT socket option for UDP multicast recv ports
This commit is contained in:
Byron Mallett 2018-08-31 20:36:34 +12:00 committed by Luca Boccassi
parent 50dbd80c51
commit d8f3b283f8

View File

@ -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<char *> (&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;