From 5d0cffc52f575ff572751cc85fd43063391a211d Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Sun, 15 May 2011 18:25:43 +0200 Subject: ZMQ_MULTICAST_HOPS socket option added Sets the time-to-live field in every multicast packet sent from the socket. Signed-off-by: Martin Sustrik --- src/options.cpp | 18 ++++++++++++++++++ src/options.hpp | 3 +++ src/pgm_socket.cpp | 14 ++++++++++---- 3 files changed, 31 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/options.cpp b/src/options.cpp index 399fd27..897e0f5 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -29,6 +29,7 @@ zmq::options_t::options_t () : affinity (0), rate (100), recovery_ivl (10000), + multicast_hops (1), sndbuf (0), rcvbuf (0), type (-1), @@ -165,6 +166,14 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, maxmsgsize = *((int64_t*) optval_); return 0; + case ZMQ_MULTICAST_HOPS: + if (optvallen_ != sizeof (int) || *((int*) optval_) <= 0) { + errno = EINVAL; + return -1; + } + multicast_hops = *((int*) optval_); + return 0; + } errno = EINVAL; @@ -301,6 +310,15 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) *optvallen_ = sizeof (int64_t); return 0; + case ZMQ_MULTICAST_HOPS: + if (*optvallen_ < sizeof (int)) { + errno = EINVAL; + return -1; + } + *((int*) optval_) = multicast_hops; + *optvallen_ = sizeof (int); + return 0; + } errno = EINVAL; diff --git a/src/options.hpp b/src/options.hpp index 9ba06e3..53d0197 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -48,6 +48,9 @@ namespace zmq // Reliability time interval [ms]. Default 10 seconds. int recovery_ivl; + // Sets the time-to-live field in every multicast packet sent. + int multicast_hops; + // SO_SNDBUF and SO_RCVBUF to be passed to underlying transport sockets. int sndbuf; int rcvbuf; diff --git a/src/pgm_socket.cpp b/src/pgm_socket.cpp index 8a60ec2..80b80a7 100644 --- a/src/pgm_socket.cpp +++ b/src/pgm_socket.cpp @@ -169,24 +169,30 @@ int zmq::pgm_socket_t::init (bool udp_encapsulation_, const char *network_) } { - const int rcvbuf = (int) options.rcvbuf, - sndbuf = (int) options.sndbuf, - max_tpdu = (int) pgm_max_tpdu; + // Propagate various socket options to the OpenPGM layer. + const int rcvbuf = (int) options.rcvbuf; if (rcvbuf) { if (!pgm_setsockopt (sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof (rcvbuf))) goto err_abort; } + + const int sndbuf = (int) options.sndbuf; if (sndbuf) { if (!pgm_setsockopt (sock, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof (sndbuf))) goto err_abort; } - // Set maximum transport protocol data unit size (TPDU). + const int max_tpdu = (int) pgm_max_tpdu; if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MTU, &max_tpdu, sizeof (max_tpdu))) goto err_abort; + + const int multicast_hops = (int) options.multicast_hops; + if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MULTICAST_HOPS, + &multicast_hops, sizeof (int))) + goto err_abort; } if (receiver) { -- cgit v1.2.3