From 5d0cffc52f575ff572751cc85fd43063391a211d Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Sun, 15 May 2011 18:25:43 +0200 Subject: [PATCH] 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 --- doc/zmq_getsockopt.txt | 15 ++++++++++++++- doc/zmq_setsockopt.txt | 12 ++++++++++++ include/zmq.h | 1 + src/options.cpp | 18 ++++++++++++++++++ src/options.hpp | 3 +++ src/pgm_socket.cpp | 14 ++++++++++---- 6 files changed, 58 insertions(+), 5 deletions(-) diff --git a/doc/zmq_getsockopt.txt b/doc/zmq_getsockopt.txt index 9d67ce26..97b4032a 100644 --- a/doc/zmq_getsockopt.txt +++ b/doc/zmq_getsockopt.txt @@ -283,7 +283,7 @@ Applicable socket types:: all, only for connection-oriented transports ZMQ_MAXMSGSIZE: Maximum acceptable inbound message size ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The options shall retrieve limit for the inbound messages. If a peer sends +The option shall retrieve limit for the inbound messages. If a peer sends a message larger than ZMQ_MAXMSGSIZE it is disconnected. Value of -1 means 'no limit'. @@ -294,6 +294,19 @@ Default value:: -1 Applicable socket types:: all +ZMQ_MULTICAST_HOPS: Maximum network hops for multicast packets +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The option shell retrieve time-to-live used for outbound multicast packets. +The default of 1 means that the multicast packets don't leave the local network. + +[horizontal] +Option value type:: int +Option value unit:: network hops +Default value:: 1 +Applicable socket types:: all, when using multicast transports + + ZMQ_FD: Retrieve file descriptor associated with the socket ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The 'ZMQ_FD' option shall retrieve the file descriptor associated with the diff --git a/doc/zmq_setsockopt.txt b/doc/zmq_setsockopt.txt index f5c873ec..ed3b3a76 100644 --- a/doc/zmq_setsockopt.txt +++ b/doc/zmq_setsockopt.txt @@ -296,6 +296,18 @@ Option value unit:: bytes Default value:: -1 Applicable socket types:: all +ZMQ_MULTICAST_HOPS: Maximum network hops for multicast packets +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Sets the time-to-live field in every multicast packet sent from this socket. +The default is 1 which means that the multicast packets don't leave the local +network. + +[horizontal] +Option value type:: int +Option value unit:: network hops +Default value:: 1 +Applicable socket types:: all, when using multicast transports RETURN VALUE ------------ diff --git a/include/zmq.h b/include/zmq.h index 2d01e249..40dffd96 100644 --- a/include/zmq.h +++ b/include/zmq.h @@ -179,6 +179,7 @@ ZMQ_EXPORT int zmq_term (void *context); #define ZMQ_MAXMSGSIZE 22 #define ZMQ_SNDHWM 23 #define ZMQ_RCVHWM 24 +#define ZMQ_MULTICAST_HOPS 25 /* Send/recv options. */ #define ZMQ_DONTWAIT 1 diff --git a/src/options.cpp b/src/options.cpp index 399fd278..897e0f55 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 9ba06e3c..53d0197d 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 8a60ec25..80b80a76 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) {