summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2019-02-04 01:02:40 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2019-02-04 03:01:33 -0500
commit653b0dac7c2434d958c0b11bc5ea8876dff4cde8 (patch)
treee4217afb3891ca6b8a55ce24f796492a2931eada
parentaa34dfd32ba380eab11596156c762d1f882de1c2 (diff)
downloadlighttpd1.4-653b0dac7c2434d958c0b11bc5ea8876dff4cde8.tar.gz
lighttpd1.4-653b0dac7c2434d958c0b11bc5ea8876dff4cde8.zip
[core] fdevent_process()
process fdevents in fdevent.c
-rw-r--r--src/fdevent.c29
-rw-r--r--src/fdevent.h5
-rw-r--r--src/server.c21
3 files changed, 15 insertions, 40 deletions
diff --git a/src/fdevent.c b/src/fdevent.c
index e1c2459d..3a617161 100644
--- a/src/fdevent.c
+++ b/src/fdevent.c
@@ -424,18 +424,6 @@ int fdevent_poll(fdevents *ev, int timeout_ms) {
return ev->poll(ev, timeout_ms);
}
-int fdevent_event_get_revent(fdevents *ev, size_t ndx) {
- if (ev->event_get_revent == NULL) SEGFAULT();
-
- return ev->event_get_revent(ev, ndx);
-}
-
-int fdevent_event_get_fd(fdevents *ev, size_t ndx) {
- if (ev->event_get_fd == NULL) SEGFAULT();
-
- return ev->event_get_fd(ev, ndx);
-}
-
fdevent_handler fdevent_get_handler(fdevents *ev, int fd) {
if (ev->fdarray[fd] == NULL) SEGFAULT();
if ((uintptr_t)ev->fdarray[fd] & 0x3) return NULL;
@@ -610,10 +598,19 @@ int fdevent_accept_listenfd(int listenfd, struct sockaddr *addr, size_t *addrlen
}
-int fdevent_event_next_fdndx(fdevents *ev, int ndx) {
- if (ev->event_next_fdndx) return ev->event_next_fdndx(ev, ndx);
-
- return -1;
+void fdevent_process(server *srv, fdevents *ev, int n) {
+ /* n is the number of events */
+ int ndx = -1;
+ do {
+ ndx = ev->event_next_fdndx(ev, ndx);
+ /* not all fdevent handlers know how many fds got an event */
+ if (-1 == ndx) return;
+ else {
+ fdnode *fdn = ev->fdarray[ev->event_get_fd(ev, ndx)];
+ if (0 == ((uintptr_t)fdn & 0x3))
+ (*fdn->handler)(srv, fdn->ctx, ev->event_get_revent(ev, ndx));
+ }
+ } while (--n > 0);
}
diff --git a/src/fdevent.h b/src/fdevent.h
index a46deee5..f5e3e9a6 100644
--- a/src/fdevent.h
+++ b/src/fdevent.h
@@ -51,14 +51,11 @@ void fdevent_event_set(fdevents *ev, int *fde_ndx, int fd, int events); /* event
void fdevent_event_add(fdevents *ev, int *fde_ndx, int fd, int event); /* events can be FDEVENT_IN or FDEVENT_OUT */
void fdevent_event_clr(fdevents *ev, int *fde_ndx, int fd, int event); /* events can be FDEVENT_IN or FDEVENT_OUT */
void fdevent_event_del(fdevents *ev, int *fde_ndx, int fd);
-int fdevent_event_get_revent(fdevents *ev, size_t ndx);
-int fdevent_event_get_fd(fdevents *ev, size_t ndx);
fdevent_handler fdevent_get_handler(fdevents *ev, int fd);
void * fdevent_get_context(fdevents *ev, int fd);
-int fdevent_event_next_fdndx(fdevents *ev, int ndx);
-
int fdevent_poll(fdevents *ev, int timeout_ms);
+void fdevent_process(server *srv, fdevents *ev, int n);
int fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx);
int fdevent_unregister(fdevents *ev, int fd);
diff --git a/src/server.c b/src/server.c
index a2f376d0..88a2b81a 100644
--- a/src/server.c
+++ b/src/server.c
@@ -2023,27 +2023,8 @@ static int server_main_loop (server * const srv) {
}
if ((n = fdevent_poll(srv->ev, 1000)) > 0) {
- /* n is the number of events */
- int fd;
- int revents;
- int fd_ndx;
+ fdevent_process(srv, srv->ev, n);
last_active_ts = srv->cur_ts;
- fd_ndx = -1;
- do {
- fdevent_handler handler;
- void *context;
-
- fd_ndx = fdevent_event_next_fdndx (srv->ev, fd_ndx);
- if (-1 == fd_ndx) break; /* not all fdevent handlers know how many fds got an event */
-
- revents = fdevent_event_get_revent (srv->ev, fd_ndx);
- fd = fdevent_event_get_fd (srv->ev, fd_ndx);
- handler = fdevent_get_handler(srv->ev, fd);
- context = fdevent_get_context(srv->ev, fd);
- if (NULL != handler) {
- (*handler)(srv, context, revents);
- }
- } while (--n > 0);
} else if (n < 0 && errno != EINTR) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"fdevent_poll failed:",