From 5dcbc34396bb4d256916fafcbb2ddd646ad179e6 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Tue, 8 Feb 2011 14:46:27 +0100 Subject: zmq_poll with no fds behaves decently Signed-off-by: Martin Sustrik --- src/zmq.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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; -- cgit v1.2.3