summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2011-02-08 14:46:27 +0100
committerMartin Sustrik <sustrik@250bpm.com>2011-02-08 14:46:27 +0100
commit5dcbc34396bb4d256916fafcbb2ddd646ad179e6 (patch)
treee01bc0267496ba2c555378282bbc196e6ac93301 /src
parent908b39bf8309044913a34c632cd432958dcf6960 (diff)
zmq_poll with no fds behaves decently
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src')
-rw-r--r--src/zmq.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/zmq.cpp b/src/zmq.cpp
index 2d2cf1b..e0bcc6f 100644
--- a/src/zmq.cpp
+++ b/src/zmq.cpp
@@ -44,6 +44,7 @@
#include "msg_content.hpp"
#include "stdint.hpp"
#include "config.hpp"
+#include "likely.hpp"
#include "clock.hpp"
#include "ctx.hpp"
#include "err.hpp"
@@ -352,6 +353,20 @@ int zmq_recv (void *s_, zmq_msg_t *msg_, int flags_)
int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
{
#if defined ZMQ_POLL_BASED_ON_POLL
+ if (unlikely (nitems_ < 0)) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (unlikely (nitems_ == 0)) {
+ if (timeout_ == 0)
+ return 0;
+#if defined ZMQ_HAVE_WINDOWS
+ Sleep (timeout_ > 0 ? timeout_ / 1000 : INFINITE);
+ return 0;
+#else
+ return usleep (timeout_);
+#endif
+ }
if (!items_) {
errno = EFAULT;
@@ -491,6 +506,21 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
#elif defined ZMQ_POLL_BASED_ON_SELECT
+ if (unlikely (nitems_ < 0)) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (unlikely (nitems_ == 0)) {
+ if (timeout_ == 0)
+ return 0;
+#if defined ZMQ_HAVE_WINDOWS
+ Sleep (timeout_ > 0 ? timeout_ / 1000 : INFINITE);
+ return 0;
+#else
+ return usleep (timeout_);
+#endif
+ }
+
if (!items_) {
errno = EFAULT;
return -1;