From 4f19c998180d9779f6fda80c18dc1bd940032c4f Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Tue, 21 Jun 2016 14:25:19 +0100 Subject: [PATCH] Update Dasynq --- src/dasynq/dasynq-epoll.h | 6 +++--- src/dasynq/dasynq-kqueue.h | 4 ++-- src/dasynq/dasynq.h | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/dasynq/dasynq-epoll.h b/src/dasynq/dasynq-epoll.h index 7a93e21..dd1f404 100644 --- a/src/dasynq/dasynq-epoll.h +++ b/src/dasynq/dasynq-epoll.h @@ -146,7 +146,7 @@ template class EpollLoop : public Base } // flags: IN_EVENTS | OUT_EVENTS - void addFdWatch(int fd, void *userdata, int flags) + void addFdWatch(int fd, void *userdata, int flags, bool enabled = true) { struct epoll_event epevent; // epevent.data.fd = fd; @@ -156,10 +156,10 @@ template class EpollLoop : public Base if (flags & ONE_SHOT) { epevent.events = EPOLLONESHOT; } - if (flags & IN_EVENTS) { + if ((flags & IN_EVENTS) && enabled) { epevent.events |= EPOLLIN; } - if (flags & OUT_EVENTS) { + if ((flags & OUT_EVENTS) && enabled) { epevent.events |= EPOLLOUT; } diff --git a/src/dasynq/dasynq-kqueue.h b/src/dasynq/dasynq-kqueue.h index dd3765a..784068c 100644 --- a/src/dasynq/dasynq-kqueue.h +++ b/src/dasynq/dasynq-kqueue.h @@ -197,7 +197,7 @@ template class KqueueLoop : public Base } // flags: IN_EVENTS | OUT_EVENTS - void addFdWatch(int fd, void *userdata, int flags) + void addFdWatch(int fd, void *userdata, int flags, bool enabled = true) { // TODO kqueue doesn't support EVFILT_WRITE on file fd's :/ // Presumably they cause the kevent call to fail. We could maintain @@ -206,7 +206,7 @@ template class KqueueLoop : public Base short filter = (flags & IN_EVENTS) ? EVFILT_READ : EVFILT_WRITE; struct kevent kev; - EV_SET(&kev, fd, filter, EV_ADD, 0, 0, userdata); + EV_SET(&kev, fd, filter, EV_ADD | (enabled ? 0 : EV_DISABLE), 0, 0, userdata); if (kevent(kqfd, &kev, 1, nullptr, 0, nullptr) == -1) { throw new std::system_error(errno, std::system_category()); } diff --git a/src/dasynq/dasynq.h b/src/dasynq/dasynq.h index 426fd8b..b5a34b1 100644 --- a/src/dasynq/dasynq.h +++ b/src/dasynq/dasynq.h @@ -585,9 +585,9 @@ template class EventLoop releaseLock(qnode); } - void registerFd(BaseFdWatcher *callback, int fd, int eventmask) + void registerFd(BaseFdWatcher *callback, int fd, int eventmask, bool enabled) { - loop_mech.addFdWatch(fd, callback, eventmask | ONE_SHOT); + loop_mech.addFdWatch(fd, callback, eventmask | ONE_SHOT, enabled); } void registerFd(BaseBidiFdWatcher *callback, int fd, int eventmask) @@ -1072,12 +1072,12 @@ class FdWatcher : private dprivate::BaseFdWatcher // causes undefined behavior. // // Can fail with std::bad_alloc or std::system_error. - void addWatch(EventLoop &eloop, int fd, int flags) + void addWatch(EventLoop &eloop, int fd, int flags, bool enabled = true) { BaseWatcher::init(); this->watch_fd = fd; this->watch_flags = flags; - eloop.registerFd(this, fd, flags); + eloop.registerFd(this, fd, flags, enabled); } // Deregister a file descriptor watcher. -- 2.25.1