Skip to content

Commit

Permalink
Problem: zmq_poller_* uses ETIMEDOUT (instead of the usual EAGAIN) to…
Browse files Browse the repository at this point in the history
… indicate timeouts

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

Fixes #2713
  • Loading branch information
sigiesec committed Aug 22, 2017
1 parent 6a3c053 commit a71f7b0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@ int zmq::proxy (
// 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'.
rc = poller_wait->wait (events, 3, -1);
if (rc < 0 && errno == ETIMEDOUT)
if (rc < 0 && errno == EAGAIN)
rc = 0;
CHECK_RC_EXIT_ON_FAILURE ();

// Some of events waited for by 'poller_wait' have arrived, now poll for everything without blocking.
rc = poller_all->wait (events, 3, 0);
if (rc < 0 && errno == ETIMEDOUT)
if (rc < 0 && errno == EAGAIN)
rc = 0;
CHECK_RC_EXIT_ON_FAILURE ();

Expand Down
8 changes: 4 additions & 4 deletions src/socket_poller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
// needs to check the return value AND the event to avoid using the
// nullified event data.
errno = ETIMEDOUT;
errno = EAGAIN;
if (timeout_ == 0)
return -1;
#if defined ZMQ_HAVE_WINDOWS
Expand Down Expand Up @@ -550,7 +550,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev
if (now >= end)
break;
}
errno = ETIMEDOUT;
errno = EAGAIN;
return -1;

#elif defined ZMQ_POLL_BASED_ON_SELECT
Expand All @@ -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
// needs to check the return value AND the event to avoid using the
// nullified event data.
errno = ETIMEDOUT;
errno = EAGAIN;
if (timeout_ == 0)
return -1;
#if defined ZMQ_HAVE_WINDOWS
Expand Down Expand Up @@ -711,7 +711,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, int n_ev
break;
}

errno = ETIMEDOUT;
errno = EAGAIN;
return -1;

#else
Expand Down
2 changes: 1 addition & 1 deletion src/zmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
if (rc < 0) {
delete [] events;
if (zmq_errno() == ETIMEDOUT) {
if (zmq_errno() == EAGAIN) {
return 0;
}
return rc;
Expand Down
10 changes: 4 additions & 6 deletions tests/test_poller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,16 @@ void test_wait_corner_cases (void *ctx)
void *poller = zmq_poller_new ();
assert (poller != NULL);

// TODO zmq_poller_wait should return EAGAIN instead of ETIMEDOUT (like all other zmq functions)

zmq_poller_event_t event;
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
rc = zmq_poller_wait(poller, &event, -1);
assert (rc == -1 && errno == EFAULT);

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
rc = zmq_poller_wait_all (poller, &event, 0, -1);
Expand Down Expand Up @@ -238,7 +236,7 @@ int main (void)
// waiting on poller with no registered sockets should report error
rc = zmq_poller_wait (poller, &event, 0);
assert (rc == -1);
assert (errno == ETIMEDOUT);
assert (errno == EAGAIN);

// register sink
rc = zmq_poller_add (poller, sink, sink, ZMQ_POLLIN);
Expand All @@ -260,7 +258,7 @@ int main (void)
// We expect timed out
rc = zmq_poller_wait (poller, &event, 0);
assert (rc == -1);
assert (errno == ETIMEDOUT);
assert (errno == EAGAIN);

// Stop polling sink
rc = zmq_poller_remove (poller, sink);
Expand Down

0 comments on commit a71f7b0

Please sign in to comment.