Browse Source

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
svn/tags/lighttpd-1.4.28
Stefan Bühler 12 years ago
parent
commit
7e5b0fe9ab
  1. 2
      NEWS
  2. 4
      src/connections.c
  3. 15
      src/fdevent.c
  4. 6
      src/fdevent.h
  5. 56
      src/fdevent_freebsd_kqueue.c
  6. 8
      src/fdevent_libev.c
  7. 4
      src/fdevent_linux_sysepoll.c
  8. 6
      src/fdevent_poll.c
  9. 10
      src/fdevent_select.c
  10. 6
      src/fdevent_solaris_devpoll.c
  11. 2
      src/mod_cgi.c
  12. 10
      src/mod_fastcgi.c
  13. 6
      src/mod_proxy.c
  14. 10
      src/mod_scgi.c
  15. 2
      src/network.c
  16. 4
      src/server.c

2
NEWS

@ -4,7 +4,7 @@ NEWS
====
- 1.4.28 -
* Silence freebsd_kqueue delete errors
* Rename fdevent_event_add to _set to reflect what the function does. Fix some handlers.
- 1.4.27 - 2010-08-13
* Fix handling return value of SSL_CTX_set_options (fixes #2157, thx mlcreech)

4
src/connections.c

@ -1792,7 +1792,7 @@ int connection_state_machine(server *srv, connection *con) {
case CON_STATE_READ_POST:
case CON_STATE_READ:
case CON_STATE_CLOSE:
fdevent_event_add(srv->ev, &(con->fde_ndx), con->fd, FDEVENT_IN);
fdevent_event_set(srv->ev, &(con->fde_ndx), con->fd, FDEVENT_IN);
break;
case CON_STATE_WRITE:
/* request write-fdevent only if we really need it
@ -1802,7 +1802,7 @@ int connection_state_machine(server *srv, connection *con) {
if (!chunkqueue_is_empty(con->write_queue) &&
(con->is_writable == 0) &&
(con->traffic_limit_reached == 0)) {
fdevent_event_add(srv->ev, &(con->fde_ndx), con->fd, FDEVENT_OUT);
fdevent_event_set(srv->ev, &(con->fde_ndx), con->fd, FDEVENT_OUT);
} else {
fdevent_event_del(srv->ev, &(con->fde_ndx), con->fd);
}

15
src/fdevent.c

@ -9,6 +9,7 @@
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <assert.h>
fdevents *fdevent_init(server *srv, size_t maxfds, fdevent_handler_t type) {
@ -112,6 +113,7 @@ int fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx) {
fdn->fd = fd;
fdn->ctx = ctx;
fdn->handler_ctx = NULL;
fdn->events = 0;
ev->fdarray[fd] = fdn;
@ -120,9 +122,12 @@ int fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx) {
int fdevent_unregister(fdevents *ev, int fd) {
fdnode *fdn;
if (!ev) return 0;
if (!ev) return 0;
fdn = ev->fdarray[fd];
assert(fdn->events == 0);
fdnode_free(fdn);
ev->fdarray[fd] = NULL;
@ -133,17 +138,21 @@ int fdevent_unregister(fdevents *ev, int fd) {
int fdevent_event_del(fdevents *ev, int *fde_ndx, int fd) {
int fde = fde_ndx ? *fde_ndx : -1;
if (NULL == ev->fdarray[fd]) return 0;
if (ev->event_del) fde = ev->event_del(ev, fde, fd);
ev->fdarray[fd]->events = 0;
if (fde_ndx) *fde_ndx = fde;
return 0;
}
int fdevent_event_add(fdevents *ev, int *fde_ndx, int fd, int events) {
int fdevent_event_set(fdevents *ev, int *fde_ndx, int fd, int events) {
int fde = fde_ndx ? *fde_ndx : -1;
if (ev->event_add) fde = ev->event_add(ev, fde, fd, events);
if (ev->event_set) fde = ev->event_set(ev, fde, fd, events);
ev->fdarray[fd]->events = events;
if (fde_ndx) *fde_ndx = fde;

6
src/fdevent.h

@ -91,7 +91,6 @@ typedef enum { FDEVENT_HANDLER_UNSET,
FDEVENT_HANDLER_LINUX_SYSEPOLL,
FDEVENT_HANDLER_SOLARIS_DEVPOLL,
FDEVENT_HANDLER_FREEBSD_KQUEUE,
FDEVENT_HANDLER_SOLARIS_PORT,
FDEVENT_HANDLER_LIBEV
} fdevent_handler_t;
@ -101,6 +100,7 @@ typedef struct _fdnode {
void *ctx;
void *handler_ctx;
int fd;
int events;
} fdnode;
/**
@ -166,7 +166,7 @@ typedef struct fdevents {
int (*reset)(struct fdevents *ev);
void (*free)(struct fdevents *ev);
int (*event_add)(struct fdevents *ev, int fde_ndx, int fd, int events);
int (*event_set)(struct fdevents *ev, int fde_ndx, int fd, int events);
int (*event_del)(struct fdevents *ev, int fde_ndx, int fd);
int (*event_get_revent)(struct fdevents *ev, size_t ndx);
int (*event_get_fd)(struct fdevents *ev, size_t ndx);
@ -182,7 +182,7 @@ fdevents *fdevent_init(struct server *srv, size_t maxfds, fdevent_handler_t type
int fdevent_reset(fdevents *ev); /* "init" after fork() */
void fdevent_free(fdevents *ev);
int fdevent_event_add(fdevents *ev, int *fde_ndx, int fd, int events);
int fdevent_event_set(fdevents *ev, int *fde_ndx, int fd, int events); /* events can be FDEVENT_IN, FDEVENT_OUT or FDEVENT_IN | FDEVENT_OUT */
int 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);

56
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);

