summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.hpp3
-rw-r--r--src/options.cpp59
-rw-r--r--src/options.hpp3
-rw-r--r--src/zmq_connecter.cpp15
-rw-r--r--src/zmq_connecter.hpp2
5 files changed, 53 insertions, 29 deletions
diff --git a/src/config.hpp b/src/config.hpp
index 3f57be2..7d5ce52 100644
--- a/src/config.hpp
+++ b/src/config.hpp
@@ -69,9 +69,6 @@ namespace zmq
// Maximum number of events the I/O thread can process in one go.
max_io_events = 256,
- // How long to wait (milliseconds) till reattempting to connect.
- reconnect_period = 100,
-
// Should initial connection attempts be delayed?
wait_before_connect = false,
diff --git a/src/options.cpp b/src/options.cpp
index c9e330f..5e92e74 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -35,6 +35,7 @@ zmq::options_t::options_t () :
rcvbuf (0),
type (-1),
linger (-1),
+ reconnect_ivl (100),
requires_in (false),
requires_out (false),
immediate_connect (true)
@@ -137,6 +138,18 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
}
linger = *((int*) optval_);
return 0;
+
+ case ZMQ_RECONNECT_IVL:
+ if (optvallen_ != sizeof (int)) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (*((int*) optval_) < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ reconnect_ivl = *((int*) optval_);
+ return 0;
}
errno = EINVAL;
@@ -147,24 +160,6 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
{
switch (option_) {
- case ZMQ_LINGER:
- if (*optvallen_ < sizeof (int)) {
- errno = EINVAL;
- return -1;
- }
- *((int*) optval_) = linger;
- *optvallen_ = sizeof (int);
- return 0;
-
- case ZMQ_TYPE:
- if (*optvallen_ < sizeof (int)) {
- errno = EINVAL;
- return -1;
- }
- *((int*) optval_) = type;
- *optvallen_ = sizeof (int);
- return 0;
-
case ZMQ_HWM:
if (*optvallen_ < sizeof (uint64_t)) {
errno = EINVAL;
@@ -246,6 +241,34 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
*((uint64_t*) optval_) = rcvbuf;
*optvallen_ = sizeof (uint64_t);
return 0;
+
+ case ZMQ_TYPE:
+ if (*optvallen_ < sizeof (int)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((int*) optval_) = type;
+ *optvallen_ = sizeof (int);
+ return 0;
+
+ case ZMQ_LINGER:
+ if (*optvallen_ < sizeof (int)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((int*) optval_) = linger;
+ *optvallen_ = sizeof (int);
+ return 0;
+
+ case ZMQ_RECONNECT_IVL:
+ if (*optvallen_ < sizeof (int)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((int*) optval_) = reconnect_ivl;
+ *optvallen_ = sizeof (int);
+ return 0;
+
}
errno = EINVAL;
diff --git a/src/options.hpp b/src/options.hpp
index 9b57ab6..47a0d63 100644
--- a/src/options.hpp
+++ b/src/options.hpp
@@ -57,6 +57,9 @@ namespace zmq
// Linger time, in milliseconds.
int linger;
+ // Interval between attempts to reconnect, in milliseconds.
+ int reconnect_ivl;
+
// These options are never set by the user directly. Instead they are
// provided by the specific socket type.
bool requires_in;
diff --git a/src/zmq_connecter.cpp b/src/zmq_connecter.cpp
index 82c3ca1..2dd9576 100644
--- a/src/zmq_connecter.cpp
+++ b/src/zmq_connecter.cpp
@@ -54,20 +54,21 @@ zmq::zmq_connecter_t::~zmq_connecter_t ()
rm_fd (handle);
}
-int zmq::zmq_connecter_t::get_reconnect_period ()
+int zmq::zmq_connecter_t::get_reconnect_ivl ()
{
#if defined ZMQ_HAVE_WINDOWS
- return (reconnect_period + (((int)GetCurrentProcessId () * 13)
- % reconnect_period));
+ return (options.reconnect_ivl + (((int) GetCurrentProcessId () * 13)
+ % options.reconnect_ivl));
#else
- return (reconnect_period + (((int)getpid () * 13) % reconnect_period));
+ return (options.reconnect_ivl + (((int) getpid () * 13)
+ % options.reconnect_ivl));
#endif
}
void zmq::zmq_connecter_t::process_plug ()
{
if (wait)
- add_timer (get_reconnect_period (), reconnect_timer_id);
+ add_timer (get_reconnect_ivl (), reconnect_timer_id);
else
start_connecting ();
}
@@ -90,7 +91,7 @@ void zmq::zmq_connecter_t::out_event ()
if (fd == retired_fd) {
tcp_connecter.close ();
wait = true;
- add_timer (get_reconnect_period (), reconnect_timer_id);
+ add_timer (get_reconnect_ivl (), reconnect_timer_id);
return;
}
@@ -139,5 +140,5 @@ void zmq::zmq_connecter_t::start_connecting ()
// Handle any other error condition by eventual reconnect.
wait = true;
- add_timer (get_reconnect_period (), reconnect_timer_id);
+ add_timer (get_reconnect_ivl (), reconnect_timer_id);
}
diff --git a/src/zmq_connecter.hpp b/src/zmq_connecter.hpp
index 3af78cb..f9ff7ba 100644
--- a/src/zmq_connecter.hpp
+++ b/src/zmq_connecter.hpp
@@ -56,7 +56,7 @@ namespace zmq
void start_connecting ();
// Internal function to return the reconnect backoff delay.
- int get_reconnect_period ();
+ int get_reconnect_ivl ();
// Actual connecting socket.
tcp_connecter_t tcp_connecter;