Commit c54589da authored by Constantin Rack's avatar Constantin Rack

Merge pull request #1891 from paddor/master

Fix return value of zmq_poller_wait when used on empty poller
parents 32f2b784 621c965f
...@@ -393,16 +393,22 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *event_, long time ...@@ -393,16 +393,22 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *event_, long time
#if defined ZMQ_POLL_BASED_ON_POLL #if defined ZMQ_POLL_BASED_ON_POLL
if (unlikely (poll_size == 0)) { if (unlikely (poll_size == 0)) {
// We'll report an error (timed out) as if the list was non-empty and
// 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;
if (timeout_ == 0) if (timeout_ == 0)
return 0; return -1;
#if defined ZMQ_HAVE_WINDOWS #if defined ZMQ_HAVE_WINDOWS
Sleep (timeout_ > 0 ? timeout_ : INFINITE); Sleep (timeout_ > 0 ? timeout_ : INFINITE);
return 0; return -1;
#elif defined ZMQ_HAVE_ANDROID #elif defined ZMQ_HAVE_ANDROID
usleep (timeout_ * 1000); usleep (timeout_ * 1000);
return 0; return -1;
#else #else
return usleep (timeout_ * 1000); usleep (timeout_ * 1000);
return -1;
#endif #endif
} }
......
...@@ -1209,6 +1209,8 @@ int zmq_poller_wait (void *poller_, zmq_poller_event_t *event, long timeout_) ...@@ -1209,6 +1209,8 @@ int zmq_poller_wait (void *poller_, zmq_poller_event_t *event, long timeout_)
return -1; return -1;
} }
zmq_assert (event != NULL);
zmq::socket_poller_t::event_t e; zmq::socket_poller_t::event_t e;
memset (&e, 0, sizeof (e)); memset (&e, 0, sizeof (e));
......
...@@ -60,6 +60,14 @@ int main (void) ...@@ -60,6 +60,14 @@ int main (void)
// Set up poller // Set up poller
void* poller = zmq_poller_new (); void* poller = zmq_poller_new ();
zmq_poller_event_t event;
// waiting on poller with no registered sockets should report error
rc = zmq_poller_wait(poller, &event, 0);
assert (rc == -1);
assert (errno == ETIMEDOUT);
// register sink
rc = zmq_poller_add (poller, sink, sink, ZMQ_POLLIN); rc = zmq_poller_add (poller, sink, sink, ZMQ_POLLIN);
assert (rc == 0); assert (rc == 0);
...@@ -69,7 +77,6 @@ int main (void) ...@@ -69,7 +77,6 @@ int main (void)
assert (rc == 1); assert (rc == 1);
// We expect a message only on the sink // We expect a message only on the sink
zmq_poller_event_t event;
rc = zmq_poller_wait (poller, &event, -1); rc = zmq_poller_wait (poller, &event, -1);
assert (rc == 0); assert (rc == 0);
assert (event.socket == sink); assert (event.socket == 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