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>
This commit is contained in:
Martin Sustrik 2011-05-15 18:25:43 +02:00
parent 49df2f416c
commit 5d0cffc52f
6 changed files with 58 additions and 5 deletions

View File

@ -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

View File

@ -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
------------

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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) {