From 49e9049ed2b00f2f3ce5bacd75dbc21932836a25 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Tue, 6 Jun 2017 18:57:52 +0300 Subject: Optimization of kqueue event processing on connection close. --- src/nxt_kqueue_engine.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/nxt_kqueue_engine.c') diff --git a/src/nxt_kqueue_engine.c b/src/nxt_kqueue_engine.c index a216e066..d15ce15a 100644 --- a/src/nxt_kqueue_engine.c +++ b/src/nxt_kqueue_engine.c @@ -293,17 +293,26 @@ nxt_kqueue_delete(nxt_event_engine_t *engine, nxt_fd_event_t *ev) * Calling close() on a file descriptor will remove any kevents that * reference the descriptor. * - * nxt_kqueue_close() always returns true as there are pending events on - * closing file descriptor because kevent() passes whole change list at once. + * So nxt_kqueue_close() returns true only if there are pending events. */ static nxt_bool_t nxt_kqueue_close(nxt_event_engine_t *engine, nxt_fd_event_t *ev) { + struct kevent *kev, *end; + ev->read = NXT_EVENT_INACTIVE; ev->write = NXT_EVENT_INACTIVE; - return 1; + end = &engine->u.kqueue.changes[engine->u.kqueue.nchanges]; + + for (kev = engine->u.kqueue.changes; kev < end; kev++) { + if (kev->ident == (uintptr_t) ev->fd) { + return 1; + } + } + + return 0; } -- cgit