mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-26 10:32:58 +01:00
Problem: process_plug, get_new_reconnect_ivl and add_reconnect_timer duplicated across subclasses of stream_connector_base_t
Solution: pull up to stream_connector_base_t
This commit is contained in:
@@ -35,7 +35,6 @@
|
||||
#include "tcp_connecter.hpp"
|
||||
#include "stream_engine.hpp"
|
||||
#include "io_thread.hpp"
|
||||
#include "random.hpp"
|
||||
#include "err.hpp"
|
||||
#include "ip.hpp"
|
||||
#include "tcp.hpp"
|
||||
@@ -81,14 +80,6 @@ zmq::tcp_connecter_t::~tcp_connecter_t ()
|
||||
zmq_assert (!_connect_timer_started);
|
||||
}
|
||||
|
||||
void zmq::tcp_connecter_t::process_plug ()
|
||||
{
|
||||
if (_delayed_start)
|
||||
add_reconnect_timer ();
|
||||
else
|
||||
start_connecting ();
|
||||
}
|
||||
|
||||
void zmq::tcp_connecter_t::process_term (int linger_)
|
||||
{
|
||||
if (_connect_timer_started) {
|
||||
@@ -208,32 +199,6 @@ void zmq::tcp_connecter_t::add_connect_timer ()
|
||||
}
|
||||
}
|
||||
|
||||
void zmq::tcp_connecter_t::add_reconnect_timer ()
|
||||
{
|
||||
if (options.reconnect_ivl != -1) {
|
||||
const int interval = get_new_reconnect_ivl ();
|
||||
add_timer (interval, reconnect_timer_id);
|
||||
_socket->event_connect_retried (_endpoint, interval);
|
||||
_reconnect_timer_started = true;
|
||||
}
|
||||
}
|
||||
|
||||
int zmq::tcp_connecter_t::get_new_reconnect_ivl ()
|
||||
{
|
||||
// The new interval is the current interval + random value.
|
||||
const int interval =
|
||||
_current_reconnect_ivl + generate_random () % options.reconnect_ivl;
|
||||
|
||||
// Only change the current reconnect interval if the maximum reconnect
|
||||
// interval was set and if it's larger than the reconnect interval.
|
||||
if (options.reconnect_ivl_max > 0
|
||||
&& options.reconnect_ivl_max > options.reconnect_ivl)
|
||||
// Calculate the next interval
|
||||
_current_reconnect_ivl =
|
||||
std::min (_current_reconnect_ivl * 2, options.reconnect_ivl_max);
|
||||
return interval;
|
||||
}
|
||||
|
||||
int zmq::tcp_connecter_t::open ()
|
||||
{
|
||||
zmq_assert (_s == retired_fd);
|
||||
|
||||
Reference in New Issue
Block a user