commit 7964cbff12247736b31ee4824a6c98e030629ce9
Author: Sepherosa Ziehau <sephe@dragonflybsd.org>
Date:   Tue May 3 22:01:18 2016 +0800

    wrk/ae: Avoid extra kqueue syscall

diff --git a/src/ae.c b/src/ae.c
index 90be4e2..7662cc6 100644
--- a/src/ae.c
+++ b/src/ae.c
@@ -122,7 +122,7 @@ int aeCreateFileEvent(aeEventLoop *eventLoop, int fd, int mask,
     return AE_OK;
 }
 
-void aeDeleteFileEvent(aeEventLoop *eventLoop, int fd, int mask)
+static void _aeDeleteFileEvent(aeEventLoop *eventLoop, int fd, int mask)
 {
     if (fd >= eventLoop->setsize) return;
     aeFileEvent *fe = &eventLoop->events[fd];
@@ -137,9 +137,20 @@ void aeDeleteFileEvent(aeEventLoop *eventLoop, int fd, int mask)
             if (eventLoop->events[j].mask != AE_NONE) break;
         eventLoop->maxfd = j;
     }
+}
+
+void aeDeleteFileEvent(aeEventLoop *eventLoop, int fd, int mask)
+{
+    _aeDeleteFileEvent(eventLoop, fd, mask);
     aeApiDelEvent(eventLoop, fd, mask);
 }
 
+void aeCloseFileEvent(aeEventLoop *eventLoop, int fd, int mask)
+{
+    _aeDeleteFileEvent(eventLoop, fd, mask);
+    aeApiCloseEvent(eventLoop, fd, mask);
+}
+
 int aeGetFileEvents(aeEventLoop *eventLoop, int fd) {
     if (fd >= eventLoop->setsize) return 0;
     aeFileEvent *fe = &eventLoop->events[fd];
diff --git a/src/ae.h b/src/ae.h
index 4d89502..6a2f674 100644
--- a/src/ae.h
+++ b/src/ae.h
@@ -104,6 +104,7 @@ void aeStop(aeEventLoop *eventLoop);
 int aeCreateFileEvent(aeEventLoop *eventLoop, int fd, int mask,
         aeFileProc *proc, void *clientData);
 void aeDeleteFileEvent(aeEventLoop *eventLoop, int fd, int mask);
+void aeCloseFileEvent(aeEventLoop *eventLoop, int fd, int mask);
 int aeGetFileEvents(aeEventLoop *eventLoop, int fd);
 long long aeCreateTimeEvent(aeEventLoop *eventLoop, long long milliseconds,
         aeTimeProc *proc, void *clientData,
diff --git a/src/ae_epoll.c b/src/ae_epoll.c
index 4823c28..20f07e9 100644
--- a/src/ae_epoll.c
+++ b/src/ae_epoll.c
@@ -100,6 +100,10 @@ static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int delmask) {
     }
 }
 
+static void aeApiCloseEvent(aeEventLoop *eventLoop, int fd, int delmask) {
+    aeApiDelEvent(eventLoop, fd, delmask);
+}
+
 static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) {
     aeApiState *state = eventLoop->apidata;
     int retval, numevents = 0;
diff --git a/src/ae_evport.c b/src/ae_evport.c
index 0196dcc..a2e1451 100644
--- a/src/ae_evport.c
+++ b/src/ae_evport.c
@@ -235,6 +235,10 @@ static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) {
     }
 }
 
+static void aeApiCloseEvent(aeEventLoop *eventLoop, int fd, int mask) {
+    aeApiDelEvent(eventLoop, fd, mask);
+}
+
 static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) {
     aeApiState *state = eventLoop->apidata;
     struct timespec timeout, *tsp;
diff --git a/src/ae_kqueue.c b/src/ae_kqueue.c
index 458772f..7d5f6e7 100644
--- a/src/ae_kqueue.c
+++ b/src/ae_kqueue.c
@@ -95,6 +95,10 @@ static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) {
     }
 }
 
+static void aeApiCloseEvent(aeEventLoop *eventLoop, int fd, int mask) {
+    /* Do nothing */
+}
+
 static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) {
     aeApiState *state = eventLoop->apidata;
     int retval, numevents = 0;
diff --git a/src/ae_select.c b/src/ae_select.c
index f732e8e..6237f1f 100644
--- a/src/ae_select.c
+++ b/src/ae_select.c
@@ -67,6 +67,10 @@ static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) {
     if (mask & AE_WRITABLE) FD_CLR(fd,&state->wfds);
 }
 
+static void aeApiCloseEvent(aeEventLoop *eventLoop, int fd, int mask) {
+    aeApiDelEvent(eventLoop, fd, mask);
+}
+
 static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) {
     aeApiState *state = eventLoop->apidata;
     int retval, j, numevents = 0;
diff --git a/src/wrk.c b/src/wrk.c
index 00fc61d..96d72b6 100644
--- a/src/wrk.c
+++ b/src/wrk.c
@@ -286,7 +286,7 @@ static int connect_socket(thread *thread, connection *c) {
 }
 
 static int reconnect_socket(thread *thread, connection *c) {
-    aeDeleteFileEvent(thread->loop, c->fd, AE_WRITABLE | AE_READABLE);
+    aeCloseFileEvent(thread->loop, c->fd, AE_WRITABLE | AE_READABLE);
     sock.close(c);
     close(c->fd);
     return connect_socket(thread, c);
