mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 18:55:10 +01:00
Add delay before reconnecting
So far ZMQ_RECONNECT_IVL delay was used only when TCP connect failed. Now it is used even if connect succeeds and the peer closes the connection afterwards. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
parent
fbe5d859f4
commit
28f3e87fc6
@ -65,9 +65,6 @@ namespace zmq
|
||||
// Maximum number of events the I/O thread can process in one go.
|
||||
max_io_events = 256,
|
||||
|
||||
// Should initial connection attempts be delayed?
|
||||
wait_before_connect = false,
|
||||
|
||||
// Maximal delay to process command in API thread (in CPU ticks).
|
||||
// 3,000,000 ticks equals to 1 - 2 milliseconds on current CPUs.
|
||||
// Note that delay is only applied when there is continuous stream of
|
||||
|
@ -38,10 +38,10 @@ zmq::connect_session_t::~connect_session_t ()
|
||||
void zmq::connect_session_t::process_plug ()
|
||||
{
|
||||
// Start connection process immediately.
|
||||
start_connecting ();
|
||||
start_connecting (false);
|
||||
}
|
||||
|
||||
void zmq::connect_session_t::start_connecting ()
|
||||
void zmq::connect_session_t::start_connecting (bool wait_)
|
||||
{
|
||||
// Choose I/O thread to run connecter in. Given that we are already
|
||||
// running in an I/O thread, there must be at least one available.
|
||||
@ -54,7 +54,8 @@ void zmq::connect_session_t::start_connecting ()
|
||||
if (protocol == "tcp" || protocol == "ipc") {
|
||||
|
||||
zmq_connecter_t *connecter = new (std::nothrow) zmq_connecter_t (
|
||||
io_thread, this, options, protocol.c_str (), address.c_str ());
|
||||
io_thread, this, options, protocol.c_str (), address.c_str (),
|
||||
wait_);
|
||||
zmq_assert (connecter);
|
||||
launch_child (connecter);
|
||||
return;
|
||||
@ -112,6 +113,6 @@ void zmq::connect_session_t::attached (const blob_t &peer_identity_)
|
||||
void zmq::connect_session_t::detached ()
|
||||
{
|
||||
// Reconnect.
|
||||
start_connecting ();
|
||||
start_connecting (true);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace zmq
|
||||
void detached ();
|
||||
|
||||
// Start the connection process.
|
||||
void start_connecting ();
|
||||
void start_connecting (bool wait_);
|
||||
|
||||
// Command handlers.
|
||||
void process_plug ();
|
||||
|
@ -35,11 +35,11 @@
|
||||
|
||||
zmq::zmq_connecter_t::zmq_connecter_t (class io_thread_t *io_thread_,
|
||||
class session_t *session_, const options_t &options_,
|
||||
const char *protocol_, const char *address_) :
|
||||
const char *protocol_, const char *address_, bool wait_) :
|
||||
own_t (io_thread_, options_),
|
||||
io_object_t (io_thread_),
|
||||
handle_valid (false),
|
||||
wait (wait_before_connect),
|
||||
wait (wait_),
|
||||
session (session_),
|
||||
current_reconnect_ivl(options.reconnect_ivl)
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ namespace zmq
|
||||
// connection process.
|
||||
zmq_connecter_t (class io_thread_t *io_thread_,
|
||||
class session_t *session_, const options_t &options_,
|
||||
const char *protocol_, const char *address_);
|
||||
const char *protocol_, const char *address_, bool delay_);
|
||||
~zmq_connecter_t ();
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user