}
// 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;
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;
}
}
// 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
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());
}
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)
// 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.