Commit ee1f1af0 authored by Martin Lucina's avatar Martin Lucina Committed by Martin Sustrik

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.
parent a85d1e51
...@@ -382,14 +382,14 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -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 // If the poll item is a 0MQ socket, we poll on the file descriptor
// retrieved by the ZMQ_FD socket option. // 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); size_t zmq_fd_size = sizeof (zmq::fd_t);
if (zmq_getsockopt (items_ [i].socket, ZMQ_FD, &pollfds [i].fd, if (zmq_getsockopt (items_ [i].socket, ZMQ_FD, &pollfds [i].fd,
&zmq_fd_size) == -1) { &zmq_fd_size) == -1) {
free (pollfds); free (pollfds);
return -1; 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 // Else, the poll item is a raw file descriptor. Just convert the
// events to normal POLLIN/POLLOUT for poll (). // events to normal POLLIN/POLLOUT for poll ().
...@@ -474,16 +474,18 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -474,16 +474,18 @@ 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 // 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. // 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); size_t zmq_fd_size = sizeof (zmq::fd_t);
zmq::fd_t notify_fd; zmq::fd_t notify_fd;
if (zmq_getsockopt (items_ [i].socket, ZMQ_FD, &notify_fd, if (zmq_getsockopt (items_ [i].socket, ZMQ_FD, &notify_fd,
&zmq_fd_size) == -1) &zmq_fd_size) == -1)
return -1; return -1;
if (items_ [i].events) {
FD_SET (notify_fd, &pollset_in); FD_SET (notify_fd, &pollset_in);
if (maxfd < notify_fd) if (maxfd < notify_fd)
maxfd = notify_fd; maxfd = notify_fd;
} }
}
// Else, the poll item is a raw file descriptor. Convert the poll item // Else, the poll item is a raw file descriptor. Convert the poll item
// events to the appropriate fd_sets. // events to the appropriate fd_sets.
else { else {
......
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