mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 10:52:56 +01:00
Problem: relicensing forced to remove support for ZMQ_RECONNECT_IVL_MAX option
Solution: reimplement support for ZMQ_RECONNECT_IVL_MAX without knowledge of the previous code.
This commit is contained in:
parent
1a921db728
commit
de1bd5c8e7
@ -186,6 +186,7 @@ zmq::options_t::options_t () :
|
|||||||
tcp_maxrt (0),
|
tcp_maxrt (0),
|
||||||
reconnect_stop (0),
|
reconnect_stop (0),
|
||||||
reconnect_ivl (100),
|
reconnect_ivl (100),
|
||||||
|
reconnect_ivl_max (0),
|
||||||
backlog (100),
|
backlog (100),
|
||||||
maxmsgsize (-1),
|
maxmsgsize (-1),
|
||||||
rcvtimeo (-1),
|
rcvtimeo (-1),
|
||||||
@ -400,11 +401,11 @@ int zmq::options_t::setsockopt (int option_,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ZMQ_RECONNECT_IVL_MAX:
|
case ZMQ_RECONNECT_IVL_MAX:
|
||||||
#ifdef ZMQ_HAVE_WINDOWS
|
if (is_int && value >= 0) {
|
||||||
return WSAEOPNOTSUPP;
|
reconnect_ivl_max = value;
|
||||||
#else
|
return 0;
|
||||||
return -EOPNOTSUPP;
|
}
|
||||||
#endif
|
break;
|
||||||
|
|
||||||
case ZMQ_BACKLOG:
|
case ZMQ_BACKLOG:
|
||||||
if (is_int && value >= 0) {
|
if (is_int && value >= 0) {
|
||||||
@ -1048,11 +1049,11 @@ int zmq::options_t::getsockopt (int option_,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ZMQ_RECONNECT_IVL_MAX:
|
case ZMQ_RECONNECT_IVL_MAX:
|
||||||
#ifdef ZMQ_HAVE_WINDOWS
|
if (is_int) {
|
||||||
return WSAEOPNOTSUPP;
|
*value = reconnect_ivl_max;
|
||||||
#else
|
return 0;
|
||||||
return -EOPNOTSUPP;
|
}
|
||||||
#endif
|
break;
|
||||||
|
|
||||||
case ZMQ_BACKLOG:
|
case ZMQ_BACKLOG:
|
||||||
if (is_int) {
|
if (is_int) {
|
||||||
|
@ -100,6 +100,10 @@ struct options_t
|
|||||||
// Default 100ms
|
// Default 100ms
|
||||||
int reconnect_ivl;
|
int reconnect_ivl;
|
||||||
|
|
||||||
|
// Maximum interval between attempts to reconnect, in milliseconds.
|
||||||
|
// Default 0ms (meaning maximum interval is disabled)
|
||||||
|
int reconnect_ivl_max;
|
||||||
|
|
||||||
// Maximum backlog for pending connections.
|
// Maximum backlog for pending connections.
|
||||||
int backlog;
|
int backlog;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ zmq::stream_connecter_base_t::stream_connecter_base_t (
|
|||||||
_socket (session_->get_socket ()),
|
_socket (session_->get_socket ()),
|
||||||
_delayed_start (delayed_start_),
|
_delayed_start (delayed_start_),
|
||||||
_reconnect_timer_started (false),
|
_reconnect_timer_started (false),
|
||||||
_current_reconnect_ivl (options.reconnect_ivl),
|
_current_reconnect_ivl (-1),
|
||||||
_session (session_)
|
_session (session_)
|
||||||
{
|
{
|
||||||
zmq_assert (_addr);
|
zmq_assert (_addr);
|
||||||
@ -85,19 +85,33 @@ void zmq::stream_connecter_base_t::add_reconnect_timer ()
|
|||||||
|
|
||||||
int zmq::stream_connecter_base_t::get_new_reconnect_ivl ()
|
int zmq::stream_connecter_base_t::get_new_reconnect_ivl ()
|
||||||
{
|
{
|
||||||
// TODO should the random jitter be really based on the configured initial
|
if (options.reconnect_ivl_max > 0) {
|
||||||
// reconnect interval options.reconnect_ivl, or better on the
|
int candidate_interval = 0;
|
||||||
// _current_reconnect_ivl?
|
if (_current_reconnect_ivl == -1)
|
||||||
|
candidate_interval = options.reconnect_ivl;
|
||||||
|
else if (_current_reconnect_ivl > std::numeric_limits<int>::max () / 2)
|
||||||
|
candidate_interval = std::numeric_limits<int>::max ();
|
||||||
|
else
|
||||||
|
candidate_interval = _current_reconnect_ivl * 2;
|
||||||
|
|
||||||
// The new interval is the current interval + random value.
|
if (candidate_interval > options.reconnect_ivl_max)
|
||||||
|
_current_reconnect_ivl = options.reconnect_ivl_max;
|
||||||
|
else
|
||||||
|
_current_reconnect_ivl = candidate_interval;
|
||||||
|
return _current_reconnect_ivl;
|
||||||
|
} else {
|
||||||
|
if (_current_reconnect_ivl == -1)
|
||||||
|
_current_reconnect_ivl = options.reconnect_ivl;
|
||||||
|
// The new interval is the base interval + random value.
|
||||||
const int random_jitter = generate_random () % options.reconnect_ivl;
|
const int random_jitter = generate_random () % options.reconnect_ivl;
|
||||||
const int interval =
|
const int interval =
|
||||||
_current_reconnect_ivl < std::numeric_limits<int>::max () - random_jitter
|
_current_reconnect_ivl
|
||||||
|
< std::numeric_limits<int>::max () - random_jitter
|
||||||
? _current_reconnect_ivl + random_jitter
|
? _current_reconnect_ivl + random_jitter
|
||||||
: std::numeric_limits<int>::max ();
|
: std::numeric_limits<int>::max ();
|
||||||
|
|
||||||
return interval;
|
return interval;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void zmq::stream_connecter_base_t::rm_handle ()
|
void zmq::stream_connecter_base_t::rm_handle ()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user