summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/xs_recv.txt2
-rw-r--r--doc/xs_recvmsg.txt2
-rw-r--r--src/err.cpp2
-rw-r--r--src/surveyor.cpp12
-rw-r--r--tests/survey.cpp2
5 files changed, 16 insertions, 4 deletions
diff --git a/doc/xs_recv.txt b/doc/xs_recv.txt
index 5706432..484c317 100644
--- a/doc/xs_recv.txt
+++ b/doc/xs_recv.txt
@@ -65,6 +65,8 @@ The provided 'socket' was invalid.
*EINTR*::
The operation was interrupted by delivery of a signal before a message was
available.
+*ETIMEDOUT*::
+Survey has timed out. (Applicable only to XS_SURVEYOR socket.)
EXAMPLE
diff --git a/doc/xs_recvmsg.txt b/doc/xs_recvmsg.txt
index 4a88177..86a15a6 100644
--- a/doc/xs_recvmsg.txt
+++ b/doc/xs_recvmsg.txt
@@ -67,6 +67,8 @@ The operation was interrupted by delivery of a signal before a message was
available.
*EFAULT*::
The message passed to the function was invalid.
+*ETIMEDOUT*::
+Survey has timed out. (Applicable only to XS_SURVEYOR socket.)
EXAMPLE
diff --git a/src/err.cpp b/src/err.cpp
index e330ed2..a771030 100644
--- a/src/err.cpp
+++ b/src/err.cpp
@@ -157,7 +157,7 @@ const char *xs::wsa_error_no (int no_)
(no_ == WSAETOOMANYREFS) ?
"Too many references can't splice" :
(no_ == WSAETIMEDOUT) ?
- "Connection timed out" :
+ "Operation timed out" :
(no_ == WSAECONNREFUSED) ?
"Connection refused" :
(no_ == WSAELOOP) ?
diff --git a/src/surveyor.cpp b/src/surveyor.cpp
index b72b91b..bd19b8a 100644
--- a/src/surveyor.cpp
+++ b/src/surveyor.cpp
@@ -92,8 +92,16 @@ int xs::surveyor_t::xrecv (msg_t *msg_, int flags_)
// Get the first part of the response -- the survey ID.
rc = xsurveyor_t::xrecv (msg_, flags_);
- if (rc != 0)
- return rc;
+ if (rc != 0) {
+ if (errno != EAGAIN)
+ return -1;
+
+ // In case of AGAIN we should check whether the survey timeout expired.
+ // If so, we should return ETIMEDOUT so that user is able to
+ // distinguish survey timeout from RCVTIMEO-caused timeout.
+ errno = now_ms () >= timeout ? ETIMEDOUT : EAGAIN;
+ return -1;
+ }
// Check whether this is response for the onging survey. If not, we can
// drop the response.
diff --git a/tests/survey.cpp b/tests/survey.cpp
index f21b217..2179779 100644
--- a/tests/survey.cpp
+++ b/tests/survey.cpp
@@ -126,7 +126,7 @@ int XS_TEST_MAIN ()
assert (rc == 3);
void *watch = xs_stopwatch_start ();
rc = xs_recv (surveyor, buf, sizeof (buf), 0);
- assert (rc == - 1 && errno == EAGAIN);
+ assert (rc == - 1 && errno == ETIMEDOUT);
unsigned long elapsed = xs_stopwatch_stop (watch) / 1000;
time_assert (elapsed, (unsigned long) timeout);