Commit a71f7b04 authored by sigiesec's avatar sigiesec

Problem: zmq_poller_* uses ETIMEDOUT (instead of the usual EAGAIN) to indicate timeouts

Solution: replace ETIMEDOUT within socket_poller_t and all client code by EAGAIN

Fixes #2713
parent 6a3c053a
...@@ -271,13 +271,13 @@ int zmq::proxy ( ...@@ -271,13 +271,13 @@ int zmq::proxy (
// If one of receiving end's queue is full ('ZMQ_POLLOUT' not available), // If one of receiving end's queue is full ('ZMQ_POLLOUT' not available),
// 'poller_wait' is pointed to 'poller_receive_blocked', 'poller_send_blocked' or 'poller_both_blocked'. // 'poller_wait' is pointed to 'poller_receive_blocked', 'poller_send_blocked' or 'poller_both_blocked'.
rc = poller_wait->wait (events, 3, -1); rc = poller_wait->wait (events, 3, -1);
if (rc < 0 && errno == ETIMEDOUT) if (rc < 0 && errno == EAGAIN)
rc = 0; rc = 0;
CHECK_RC_EXIT_ON_FAILURE (); CHECK_RC_EXIT_ON_FAILURE ();
// Some of events waited for by 'poller_wait' have arrived, now poll for everything without blocking. // Some of events waited for by 'poller_wait' have arrived, now poll for everything without blocking.
rc = poller_all->wait (events, 3, 0); rc = poller_all->wait (events, 3, 0);
if (rc < 0 && errno == ETIMEDOUT) if (rc < 0 && errno == EAGAIN)
rc = 0; rc = 0;
CHECK_RC_EXIT_ON_FAILURE (); CHECK_RC_EXIT_ON_FAILURE ();
......
...@@ -415,7 +415,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev ...@@ -415,7 +415,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev
// no event occured within the specified timeout. Otherwise the caller // no event occured within the specified timeout. Otherwise the caller
// needs to check the return value AND the event to avoid using the // needs to check the return value AND the event to avoid using the
// nullified event data. // nullified event data.
errno = ETIMEDOUT; errno = EAGAIN;
if (timeout_ == 0) if (timeout_ == 0)
return -1; return -1;
#if defined ZMQ_HAVE_WINDOWS #if defined ZMQ_HAVE_WINDOWS
...@@ -550,7 +550,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev ...@@ -550,7 +550,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev
if (now >= end) if (now >= end)
break; break;
} }
errno = ETIMEDOUT; errno = EAGAIN;
return -1; return -1;
#elif defined ZMQ_POLL_BASED_ON_SELECT #elif defined ZMQ_POLL_BASED_ON_SELECT
...@@ -560,7 +560,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev ...@@ -560,7 +560,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev
// no event occured within the specified timeout. Otherwise the caller // no event occured within the specified timeout. Otherwise the caller
// needs to check the return value AND the event to avoid using the // needs to check the return value AND the event to avoid using the
// nullified event data. // nullified event data.
errno = ETIMEDOUT; errno = EAGAIN;
if (timeout_ == 0) if (timeout_ == 0)
return -1; return -1;
#if defined ZMQ_HAVE_WINDOWS #if defined ZMQ_HAVE_WINDOWS
...@@ -711,7 +711,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev ...@@ -711,7 +711,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev
break; break;
} }
errno = ETIMEDOUT; errno = EAGAIN;
return -1; return -1;
#else #else
......
...@@ -813,7 +813,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -813,7 +813,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
rc = zmq_poller_wait_all (&poller, events, nitems_, timeout_); rc = zmq_poller_wait_all (&poller, events, nitems_, timeout_);
if (rc < 0) { if (rc < 0) {
delete [] events; delete [] events;
if (zmq_errno() == ETIMEDOUT) { if (zmq_errno() == EAGAIN) {
return 0; return 0;
} }
return rc; return rc;
......
...@@ -170,18 +170,16 @@ void test_wait_corner_cases (void *ctx) ...@@ -170,18 +170,16 @@ void test_wait_corner_cases (void *ctx)
void *poller = zmq_poller_new (); void *poller = zmq_poller_new ();
assert (poller != NULL); assert (poller != NULL);
// TODO zmq_poller_wait should return EAGAIN instead of ETIMEDOUT (like all other zmq functions)
zmq_poller_event_t event; zmq_poller_event_t event;
int rc = zmq_poller_wait(poller, &event, 0); int rc = zmq_poller_wait(poller, &event, 0);
assert (rc == -1 && errno == ETIMEDOUT); assert (rc == -1 && errno == EAGAIN);
// this can never return since no socket was registered, and should yield an error // this can never return since no socket was registered, and should yield an error
rc = zmq_poller_wait(poller, &event, -1); rc = zmq_poller_wait(poller, &event, -1);
assert (rc == -1 && errno == EFAULT); assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_wait_all (poller, &event, 0, 0); rc = zmq_poller_wait_all (poller, &event, 0, 0);
assert (rc == -1 && errno == ETIMEDOUT); assert (rc == -1 && errno == EAGAIN);
// this can never return since no socket was registered, and should yield an error // this can never return since no socket was registered, and should yield an error
rc = zmq_poller_wait_all (poller, &event, 0, -1); rc = zmq_poller_wait_all (poller, &event, 0, -1);
...@@ -238,7 +236,7 @@ int main (void) ...@@ -238,7 +236,7 @@ int main (void)
// waiting on poller with no registered sockets should report error // waiting on poller with no registered sockets should report error
rc = zmq_poller_wait (poller, &event, 0); rc = zmq_poller_wait (poller, &event, 0);
assert (rc == -1); assert (rc == -1);
assert (errno == ETIMEDOUT); assert (errno == EAGAIN);
// register sink // register sink
rc = zmq_poller_add (poller, sink, sink, ZMQ_POLLIN); rc = zmq_poller_add (poller, sink, sink, ZMQ_POLLIN);
...@@ -260,7 +258,7 @@ int main (void) ...@@ -260,7 +258,7 @@ int main (void)
// We expect timed out // We expect timed out
rc = zmq_poller_wait (poller, &event, 0); rc = zmq_poller_wait (poller, &event, 0);
assert (rc == -1); assert (rc == -1);
assert (errno == ETIMEDOUT); assert (errno == EAGAIN);
// Stop polling sink // Stop polling sink
rc = zmq_poller_remove (poller, sink); rc = zmq_poller_remove (poller, sink);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment