From dc4ed5a7b59f1d5b4e4f7fb4b6e29ecaf5e6cc5c Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Mon, 16 Apr 2012 07:47:00 +0200 Subject: XS_SURVEY_TIMEOUT socket option added. It can be used to timeout the survey. Value is in milliseconds and -1 means infinite (default). Signed-off-by: Martin Sustrik --- src/surveyor.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/surveyor.cpp') diff --git a/src/surveyor.cpp b/src/surveyor.cpp index c5216bd..b76128b 100644 --- a/src/surveyor.cpp +++ b/src/surveyor.cpp @@ -18,6 +18,8 @@ along with this program. If not, see . */ +#include + #include "surveyor.hpp" #include "err.hpp" #include "msg.hpp" @@ -28,7 +30,8 @@ xs::surveyor_t::surveyor_t (class ctx_t *parent_, uint32_t tid_, int sid_) : xsurveyor_t (parent_, tid_, sid_), receiving_responses (false), - survey_id (generate_random ()) + survey_id (generate_random ()), + timeout (0) { options.type = XS_SURVEYOR; } @@ -68,6 +71,12 @@ int xs::surveyor_t::xsend (msg_t *msg_, int flags_) // Start waiting for responses from the peers. receiving_responses = true; + // Set up the timeout for the survey (-1 means infinite). + if (!options.survey_timeout) + timeout = -1; + else + timeout = clock.now_ms () + options.survey_timeout; + return 0; } @@ -121,6 +130,16 @@ bool xs::surveyor_t::xhas_out () return xsurveyor_t::xhas_out (); } +int xs::surveyor_t::rcvtimeo () +{ + int t = timeout - clock.now_ms (); + if (t < 0) + return options.rcvtimeo; + if (options.rcvtimeo < 0) + return t; + return std::min (t, options.rcvtimeo); +} + xs::surveyor_session_t::surveyor_session_t (io_thread_t *io_thread_, bool connect_, socket_base_t *socket_, const options_t &options_, const char *protocol_, const char *address_) : -- cgit v1.2.3