summaryrefslogtreecommitdiff
path: root/src/tcp_connecter.cpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2011-07-28 09:02:54 +0200
committerMartin Sustrik <sustrik@250bpm.com>2011-07-28 09:02:54 +0200
commit6e987428d49558a8a7b08795bcc429f720bb3874 (patch)
tree91af699d90c3aa3c0e6e13e4aa9248dd8cff8f6c /src/tcp_connecter.cpp
parentce7a9a58e3a0d13db53f7e0b4c17b3185a8c0e1a (diff)
Precise reconnect interval randomised
Till now the random fraction of the reconnect interval was computed based on process ID. This patch uses pseudo-random generated (seeded by exact time of when the process was started) to compute the interval. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/tcp_connecter.cpp')
-rw-r--r--src/tcp_connecter.cpp9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp
index 30e206a..6deb145 100644
--- a/src/tcp_connecter.cpp
+++ b/src/tcp_connecter.cpp
@@ -25,6 +25,7 @@
#include "tcp_engine.hpp"
#include "io_thread.hpp"
#include "platform.hpp"
+#include "random.hpp"
#include "ip.hpp"
#include "err.hpp"
@@ -154,15 +155,9 @@ void zmq::tcp_connecter_t::add_reconnect_timer()
int zmq::tcp_connecter_t::get_new_reconnect_ivl ()
{
-#if defined ZMQ_HAVE_WINDOWS
- int pid = (int) GetCurrentProcessId ();
-#else
- int pid = (int) getpid ();
-#endif
-
// The new interval is the current interval + random value.
int this_interval = current_reconnect_ivl +
- ((pid * 13) % options.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.