summaryrefslogtreecommitdiff
path: root/src/fdevent_freebsd_kqueue.c
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2010-08-17 09:54:42 +0000
committerStefan Bühler <stbuehler@web.de>2010-08-17 09:54:42 +0000
commit7e5b0fe9aba2f86fa704d1d14bf3900fbad65f69 (patch)
tree3c8d03629cee1405448070208c484ba58bbdf6ab /src/fdevent_freebsd_kqueue.c
parent00fef415a53555bc88ed39c7138a7da97a8297e2 (diff)
downloadlighttpd1.4-7e5b0fe9aba2f86fa704d1d14bf3900fbad65f69.tar.gz
lighttpd1.4-7e5b0fe9aba2f86fa704d1d14bf3900fbad65f69.zip
Rename fdevent_event_add to _set to reflect what the function does. Fix some handlers.
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2765 152afb58-edef-0310-8abb-c4023f1b3aa9
Diffstat (limited to 'src/fdevent_freebsd_kqueue.c')
-rw-r--r--src/fdevent_freebsd_kqueue.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/src/fdevent_freebsd_kqueue.c b/src/fdevent_freebsd_kqueue.c
index f3a2724a..0f53a2a2 100644
--- a/src/fdevent_freebsd_kqueue.c
+++ b/src/fdevent_freebsd_kqueue.c
@@ -22,58 +22,84 @@ static void fdevent_freebsd_kqueue_free(fdevents *ev) {
}
static int fdevent_freebsd_kqueue_event_del(fdevents *ev, int fde_ndx, int fd) {
- int ret;
+ int ret, n = 0;
struct kevent kev[2];
struct timespec ts;
+ int oevents;
if (fde_ndx < 0) return -1;
- EV_SET(&kev[0], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
- EV_SET(&kev[1], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
+ oevents = ev->fdarray[fd]->events;
+
+ if (oevents & FDEVENT_IN) {
+ EV_SET(&kev[n], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
+ n++;
+ }
+ if (oevents & FDEVENT_OUT) {
+ EV_SET(&kev[n], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
+ n++;
+ }
+
+ if (0 == n) return -1;
ts.tv_sec = 0;
ts.tv_nsec = 0;
ret = kevent(ev->kq_fd,
- &kev, 2,
+ &kev, n,
NULL, 0,
&ts);
- /* Ignore errors for now, as we remove for READ and WRITE without knowing what was registered */
-#if 0
if (ret == -1) {
log_error_write(ev->srv, __FILE__, __LINE__, "SS",
"kqueue event delete failed: ", strerror(errno));
return -1;
}
-#endif
return -1;
}
-static int fdevent_freebsd_kqueue_event_add(fdevents *ev, int fde_ndx, int fd, int events) {
- int filter, ret;
- struct kevent kev;
+static int fdevent_freebsd_kqueue_event_set(fdevents *ev, int fde_ndx, int fd, int events) {
+ int ret, n = 0;
+ struct kevent kev[2];
struct timespec ts;
+ int oevents = ev->fdarray[fd]->events;
+ int addevents = events & ~oevents;
+ int delevents = ~events & oevents;
UNUSED(fde_ndx);
- filter = (events & FDEVENT_IN) ? EVFILT_READ : EVFILT_WRITE;
+ if (events == oevents) return fd;
+
+ if (addevents & FDEVENT_IN) {
+ EV_SET(&kev[n], fd, EVFILT_READ, EV_ADD|EV_CLEAR, 0, 0, NULL);
+ n++;
+ } else if (delevents & FDEVENT_IN) {
+ EV_SET(&kev[n], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
+ n++;
+ }
+ if (addevents & FDEVENT_OUT) {
+ EV_SET(&kev[n], fd, EVFILT_WRITE, EV_ADD|EV_CLEAR, 0, 0, NULL);
+ n++;
+ } else if (delevents & FDEVENT_OUT) {
+ EV_SET(&kev[n], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
+ n++;
+ }
- EV_SET(&kev, fd, filter, EV_ADD|EV_CLEAR, 0, 0, NULL);
+ if (0 == n) return fd;
ts.tv_sec = 0;
ts.tv_nsec = 0;
ret = kevent(ev->kq_fd,
- &kev, 1,
+ kev, n,
NULL, 0,
&ts);
if (ret == -1) {
log_error_write(ev->srv, __FILE__, __LINE__, "SS",
- "kqueue event add failed: ", strerror(errno));
+ "kqueue event set failed: ", strerror(errno));
return -1;
}
@@ -164,7 +190,7 @@ int fdevent_freebsd_kqueue_init(fdevents *ev) {
SET(reset);
SET(event_del);
- SET(event_add);
+ SET(event_set);
SET(event_next_fdndx);
SET(event_get_fd);