diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2012-04-16 07:47:00 +0200 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2012-04-17 07:34:37 +0200 |
commit | dc4ed5a7b59f1d5b4e4f7fb4b6e29ecaf5e6cc5c (patch) | |
tree | 29987586f7012a31c187de491edc99aea174473b /src/surveyor.cpp | |
parent | 443d06f894751062da6d69238ce09f6fbfc27577 (diff) |
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 <sustrik@250bpm.com>
Diffstat (limited to 'src/surveyor.cpp')
-rw-r--r-- | src/surveyor.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>. */ +#include <algorithm> + #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_) : |