From c0eb5a1faf2db0d5a7ab83fa903a0c4e164847e1 Mon Sep 17 00:00:00 2001 From: Travis McArthur Date: Fri, 16 Oct 2015 14:05:59 -0700 Subject: [PATCH] Fix removing things from kqueue before adding --- src/s_dispatch.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/s_dispatch.c b/src/s_dispatch.c index 017c26e56..d271c9a73 100644 --- a/src/s_dispatch.c +++ b/src/s_dispatch.c @@ -292,24 +292,30 @@ void fd_refresh(int fd) fde->backend_flags = 0; - EV_SET(&ev, (uintptr_t) fd, (short) EVFILT_READ, fde->read_callback != NULL ? EV_ADD : EV_DELETE, 0, 0, fde); - if (kevent(kqueue_fd, &ev, 1, NULL, 0, &(const struct timespec){ .tv_sec = 0, .tv_nsec = 0}) != 0) + if (fde->read_callback != NULL || fde->backend_flags & EVFILT_READ) { - if (ERRNO == P_EWOULDBLOCK || ERRNO == P_EAGAIN) - return; + EV_SET(&ev, (uintptr_t) fd, (short) EVFILT_READ, fde->read_callback != NULL ? EV_ADD : EV_DELETE, 0, 0, fde); + if (kevent(kqueue_fd, &ev, 1, NULL, 0, &(const struct timespec){ .tv_sec = 0, .tv_nsec = 0}) != 0) + { + if (ERRNO == P_EWOULDBLOCK || ERRNO == P_EAGAIN) + return; - ircd_log(LOG_ERROR, "[BUG?] kevent returned %d", errno); - return; + ircd_log(LOG_ERROR, "[BUG?] kevent returned %d", errno); + return; + } } - EV_SET(&ev, (uintptr_t) fd, (short) EVFILT_WRITE, fde->write_callback != NULL ? EV_ADD : EV_DELETE, 0, 0, fde); - if (kevent(kqueue_fd, &ev, 1, NULL, 0, &(const struct timespec){ .tv_sec = 0, .tv_nsec = 0}) != 0) + if (fde->write_callback != NULL || fde->backend_flags & EVFILT_WRITE) { - if (ERRNO == P_EWOULDBLOCK || ERRNO == P_EAGAIN) - return; + EV_SET(&ev, (uintptr_t) fd, (short) EVFILT_WRITE, fde->write_callback != NULL ? EV_ADD : EV_DELETE, 0, 0, fde); + if (kevent(kqueue_fd, &ev, 1, NULL, 0, &(const struct timespec){ .tv_sec = 0, .tv_nsec = 0}) != 0) + { + if (ERRNO == P_EWOULDBLOCK || ERRNO == P_EAGAIN) + return; - ircd_log(LOG_ERROR, "[BUG?] kevent returned %d", errno); - return; + ircd_log(LOG_ERROR, "[BUG?] kevent returned %d", errno); + return; + } } if (fde->read_callback != NULL) @@ -517,7 +523,7 @@ void fd_select(time_t delay) #ifdef DEBUG_IOENGINE gettimeofday(&t, NULL); tdiff = ((t.tv_sec - oldt.tv_sec) * 1000000) + (t.tv_usec - oldt.tv_usec); - + if (tdiff > 1000000) { sendto_realops_and_log("WARNING: Slow I/O engine or high load: fd_select() took %lld ms! read_callbacks=%d, write_callbacks=%d",