diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2011-10-27 09:41:48 +0200 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2011-10-27 09:41:48 +0200 |
commit | b3cda2ad6091096264f777a95907050edfdd3ffe (patch) | |
tree | 79a4c8325d9188c300c04f5980e0c31e498a128f /src | |
parent | 6c1b50cfab1529e866e40c037ce1be7027423af0 (diff) |
Bug in kqueue poller fixed (issue 261)
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/kqueue.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/kqueue.cpp b/src/kqueue.cpp index bb42d8f..cbf38d1 100644 --- a/src/kqueue.cpp +++ b/src/kqueue.cpp @@ -33,6 +33,7 @@ #include "err.hpp" #include "config.hpp" #include "i_poll_events.hpp" +#include "likely.hpp" // NetBSD defines (struct kevent).udata as intptr_t, everyone else // as void *. @@ -106,29 +107,37 @@ void zmq::kqueue_t::rm_fd (handle_t handle_) void zmq::kqueue_t::set_pollin (handle_t handle_) { poll_entry_t *pe = (poll_entry_t*) handle_; - pe->flag_pollin = true; - kevent_add (pe->fd, EVFILT_READ, pe); + if (likely (!pe->flag_pollin)) { + pe->flag_pollin = true; + kevent_add (pe->fd, EVFILT_READ, pe); + } } void zmq::kqueue_t::reset_pollin (handle_t handle_) { poll_entry_t *pe = (poll_entry_t*) handle_; - pe->flag_pollin = false; - kevent_delete (pe->fd, EVFILT_READ); + if (likely (pe->flag_pollin)) { + pe->flag_pollin = false; + kevent_delete (pe->fd, EVFILT_READ); + } } void zmq::kqueue_t::set_pollout (handle_t handle_) { poll_entry_t *pe = (poll_entry_t*) handle_; - pe->flag_pollout = true; - kevent_add (pe->fd, EVFILT_WRITE, pe); + if (likely (!pe->flag_pollout)) { + pe->flag_pollout = true; + kevent_add (pe->fd, EVFILT_WRITE, pe); + } } void zmq::kqueue_t::reset_pollout (handle_t handle_) { poll_entry_t *pe = (poll_entry_t*) handle_; - pe->flag_pollout = false; - kevent_delete (pe->fd, EVFILT_WRITE); + if (likely (pe->flag_pollout)) { + pe->flag_pollout = false; + kevent_delete (pe->fd, EVFILT_WRITE); + } } void zmq::kqueue_t::start () |