summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Lucina <mato@kotelna.sk>2010-08-07 21:04:30 +0200
committerMartin Sustrik <sustrik@250bpm.com>2010-08-25 15:39:20 +0200
commitee1f1af0091d9bdffa0e5ce1783da925b3cd7e56 (patch)
tree3fd4b1a590ccc2a3b6075f4da7a91d20ae80f4d2 /src
parenta85d1e51bff991a0d2f93ded2724e0ee290edf12 (diff)
zmq_poll(): Fix some corner cases
Trying to optimize out the case where items_[i]. events is 0 would result in a bogus pollfds[i]. Similarly in the select()-based impl, while not strictly necessary it's better to get ZMQ_FD even if events is 0 since that detects ETERM and friends.
Diffstat (limited to 'src')
-rw-r--r--src/zmq.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/zmq.cpp b/src/zmq.cpp
index 6ec8fbe..1a74f86 100644
--- a/src/zmq.cpp
+++ b/src/zmq.cpp
@@ -382,14 +382,14 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
// If the poll item is a 0MQ socket, we poll on the file descriptor
// retrieved by the ZMQ_FD socket option.
- if (items_ [i].socket && items_ [i].events) {
+ if (items_ [i].socket) {
size_t zmq_fd_size = sizeof (zmq::fd_t);
if (zmq_getsockopt (items_ [i].socket, ZMQ_FD, &pollfds [i].fd,
&zmq_fd_size) == -1) {
free (pollfds);
return -1;
}
- pollfds [i].events = POLLIN;
+ pollfds [i].events = items_ [i].events ? POLLIN : 0;
}
// Else, the poll item is a raw file descriptor. Just convert the
// events to normal POLLIN/POLLOUT for poll ().
@@ -474,15 +474,17 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
// If the poll item is a 0MQ socket we are interested in input on the
// notification file descriptor retrieved by the ZMQ_FD socket option.
- if (items_ [i].socket && items_ [i].events) {
+ if (items_ [i].socket) {
size_t zmq_fd_size = sizeof (zmq::fd_t);
zmq::fd_t notify_fd;
if (zmq_getsockopt (items_ [i].socket, ZMQ_FD, &notify_fd,
&zmq_fd_size) == -1)
return -1;
- FD_SET (notify_fd, &pollset_in);
- if (maxfd < notify_fd)
- maxfd = notify_fd;
+ if (items_ [i].events) {
+ FD_SET (notify_fd, &pollset_in);
+ if (maxfd < notify_fd)
+ maxfd = notify_fd;
+ }
}
// Else, the poll item is a raw file descriptor. Convert the poll item
// events to the appropriate fd_sets.