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:
Martin Sustrik 2011-02-17 10:33:38 +01:00
parent fbe5d859f4
commit 28f3e87fc6
5 changed files with 9 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

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