summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2011-02-17 10:33:38 +0100
committerMartin Sustrik <sustrik@250bpm.com>2011-02-17 10:33:38 +0100
commit28f3e87fc6c8c5c7046234bf9a08ae62f26d7f3a (patch)
treee926ac76c70ca42d208977c23f7d9057a0b1315a
parentfbe5d859f461b0deaa6083fdee077e01e9b47b91 (diff)
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>
-rw-r--r--src/config.hpp3
-rw-r--r--src/connect_session.cpp9
-rw-r--r--src/connect_session.hpp2
-rw-r--r--src/zmq_connecter.cpp4
-rw-r--r--src/zmq_connecter.hpp2
5 files changed, 9 insertions, 11 deletions
diff --git a/src/config.hpp b/src/config.hpp
index 1db3bb6..ef75508 100644
--- a/src/config.hpp
+++ b/src/config.hpp
@@ -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
diff --git a/src/connect_session.cpp b/src/connect_session.cpp
index da46568..62799b3 100644
--- a/src/connect_session.cpp
+++ b/src/connect_session.cpp
@@ -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);
}
diff --git a/src/connect_session.hpp b/src/connect_session.hpp
index c93b70c..0c3c90d 100644
--- a/src/connect_session.hpp
+++ b/src/connect_session.hpp
@@ -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 ();
diff --git a/src/zmq_connecter.cpp b/src/zmq_connecter.cpp
index d2638ac..57a6c3b 100644
--- a/src/zmq_connecter.cpp
+++ b/src/zmq_connecter.cpp
@@ -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)
{
diff --git a/src/zmq_connecter.hpp b/src/zmq_connecter.hpp
index ef2cd1a..af7c286 100644
--- a/src/zmq_connecter.hpp
+++ b/src/zmq_connecter.hpp
@@ -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: