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/socket_base.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/socket_base.cpp')
-rw-r--r-- | src/socket_base.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/socket_base.cpp b/src/socket_base.cpp index df182f1..1f45fd6 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -552,13 +552,13 @@ int xs::socket_base_t::send (msg_t *msg_, int flags_) // In case of non-blocking send we'll simply propagate // the error - including EAGAIN - up the stack. - if (flags_ & XS_DONTWAIT || options.sndtimeo == 0) + int timeout = sndtimeo (); + if (flags_ & XS_DONTWAIT || timeout == 0) return -1; // Compute the time when the timeout should occur. // If the timeout is infite, don't care. clock_t clock ; - int timeout = options.sndtimeo; uint64_t end = timeout < 0 ? 0 : (clock.now_ms () + timeout); // Oops, we couldn't send the message. Wait for the next @@ -627,7 +627,8 @@ int xs::socket_base_t::recv (msg_t *msg_, int flags_) // For non-blocking recv, commands are processed in case there's an // activate_reader command already waiting int a command pipe. // If it's not, return EAGAIN. - if (flags_ & XS_DONTWAIT || options.rcvtimeo == 0) { + int timeout = rcvtimeo (); + if (flags_ & XS_DONTWAIT || timeout == 0) { if (unlikely (process_commands (0, false) != 0)) return -1; ticks = 0; @@ -643,7 +644,6 @@ int xs::socket_base_t::recv (msg_t *msg_, int flags_) // Compute the time when the timeout should occur. // If the timeout is infite, don't care. clock_t clock ; - int timeout = options.rcvtimeo; uint64_t end = timeout < 0 ? 0 : (clock.now_ms () + timeout); // In blocking scenario, commands are processed over and over again until @@ -926,3 +926,13 @@ void xs::socket_base_t::extract_flags (msg_t *msg_) rcvmore = msg_->flags () & msg_t::more ? true : false; } +int xs::socket_base_t::rcvtimeo () +{ + return options.rcvtimeo; +} + +int xs::socket_base_t::sndtimeo () +{ + return options.sndtimeo; +} + |