summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2011-05-15 18:25:43 +0200
committerMartin Sustrik <sustrik@250bpm.com>2011-05-15 18:25:43 +0200
commit5d0cffc52f575ff572751cc85fd43063391a211d (patch)
tree2f61c1e0f6060fc756feefef11fcafa1c168d16f /src
parent49df2f416cd43e9e18f3dbd964271c5cca835729 (diff)
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 <sustrik@250bpm.com>
Diffstat (limited to 'src')
-rw-r--r--src/options.cpp18
-rw-r--r--src/options.hpp3
-rw-r--r--src/pgm_socket.cpp14
3 files changed, 31 insertions, 4 deletions
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) {