summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2017-06-06 18:57:52 +0300
committerIgor Sysoev <igor@sysoev.ru>2017-06-06 18:57:52 +0300
commit49e9049ed2b00f2f3ce5bacd75dbc21932836a25 (patch)
tree188d5e7c8fe31b048953cfb21dea80dfabf6bbdb /src
parent71c906a512ad64450cc33d3c02a719b31888f272 (diff)
downloadunit-49e9049ed2b00f2f3ce5bacd75dbc21932836a25.tar.gz
unit-49e9049ed2b00f2f3ce5bacd75dbc21932836a25.tar.bz2
Optimization of kqueue event processing on connection close.
Diffstat (limited to '')
-rw-r--r--src/nxt_kqueue_engine.c15
1 files changed, 12 insertions, 3 deletions
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;
}