mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-28 16:15:23 +08:00
ZMQ_RECONNECT_IVL socket options added.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
parent
8b8837688a
commit
e8e2944f45
@ -212,8 +212,8 @@ Default value:: 0
|
|||||||
Applicable socket types:: all
|
Applicable socket types:: all
|
||||||
|
|
||||||
|
|
||||||
ZMQ_LINGER: Set linger period for socket shutdown
|
ZMQ_LINGER: Retrieve linger period for socket shutdown
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
The 'ZMQ_LINGER' option shall retrieve the period for pending outbound
|
The 'ZMQ_LINGER' option shall retrieve the period for pending outbound
|
||||||
messages to linger in memory after closing the socket. Value of -1 means
|
messages to linger in memory after closing the socket. Value of -1 means
|
||||||
infinite. Pending messages will be kept until they are fully transferred to
|
infinite. Pending messages will be kept until they are fully transferred to
|
||||||
@ -227,6 +227,17 @@ Option value unit:: milliseconds
|
|||||||
Default value:: -1
|
Default value:: -1
|
||||||
Applicable socket types:: all
|
Applicable socket types:: all
|
||||||
|
|
||||||
|
ZMQ_RECONNECT_IVL: Retrieve reconnect period for connection-based transports
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
The 'ZMQ_RECONNECT' option shall retrieve the period indicating how long it
|
||||||
|
takes for a disconnected underlying connection to attempt to reconnect.
|
||||||
|
|
||||||
|
[horizontal]
|
||||||
|
Option value type:: int
|
||||||
|
Option value unit:: milliseconds
|
||||||
|
Default value:: 100
|
||||||
|
Applicable socket types:: all
|
||||||
|
|
||||||
|
|
||||||
ZMQ_FD: Retrieve file descriptor associated with the socket
|
ZMQ_FD: Retrieve file descriptor associated with the socket
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -232,6 +232,19 @@ Default value:: -1
|
|||||||
Applicable socket types:: all
|
Applicable socket types:: all
|
||||||
|
|
||||||
|
|
||||||
|
ZMQ_RECONNECT_IVL: Set reconnect period for connection-based transports
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
The 'ZMQ_RECONNECT' option shall be set to specify how long it takes for a
|
||||||
|
disconnected underlying connection to attempt to reconnect. The interval
|
||||||
|
can be randomised to some extent by 0MQ to prevent reconnection storms.
|
||||||
|
|
||||||
|
[horizontal]
|
||||||
|
Option value type:: int
|
||||||
|
Option value unit:: milliseconds
|
||||||
|
Default value:: 100
|
||||||
|
Applicable socket types:: all
|
||||||
|
|
||||||
|
|
||||||
RETURN VALUE
|
RETURN VALUE
|
||||||
------------
|
------------
|
||||||
The _zmq_setsockopt()_ function shall return zero if successful. Otherwise it
|
The _zmq_setsockopt()_ function shall return zero if successful. Otherwise it
|
||||||
|
@ -192,6 +192,7 @@ ZMQ_EXPORT int zmq_term (void *context);
|
|||||||
#define ZMQ_EVENTS 15
|
#define ZMQ_EVENTS 15
|
||||||
#define ZMQ_TYPE 16
|
#define ZMQ_TYPE 16
|
||||||
#define ZMQ_LINGER 17
|
#define ZMQ_LINGER 17
|
||||||
|
#define ZMQ_RECONNECT_IVL 18
|
||||||
|
|
||||||
/* Send/recv options. */
|
/* Send/recv options. */
|
||||||
#define ZMQ_NOBLOCK 1
|
#define ZMQ_NOBLOCK 1
|
||||||
|
@ -69,9 +69,6 @@ namespace zmq
|
|||||||
// Maximum number of events the I/O thread can process in one go.
|
// Maximum number of events the I/O thread can process in one go.
|
||||||
max_io_events = 256,
|
max_io_events = 256,
|
||||||
|
|
||||||
// How long to wait (milliseconds) till reattempting to connect.
|
|
||||||
reconnect_period = 100,
|
|
||||||
|
|
||||||
// Should initial connection attempts be delayed?
|
// Should initial connection attempts be delayed?
|
||||||
wait_before_connect = false,
|
wait_before_connect = false,
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ zmq::options_t::options_t () :
|
|||||||
rcvbuf (0),
|
rcvbuf (0),
|
||||||
type (-1),
|
type (-1),
|
||||||
linger (-1),
|
linger (-1),
|
||||||
|
reconnect_ivl (100),
|
||||||
requires_in (false),
|
requires_in (false),
|
||||||
requires_out (false),
|
requires_out (false),
|
||||||
immediate_connect (true)
|
immediate_connect (true)
|
||||||
@ -137,6 +138,18 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
|||||||
}
|
}
|
||||||
linger = *((int*) optval_);
|
linger = *((int*) optval_);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_RECONNECT_IVL:
|
||||||
|
if (optvallen_ != sizeof (int)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (*((int*) optval_) < 0) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
reconnect_ivl = *((int*) optval_);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
@ -147,24 +160,6 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
|||||||
{
|
{
|
||||||
switch (option_) {
|
switch (option_) {
|
||||||
|
|
||||||
case ZMQ_LINGER:
|
|
||||||
if (*optvallen_ < sizeof (int)) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
*((int*) optval_) = linger;
|
|
||||||
*optvallen_ = sizeof (int);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case ZMQ_TYPE:
|
|
||||||
if (*optvallen_ < sizeof (int)) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
*((int*) optval_) = type;
|
|
||||||
*optvallen_ = sizeof (int);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case ZMQ_HWM:
|
case ZMQ_HWM:
|
||||||
if (*optvallen_ < sizeof (uint64_t)) {
|
if (*optvallen_ < sizeof (uint64_t)) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
@ -246,6 +241,34 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
|||||||
*((uint64_t*) optval_) = rcvbuf;
|
*((uint64_t*) optval_) = rcvbuf;
|
||||||
*optvallen_ = sizeof (uint64_t);
|
*optvallen_ = sizeof (uint64_t);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_TYPE:
|
||||||
|
if (*optvallen_ < sizeof (int)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((int*) optval_) = type;
|
||||||
|
*optvallen_ = sizeof (int);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_LINGER:
|
||||||
|
if (*optvallen_ < sizeof (int)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((int*) optval_) = linger;
|
||||||
|
*optvallen_ = sizeof (int);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_RECONNECT_IVL:
|
||||||
|
if (*optvallen_ < sizeof (int)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((int*) optval_) = reconnect_ivl;
|
||||||
|
*optvallen_ = sizeof (int);
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
|
@ -57,6 +57,9 @@ namespace zmq
|
|||||||
// Linger time, in milliseconds.
|
// Linger time, in milliseconds.
|
||||||
int linger;
|
int linger;
|
||||||
|
|
||||||
|
// Interval between attempts to reconnect, in milliseconds.
|
||||||
|
int reconnect_ivl;
|
||||||
|
|
||||||
// These options are never set by the user directly. Instead they are
|
// These options are never set by the user directly. Instead they are
|
||||||
// provided by the specific socket type.
|
// provided by the specific socket type.
|
||||||
bool requires_in;
|
bool requires_in;
|
||||||
|
@ -54,20 +54,21 @@ zmq::zmq_connecter_t::~zmq_connecter_t ()
|
|||||||
rm_fd (handle);
|
rm_fd (handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::zmq_connecter_t::get_reconnect_period ()
|
int zmq::zmq_connecter_t::get_reconnect_ivl ()
|
||||||
{
|
{
|
||||||
#if defined ZMQ_HAVE_WINDOWS
|
#if defined ZMQ_HAVE_WINDOWS
|
||||||
return (reconnect_period + (((int)GetCurrentProcessId () * 13)
|
return (options.reconnect_ivl + (((int) GetCurrentProcessId () * 13)
|
||||||
% reconnect_period));
|
% options.reconnect_ivl));
|
||||||
#else
|
#else
|
||||||
return (reconnect_period + (((int)getpid () * 13) % reconnect_period));
|
return (options.reconnect_ivl + (((int) getpid () * 13)
|
||||||
|
% options.reconnect_ivl));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void zmq::zmq_connecter_t::process_plug ()
|
void zmq::zmq_connecter_t::process_plug ()
|
||||||
{
|
{
|
||||||
if (wait)
|
if (wait)
|
||||||
add_timer (get_reconnect_period (), reconnect_timer_id);
|
add_timer (get_reconnect_ivl (), reconnect_timer_id);
|
||||||
else
|
else
|
||||||
start_connecting ();
|
start_connecting ();
|
||||||
}
|
}
|
||||||
@ -90,7 +91,7 @@ void zmq::zmq_connecter_t::out_event ()
|
|||||||
if (fd == retired_fd) {
|
if (fd == retired_fd) {
|
||||||
tcp_connecter.close ();
|
tcp_connecter.close ();
|
||||||
wait = true;
|
wait = true;
|
||||||
add_timer (get_reconnect_period (), reconnect_timer_id);
|
add_timer (get_reconnect_ivl (), reconnect_timer_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,5 +140,5 @@ void zmq::zmq_connecter_t::start_connecting ()
|
|||||||
|
|
||||||
// Handle any other error condition by eventual reconnect.
|
// Handle any other error condition by eventual reconnect.
|
||||||
wait = true;
|
wait = true;
|
||||||
add_timer (get_reconnect_period (), reconnect_timer_id);
|
add_timer (get_reconnect_ivl (), reconnect_timer_id);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ namespace zmq
|
|||||||
void start_connecting ();
|
void start_connecting ();
|
||||||
|
|
||||||
// Internal function to return the reconnect backoff delay.
|
// Internal function to return the reconnect backoff delay.
|
||||||
int get_reconnect_period ();
|
int get_reconnect_ivl ();
|
||||||
|
|
||||||
// Actual connecting socket.
|
// Actual connecting socket.
|
||||||
tcp_connecter_t tcp_connecter;
|
tcp_connecter_t tcp_connecter;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user