8
src/fdevent_libev.c

@ -53,7 +53,7 @@ static int fdevent_libev_event_del(fdevents *ev, int fde_ndx, int fd) {
return -1;
}
static int fdevent_libev_event_add(fdevents *ev, int fde_ndx, int fd, int events) {
static int fdevent_libev_event_set(fdevents *ev, int fde_ndx, int fd, int events) {
fdnode *fdn = ev->fdarray[fd];
ev_io *watcher = fdn->handler_ctx;
int ev_events = 0;
@ -70,9 +70,9 @@ static int fdevent_libev_event_add(fdevents *ev, int fde_ndx, int fd, int events
watcher->data = ev;
ev_io_start(ev->libev_loop, watcher);
} else {
if ((watcher->events & ev_events) != ev_events) {
if ((watcher->events & (EV_READ | EV_WRITE)) != ev_events) {
ev_io_stop(ev->libev_loop, watcher);
ev_io_set(watcher, watcher->fd, watcher->events | ev_events);
ev_io_set(watcher, watcher->fd, ev_events);
ev_io_start(ev->libev_loop, watcher);
}
}
@ -140,7 +140,7 @@ int fdevent_libev_init(fdevents *ev) {
SET(reset);
SET(event_del);
SET(event_add);
SET(event_set);
SET(event_next_fdndx);
SET(event_get_fd);

4
src/fdevent_linux_sysepoll.c

@ -41,7 +41,7 @@ static int fdevent_linux_sysepoll_event_del(fdevents *ev, int fde_ndx, int fd) {
return -1;
}
static int fdevent_linux_sysepoll_event_add(fdevents *ev, int fde_ndx, int fd, int events) {
static int fdevent_linux_sysepoll_event_set(fdevents *ev, int fde_ndx, int fd, int events) {
struct epoll_event ep;
int add = 0;
@ -124,7 +124,7 @@ int fdevent_linux_sysepoll_init(fdevents *ev) {
SET(poll);
SET(event_del);
SET(event_add);
SET(event_set);
SET(event_next_fdndx);
SET(event_get_fd);

6
src/fdevent_poll.c

@ -66,7 +66,7 @@ static int fdevent_poll_event_compress(fdevents *ev) {
}
#endif
static int fdevent_poll_event_add(fdevents *ev, int fde_ndx, int fd, int events) {
static int fdevent_poll_event_set(fdevents *ev, int fde_ndx, int fd, int events) {
int pevents = 0;
if (events & FDEVENT_IN) pevents |= POLLIN;
if (events & FDEVENT_OUT) pevents |= POLLOUT;
@ -80,7 +80,7 @@ static int fdevent_poll_event_add(fdevents *ev, int fde_ndx, int fd, int events)
return fde_ndx;
}
log_error_write(ev->srv, __FILE__, __LINE__, "SdD",
"add: ", fde_ndx, ev->pollfds[fde_ndx].fd);
"set: ", fde_ndx, ev->pollfds[fde_ndx].fd);
SEGFAULT();
}
@ -170,7 +170,7 @@ int fdevent_poll_init(fdevents *ev) {
SET(poll);
SET(event_del);
SET(event_add);
SET(event_set);
SET(event_next_fdndx);
SET(event_get_fd);

10
src/fdevent_select.c

@ -34,7 +34,7 @@ static int fdevent_select_event_del(fdevents *ev, int fde_ndx, int fd) {
return -1;
}
static int fdevent_select_event_add(fdevents *ev, int fde_ndx, int fd, int events) {
static int fdevent_select_event_set(fdevents *ev, int fde_ndx, int fd, int events) {
UNUSED(fde_ndx);
/* we should be protected by max-fds, but you never know */
@ -42,11 +42,13 @@ static int fdevent_select_event_add(fdevents *ev, int fde_ndx, int fd, int event
if (events & FDEVENT_IN) {
FD_SET(fd, &(ev->select_set_read));
FD_CLR(fd, &(ev->select_set_write));
} else {
FD_CLR(fd, &(ev->select_set_read));
}
if (events & FDEVENT_OUT) {
FD_CLR(fd, &(ev->select_set_read));
FD_SET(fd, &(ev->select_set_write));
} else {
FD_CLR(fd, &(ev->select_set_write));
}
FD_SET(fd, &(ev->select_set_error));
@ -113,7 +115,7 @@ int fdevent_select_init(fdevents *ev) {
SET(poll);
SET(event_del);
SET(event_add);
SET(event_set);
SET(event_next_fdndx);
SET(event_get_fd);

6
src/fdevent_solaris_devpoll.c

@ -40,7 +40,7 @@ static int fdevent_solaris_devpoll_event_del(fdevents *ev, int fde_ndx, int fd)
return -1;
}
static int fdevent_solaris_devpoll_event_add(fdevents *ev, int fde_ndx, int fd, int events) {
static int fdevent_solaris_devpoll_event_set(fdevents *ev, int fde_ndx, int fd, int events) {
struct pollfd pfd;
int add = 0;
@ -56,7 +56,7 @@ static int fdevent_solaris_devpoll_event_add(fdevents *ev, int fde_ndx, int fd,
if (-1 == write(ev->devpoll_fd, &pfd, sizeof(pfd))) {
log_error_write(ev->srv, __FILE__, __LINE__, "S(D, S)",
"(add) write failed: ", fd, strerror(errno));
"(set) write failed: ", fd, strerror(errno));
return -1;
}
@ -139,7 +139,7 @@ int fdevent_solaris_devpoll_init(fdevents *ev) {
SET(reset);
SET(event_del);
SET(event_add);
SET(event_set);
SET(event_next_fdndx);
SET(event_get_fd);

2
src/mod_cgi.c

@ -1157,7 +1157,7 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, buffer *
con->plugin_ctx[p->id] = hctx;
fdevent_register(srv->ev, hctx->fd, cgi_handle_fdevent, hctx);
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
if (-1 == fdevent_fcntl_set(srv->ev, hctx->fd)) {
log_error_write(srv, __FILE__, __LINE__, "ss", "fcntl failed: ", strerror(errno));

10
src/mod_fastcgi.c

@ -2989,7 +2989,7 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
case CONNECTION_DELAYED:
/* connection is in progress, wait for an event and call getsockopt() below */
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
fcgi_set_state(srv, hctx, FCGI_STATE_CONNECT_DELAYED);
return HANDLER_WAIT_FOR_EVENT;
@ -3108,10 +3108,10 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
if (hctx->wb->bytes_out == hctx->wb->bytes_in) {
/* we don't need the out event anymore */
fdevent_event_del(srv->ev, &(hctx->fde_ndx), hctx->fd);
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
fcgi_set_state(srv, hctx, FCGI_STATE_READ);
} else {
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
return HANDLER_WAIT_FOR_EVENT;
}
@ -3726,12 +3726,12 @@ JOBLIST_FUNC(mod_fastcgi_handle_joblist) {
if (hctx->fd != -1) {
switch (hctx->state) {
case FCGI_STATE_READ:
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
break;
case FCGI_STATE_CONNECT_DELAYED:
case FCGI_STATE_WRITE:
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
break;
case FCGI_STATE_INIT:

6
src/mod_proxy.c

@ -798,7 +798,7 @@ static handler_t proxy_write_request(server *srv, handler_ctx *hctx) {
/* connection is in progress, wait for an event and call getsockopt() below */
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
return HANDLER_WAIT_FOR_EVENT;
case -1:
@ -863,9 +863,9 @@ static handler_t proxy_write_request(server *srv, handler_ctx *hctx) {
proxy_set_state(srv, hctx, PROXY_STATE_READ);
fdevent_event_del(srv->ev, &(hctx->fde_ndx), hctx->fd);
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
} else {
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
return HANDLER_WAIT_FOR_EVENT;
}

10
src/mod_scgi.c

@ -2230,7 +2230,7 @@ static handler_t scgi_write_request(server *srv, handler_ctx *hctx) {
/* connection is in progress, wait for an event and call getsockopt() below */
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
return HANDLER_WAIT_FOR_EVENT;
case -1:
@ -2343,10 +2343,10 @@ static handler_t scgi_write_request(server *srv, handler_ctx *hctx) {
if (hctx->wb->bytes_out == hctx->wb->bytes_in) {
/* we don't need the out event anymore */
fdevent_event_del(srv->ev, &(hctx->fde_ndx), hctx->fd);
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
scgi_set_state(srv, hctx, FCGI_STATE_READ);
} else {
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
return HANDLER_WAIT_FOR_EVENT;
}
@ -2891,12 +2891,12 @@ JOBLIST_FUNC(mod_scgi_handle_joblist) {
if (hctx->fd != -1) {
switch (hctx->state) {
case FCGI_STATE_READ:
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
break;
case FCGI_STATE_CONNECT:
case FCGI_STATE_WRITE:
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
break;
case FCGI_STATE_INIT:

2
src/network.c

@ -724,7 +724,7 @@ int network_register_fdevents(server *srv) {
server_socket *srv_socket = srv->srv_sockets.ptr[i];
fdevent_register(srv->ev, srv_socket->fd, network_server_handle_fdevent, srv_socket);
fdevent_event_add(srv->ev, &(srv_socket->fde_ndx), srv_socket->fd, FDEVENT_IN);
fdevent_event_set(srv->ev, &(srv_socket->fde_ndx), srv_socket->fd, FDEVENT_IN);
}
return 0;
}

4
src/server.c

@ -1147,7 +1147,7 @@ int main (int argc, char **argv) {
srv->stat_cache->fam_fcce_ndx = -1;
fdevent_register(srv->ev, FAMCONNECTION_GETFD(srv->stat_cache->fam), stat_cache_handle_fdevent, NULL);
fdevent_event_add(srv->ev, &(srv->stat_cache->fam_fcce_ndx), FAMCONNECTION_GETFD(srv->stat_cache->fam), FDEVENT_IN);
fdevent_event_set(srv->ev, &(srv->stat_cache->fam_fcce_ndx), FAMCONNECTION_GETFD(srv->stat_cache->fam), FDEVENT_IN);
}
#endif
@ -1346,7 +1346,7 @@ int main (int argc, char **argv) {
(0 == graceful_shutdown)) {
for (i = 0; i < srv->srv_sockets.used; i++) {
server_socket *srv_socket = srv->srv_sockets.ptr[i];
fdevent_event_add(srv->ev, &(srv_socket->fde_ndx), srv_socket->fd, FDEVENT_IN);
fdevent_event_set(srv->ev, &(srv_socket->fde_ndx), srv_socket->fd, FDEVENT_IN);
}
log_error_write(srv, __FILE__, __LINE__, "s", "[note] sockets enabled again");

Loading…
Cancel
Save