Browse Source

[core] pass (fdnode *) for registered fdevent fd

inline fdevent_fdnode_interest()
avoid array lookup for (fdnode *) for various ops
personal/stbuehler/ci-build
Glenn Strauss 3 years ago
parent
commit
9113011d5b
  1. 2
      src/base.h
  2. 2
      src/base_decls.h
  3. 15
      src/connections.c
  4. 37
      src/fdevent.c
  5. 26
      src/fdevent.h
  6. 11
      src/fdevent_impl.h
  7. 29
      src/gw_backend.c
  8. 1
      src/gw_backend.h
  9. 11
      src/http-header-glue.c
  10. 30
      src/mod_cgi.c
  11. 2
      src/mod_fastcgi.c
  12. 12
      src/network.c
  13. 2
      src/response.h
  14. 7
      src/server.c
  15. 21
      src/stat_cache.c

2
src/base.h

@ -212,6 +212,7 @@ struct connection {
* this is self-protection
*/
fdnode *fdn; /* fdevent (fdnode *) object */
int fd; /* the FD for this connection */
int ndx; /* reverse mapping to server->connection[ndx] */
@ -352,6 +353,7 @@ typedef struct server_socket {
unsigned short is_ssl;
unsigned short sidx;
fdnode *fdn;
buffer *srv_token;
} server_socket;

2
src/base_decls.h

@ -12,6 +12,8 @@ typedef struct connection connection;
union sock_addr;
typedef union sock_addr sock_addr;
struct fdnode_st;
typedef struct fdnode_st fdnode;
enum handler_t {
HANDLER_UNSET,

15
src/connections.c

@ -110,8 +110,9 @@ static int connection_close(server *srv, connection *con) {
con->request_count = 0;
chunkqueue_reset(con->read_queue);
fdevent_event_del(srv->ev, con->fd);
fdevent_fdnode_event_del(srv->ev, con->fdn);
fdevent_unregister(srv->ev, con->fd);
con->fdn = NULL;
#ifdef __WIN32
if (closesocket(con->fd)) {
log_error_write(srv, __FILE__, __LINE__, "sds",
@ -903,7 +904,7 @@ static handler_t connection_handle_fdevent(server *srv, void *context, int reven
} else if (revents & FDEVENT_HUP) {
connection_set_state(srv, con, CON_STATE_ERROR);
} else if (revents & FDEVENT_RDHUP) {
int events = fdevent_event_get_interest(srv->ev, con->fd);
int events = fdevent_fdnode_interest(con->fdn);
events &= ~(FDEVENT_IN|FDEVENT_RDHUP);
con->conf.stream_request_body &= ~(FDEVENT_STREAM_REQUEST_BUFMIN|FDEVENT_STREAM_REQUEST_POLLIN);
con->conf.stream_request_body |= FDEVENT_STREAM_REQUEST_POLLRDHUP;
@ -914,7 +915,7 @@ static handler_t connection_handle_fdevent(server *srv, void *context, int reven
}
if (sock_addr_get_family(&con->dst_addr) == AF_UNIX) {
/* future: will getpeername() on AF_UNIX properly check if still connected? */
fdevent_event_set(srv->ev, con->fd, events);
fdevent_fdnode_event_set(srv->ev, con->fdn, events);
} else if (fdevent_is_tcp_half_closed(con->fd)) {
/* Success of fdevent_is_tcp_half_closed() after FDEVENT_RDHUP indicates TCP FIN received,
* but does not distinguish between client shutdown(fd, SHUT_WR) and client close(fd).
@ -924,7 +925,7 @@ static handler_t connection_handle_fdevent(server *srv, void *context, int reven
* (without FDEVENT_RDHUP interest) when checking for write timeouts
* once a second in server.c, though getpeername() on Windows might not indicate this */
con->conf.stream_request_body |= FDEVENT_STREAM_REQUEST_TCP_FIN;
fdevent_event_set(srv->ev, con->fd, events);
fdevent_fdnode_event_set(srv->ev, con->fdn, events);
} else {
/* Failure of fdevent_is_tcp_half_closed() indicates TCP RST
* (or unable to tell (unsupported OS), though should not
@ -1093,7 +1094,7 @@ connection *connection_accepted(server *srv, server_socket *srv_socket, sock_add
con = connections_get_new_connection(srv);
con->fd = cnt;
fdevent_register(srv->ev, con->fd, connection_handle_fdevent, con);
con->fdn = fdevent_register(srv->ev, con->fd, connection_handle_fdevent, con);
con->network_read = connection_read_cq;
con->network_write = connection_write_cq;
@ -1341,7 +1342,7 @@ int connection_state_machine(server *srv, connection *con) {
break;
}
if (con->fd >= 0) {
const int events = fdevent_event_get_interest(srv->ev, con->fd);
const int events = fdevent_fdnode_interest(con->fdn);
if (con->is_readable < 0) {
con->is_readable = 0;
r |= FDEVENT_IN;
@ -1361,7 +1362,7 @@ int connection_state_machine(server *srv, connection *con) {
if ((r & FDEVENT_OUT) && !(events & FDEVENT_OUT)) {
con->write_request_ts = srv->cur_ts;
}
fdevent_event_set(srv->ev, con->fd, r);
fdevent_fdnode_event_set(srv->ev, con->fdn, r);
}
}

37
src/fdevent.c

@ -278,7 +278,7 @@ static void fdnode_free(fdnode *fdn) {
free(fdn);
}
void fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx) {
fdnode * fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx) {
fdnode *fdn = ev->fdarray[fd] = fdnode_init();
force_assert(NULL != fdn);
fdn->handler = handler;
@ -289,6 +289,7 @@ void fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx)
#ifdef FDEVENT_USE_LIBEV
fdn->handler_ctx = NULL;
#endif
return fdn;
}
void fdevent_unregister(fdevents *ev, int fd) {
@ -344,11 +345,7 @@ static void fdevent_sched_run(fdevents *ev) {
ev->pendclose = NULL;
}
int fdevent_event_get_interest(const fdevents *ev, int fd) {
return fd >= 0 ? ev->fdarray[fd]->events : 0;
}
static void fdevent_fdnode_event_del(fdevents *ev, fdnode *fdn) {
static void fdevent_fdnode_event_unsetter(fdevents *ev, fdnode *fdn) {
if (-1 == fdn->fde_ndx) return;
if (0 == ev->event_del(ev, fdn)) {
fdn->fde_ndx = -1;
@ -360,7 +357,7 @@ static void fdevent_fdnode_event_del(fdevents *ev, fdnode *fdn) {
}
}
static void fdevent_fdnode_event_set(fdevents *ev, fdnode *fdn, int events) {
static void fdevent_fdnode_event_setter(fdevents *ev, fdnode *fdn, int events) {
/*(Note: skips registering with kernel if initial events is 0,
* so caller should pass non-zero events for initial registration.
* If never registered due to never being called with non-zero events,
@ -374,30 +371,20 @@ static void fdevent_fdnode_event_set(fdevents *ev, fdnode *fdn, int events) {
"fdevent event_set failed: ", strerror(errno));
}
void fdevent_event_del(fdevents *ev, int fd) {
if (-1 != fd) {
fdnode *fdn = ev->fdarray[fd];
if ((uintptr_t)fdn & 0x3) return;
fdevent_fdnode_event_del(ev, fdn);
}
void fdevent_fdnode_event_del(fdevents *ev, fdnode *fdn) {
if (NULL != fdn) fdevent_fdnode_event_unsetter(ev, fdn);
}
void fdevent_event_set(fdevents *ev, int fd, int events) {
if (-1 != fd) fdevent_fdnode_event_set(ev, ev->fdarray[fd], events);
void fdevent_fdnode_event_set(fdevents *ev, fdnode *fdn, int events) {
if (NULL != fdn) fdevent_fdnode_event_setter(ev, fdn, events);
}
void fdevent_event_add(fdevents *ev, int fd, int event) {
if (-1 != fd) {
fdnode *fdn = ev->fdarray[fd];
fdevent_fdnode_event_set(ev, fdn, (fdn->events | event));
}
void fdevent_fdnode_event_add(fdevents *ev, fdnode *fdn, int event) {
if (NULL != fdn) fdevent_fdnode_event_setter(ev, fdn, (fdn->events|event));
}
void fdevent_event_clr(fdevents *ev, int fd, int event) {
if (-1 != fd) {
fdnode *fdn = ev->fdarray[fd];
fdevent_fdnode_event_set(ev, fdn, (fdn->events & ~event));
}
void fdevent_fdnode_event_clr(fdevents *ev, fdnode *fdn, int event) {
if (NULL != fdn) fdevent_fdnode_event_setter(ev, fdn, (fdn->events&~event));
}
int fdevent_poll(fdevents *ev, int timeout_ms) {

26
src/fdevent.h

@ -9,8 +9,18 @@ typedef struct fdevents fdevents;
typedef handler_t (*fdevent_handler)(struct server *srv, void *ctx, int revents);
/* these are the POLL* values from <bits/poll.h> (linux poll)
*/
struct fdnode_st {
fdevent_handler handler;
void *ctx;
int fd;
int events;
int fde_ndx;
#ifdef HAVE_LIBEV
void *handler_ctx;
#endif
};
/* These must match POLL* values from operating system headers */
#define FDEVENT_IN 0x0001
#define FDEVENT_PRI 0x0002
@ -50,15 +60,15 @@ int fdevent_reset(fdevents *ev); /* "init" after fork() */
__attribute_cold__
void fdevent_free(fdevents *ev);
int fdevent_event_get_interest(const fdevents *ev, int fd);
void fdevent_event_set(fdevents *ev, int fd, int events);/* events can be FDEVENT_IN, FDEVENT_OUT or FDEVENT_IN | FDEVENT_OUT */
void fdevent_event_add(fdevents *ev, int fd, int event); /* event can be FDEVENT_IN or FDEVENT_OUT */
void fdevent_event_clr(fdevents *ev, int fd, int event); /* event can be FDEVENT_IN or FDEVENT_OUT */
void fdevent_event_del(fdevents *ev, int fd);
#define fdevent_fdnode_interest(fdn) (NULL != (fdn) ? (fdn)->events : 0)
void fdevent_fdnode_event_del(fdevents *ev, fdnode *fdn);
void fdevent_fdnode_event_set(fdevents *ev, fdnode *fdn, int events);
void fdevent_fdnode_event_add(fdevents *ev, fdnode *fdn, int event);
void fdevent_fdnode_event_clr(fdevents *ev, fdnode *fdn, int event);
int fdevent_poll(fdevents *ev, int timeout_ms);
void fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx);
fdnode * fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx);
void fdevent_unregister(fdevents *ev, int fd);
void fdevent_sched_close(fdevents *ev, int fd, int issock);

11
src/fdevent_impl.h

@ -60,17 +60,6 @@ typedef enum {
FDEVENT_HANDLER_LIBEV
} fdevent_handler_t;
typedef struct _fdnode {
fdevent_handler handler;
void *ctx;
int fd;
int events;
int fde_ndx;
#ifdef FDEVENT_USE_LIBEV
void *handler_ctx;
#endif
} fdnode;
/**
* array of unused fd's
*

29
src/gw_backend.c

@ -1643,9 +1643,10 @@ void gw_set_transparent(server *srv, gw_handler_ctx *hctx) {
static void gw_backend_close(server *srv, gw_handler_ctx *hctx) {
if (hctx->fd >= 0) {
fdevent_event_del(srv->ev, hctx->fd);
fdevent_fdnode_event_del(srv->ev, hctx->fdn);
/*fdevent_unregister(srv->ev, hctx->fd);*//*(handled below)*/
fdevent_sched_close(srv->ev, hctx->fd, 1);
hctx->fdn = NULL;
hctx->fd = -1;
}
@ -1712,7 +1713,7 @@ static void gw_conditional_tcp_fin(server *srv, gw_handler_ctx *hctx) {
con->conf.stream_request_body &= ~FDEVENT_STREAM_REQUEST_POLLIN;
con->is_readable = 0;
shutdown(hctx->fd, SHUT_WR);
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_OUT);
fdevent_fdnode_event_clr(srv->ev, hctx->fdn, FDEVENT_OUT);
}
static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
@ -1758,7 +1759,7 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
srv->cur_fds++;
fdevent_register(srv->ev, hctx->fd, gw_handle_fdevent, hctx);
hctx->fdn = fdevent_register(srv->ev,hctx->fd,gw_handle_fdevent,hctx);
if (hctx->proc->is_local) {
hctx->pid = hctx->proc->pid;
@ -1767,7 +1768,7 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
switch (gw_establish_connection(srv, hctx->host, hctx->proc, hctx->pid,
hctx->fd, hctx->conf.debug)) {
case 1: /* connection is in progress */
fdevent_event_set(srv->ev, hctx->fd, FDEVENT_OUT);
fdevent_fdnode_event_set(srv->ev, hctx->fdn, FDEVENT_OUT);
gw_set_state(srv, hctx, GW_STATE_CONNECT_DELAYED);
return HANDLER_WAIT_FOR_EVENT;
case -1:/* connection error */
@ -1799,7 +1800,7 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
handler_t rc = hctx->create_env(srv, hctx);
if (HANDLER_GO_ON != rc) {
if (HANDLER_FINISHED != rc && HANDLER_ERROR != rc)
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_OUT);
fdevent_fdnode_event_clr(srv->ev, hctx->fdn, FDEVENT_OUT);
return rc;
}
}
@ -1814,7 +1815,7 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
}
}
fdevent_event_add(srv->ev, hctx->fd, FDEVENT_IN | FDEVENT_RDHUP);
fdevent_fdnode_event_add(srv->ev, hctx->fdn, FDEVENT_IN|FDEVENT_RDHUP);
gw_set_state(srv, hctx, GW_STATE_WRITE);
/* fall through */
case GW_STATE_WRITE:
@ -1856,7 +1857,7 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
}
if (hctx->wb->bytes_out == hctx->wb_reqlen) {
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_OUT);
fdevent_fdnode_event_clr(srv->ev, hctx->fdn, FDEVENT_OUT);
gw_set_state(srv, hctx, GW_STATE_READ);
} else {
off_t wblen = hctx->wb->bytes_in - hctx->wb->bytes_out;
@ -1872,9 +1873,9 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
}
}
if (0 == wblen) {
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_OUT);
fdevent_fdnode_event_clr(srv->ev, hctx->fdn, FDEVENT_OUT);
} else {
fdevent_event_add(srv->ev, hctx->fd, FDEVENT_OUT);
fdevent_fdnode_event_add(srv->ev, hctx->fdn, FDEVENT_OUT);
}
}
@ -1932,14 +1933,14 @@ handler_t gw_handle_subrequest(server *srv, connection *con, void *p_d) {
if ((con->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_BUFMIN)
&& con->file_started) {
if (chunkqueue_length(con->write_queue) > 65536 - 4096) {
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_IN);
fdevent_fdnode_event_clr(srv->ev, hctx->fdn, FDEVENT_IN);
}
else if (!(fdevent_event_get_interest(srv->ev, hctx->fd) & FDEVENT_IN)){
else if (!(fdevent_fdnode_interest(hctx->fdn) & FDEVENT_IN)) {
/* optimistic read from backend */
handler_t rc;
rc = gw_recv_response(srv, hctx); /*(might invalidate hctx)*/
if (rc != HANDLER_GO_ON) return rc; /*(unless HANDLER_GO_ON)*/
fdevent_event_add(srv->ev, hctx->fd, FDEVENT_IN);
fdevent_fdnode_event_add(srv->ev, hctx->fdn, FDEVENT_IN);
}
}
@ -1982,7 +1983,7 @@ handler_t gw_handle_subrequest(server *srv, connection *con, void *p_d) {
}
else
chunkqueue_append_chunkqueue(hctx->wb, req_cq);
if (fdevent_event_get_interest(srv->ev,hctx->fd) & FDEVENT_OUT){
if (fdevent_fdnode_interest(hctx->fdn) & FDEVENT_OUT) {
return (r == HANDLER_GO_ON) ? HANDLER_WAIT_FOR_EVENT : r;
}
}
@ -2028,7 +2029,7 @@ static handler_t gw_recv_response(server *srv, gw_handler_ctx *hctx) {
: hctx->response;
handler_t rc =
http_response_read(srv, hctx->remote_conn, &hctx->opts, b, hctx->fd);
http_response_read(srv, hctx->remote_conn, &hctx->opts, b, hctx->fdn);
if (b != hctx->response) chunk_buffer_release(b);

1
src/gw_backend.h

@ -311,6 +311,7 @@ typedef struct gw_handler_ctx {
buffer *response;
fdnode *fdn; /* fdevent (fdnode *) object */
int fd; /* fd to the gw process */
pid_t pid;

11
src/http-header-glue.c

@ -1175,7 +1175,8 @@ handler_t http_response_parse_headers(server *srv, connection *con, http_respons
}
handler_t http_response_read(server *srv, connection *con, http_response_opts *opts, buffer *b, int fd) {
handler_t http_response_read(server *srv, connection *con, http_response_opts *opts, buffer *b, fdnode *fdn) {
const int fd = fdn->fd;
while (1) {
ssize_t n;
size_t avail = buffer_string_space(b);
@ -1191,11 +1192,11 @@ handler_t http_response_read(server *srv, connection *con, http_response_opts *o
}
else if (0 == toread) {
#if 0
return (fdevent_event_get_interest(srv->ev, fd) & FDEVENT_IN)
return (fdevent_fdnode_interest(fdn) & FDEVENT_IN)
? HANDLER_FINISHED /* read finished */
: HANDLER_GO_ON; /* optimistic read; data not ready */
#else
if (!(fdevent_event_get_interest(srv->ev, fd) & FDEVENT_IN)) {
if (!(fdevent_fdnode_interest(fdn) & FDEVENT_IN)) {
if (!(con->conf.stream_response_body
& FDEVENT_STREAM_RESPONSE_POLLRDHUP))
return HANDLER_GO_ON;/*optimistic read; data not ready*/
@ -1218,7 +1219,7 @@ handler_t http_response_read(server *srv, connection *con, http_response_opts *o
* immediately, unless !con->is_writable, where
* connection_state_machine() might not loop back to call
* mod_proxy_handle_subrequest())*/
fdevent_event_clr(srv->ev, fd, FDEVENT_IN);
fdevent_fdnode_event_clr(srv->ev, fdn, FDEVENT_IN);
}
if (cqlen >= 65536-1) return HANDLER_GO_ON;
toread = 65536 - 1 - (unsigned int)cqlen;
@ -1289,7 +1290,7 @@ handler_t http_response_read(server *srv, connection *con, http_response_opts *o
* data immediately, unless !con->is_writable, where
* connection_state_machine() might not loop back to
* call the subrequest handler)*/
fdevent_event_clr(srv->ev, fd, FDEVENT_IN);
fdevent_fdnode_event_clr(srv->ev, fdn, FDEVENT_IN);
}
break;
}

30
src/mod_cgi.c

@ -82,6 +82,8 @@ typedef struct {
pid_t pid;
int fd;
int fdtocgi;
fdnode *fdn;
fdnode *fdntocgi;
connection *remote_conn; /* dumb pointer */
plugin_data *plugin_data; /* dumb pointer */
@ -281,9 +283,10 @@ static void cgi_pid_del(plugin_data *p, size_t i) {
static void cgi_connection_close_fdtocgi(server *srv, handler_ctx *hctx) {
/*(closes only hctx->fdtocgi)*/
fdevent_event_del(srv->ev, hctx->fdtocgi);
fdevent_fdnode_event_del(srv->ev, hctx->fdntocgi);
/*fdevent_unregister(srv->ev, hctx->fdtocgi);*//*(handled below)*/
fdevent_sched_close(srv->ev, hctx->fdtocgi, 0);
hctx->fdntocgi = NULL;
hctx->fdtocgi = -1;
}
@ -299,9 +302,10 @@ static void cgi_connection_close(server *srv, handler_ctx *hctx) {
if (hctx->fd != -1) {
/* close connection to the cgi-script */
fdevent_event_del(srv->ev, hctx->fd);
fdevent_fdnode_event_del(srv->ev, hctx->fdn);
/*fdevent_unregister(srv->ev, hctx->fd);*//*(handled below)*/
fdevent_sched_close(srv->ev, hctx->fd, 0);
hctx->fdn = NULL;
}
if (hctx->fdtocgi != -1) {
@ -408,7 +412,7 @@ static handler_t cgi_response_headers(server *srv, connection *con, struct http_
static int cgi_recv_response(server *srv, handler_ctx *hctx) {
switch (http_response_read(srv, hctx->remote_conn, &hctx->opts,
hctx->response, hctx->fd)) {
hctx->response, hctx->fdn)) {
default:
return HANDLER_GO_ON;
case HANDLER_ERROR:
@ -700,15 +704,15 @@ static int cgi_write_request(server *srv, handler_ctx *hctx, int fd) {
}
if (-1 == hctx->fdtocgi) { /*(not registered yet)*/
hctx->fdtocgi = fd;
fdevent_register(srv->ev, hctx->fdtocgi, cgi_handle_fdevent_send, hctx);
hctx->fdntocgi = fdevent_register(srv->ev, hctx->fdtocgi, cgi_handle_fdevent_send, hctx);
}
if (0 == cqlen) { /*(chunkqueue_is_empty(cq))*/
if ((fdevent_event_get_interest(srv->ev, hctx->fdtocgi) & FDEVENT_OUT)) {
fdevent_event_set(srv->ev, hctx->fdtocgi, 0);
if ((fdevent_fdnode_interest(hctx->fdntocgi) & FDEVENT_OUT)) {
fdevent_fdnode_event_set(srv->ev, hctx->fdntocgi, 0);
}
} else {
/* more request body remains to be sent to CGI so register for fdevents */
fdevent_event_set(srv->ev, hctx->fdtocgi, FDEVENT_OUT);
fdevent_fdnode_event_set(srv->ev, hctx->fdntocgi, FDEVENT_OUT);
}
}
@ -847,13 +851,13 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, handler_
++srv->cur_fds;
}
fdevent_register(srv->ev, hctx->fd, cgi_handle_fdevent, hctx);
hctx->fdn = fdevent_register(srv->ev, hctx->fd, cgi_handle_fdevent, hctx);
if (-1 == fdevent_fcntl_set_nb(srv->ev, hctx->fd)) {
log_error_write(srv, __FILE__, __LINE__, "ss", "fcntl failed: ", strerror(errno));
cgi_connection_close(srv, hctx);
return -1;
}
fdevent_event_set(srv->ev, hctx->fd, FDEVENT_IN | FDEVENT_RDHUP);
fdevent_fdnode_event_set(srv->ev, hctx->fdn, FDEVENT_IN | FDEVENT_RDHUP);
return 0;
}
@ -965,12 +969,12 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) {
if ((con->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_BUFMIN)
&& con->file_started) {
if (chunkqueue_length(con->write_queue) > 65536 - 4096) {
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_IN);
} else if (!(fdevent_event_get_interest(srv->ev, hctx->fd) & FDEVENT_IN)) {
fdevent_fdnode_event_clr(srv->ev,hctx->fdn,FDEVENT_IN);
} else if (!(fdevent_fdnode_interest(hctx->fdn) & FDEVENT_IN)) {
/* optimistic read from backend */
handler_t rc = cgi_recv_response(srv, hctx); /*(might invalidate hctx)*/
if (rc != HANDLER_GO_ON) return rc; /*(unless HANDLER_GO_ON)*/
fdevent_event_add(srv->ev, hctx->fd, FDEVENT_IN);
fdevent_fdnode_event_add(srv->ev, hctx->fdn, FDEVENT_IN);
}
}
@ -984,7 +988,7 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) {
} else {
handler_t r = connection_handle_read_post_state(srv, con);
if (!chunkqueue_is_empty(cq)) {
if (fdevent_event_get_interest(srv->ev, hctx->fdtocgi) & FDEVENT_OUT) {
if (fdevent_fdnode_interest(hctx->fdntocgi) & FDEVENT_OUT) {
return (r == HANDLER_GO_ON) ? HANDLER_WAIT_FOR_EVENT : r;
}
}

2
src/mod_fastcgi.c

@ -347,7 +347,7 @@ static handler_t fcgi_recv_parse(server *srv, connection *con, struct http_respo
if (0 == n) {
if (-1 == hctx->request_id) return HANDLER_FINISHED; /*(flag request ended)*/
if (!(fdevent_event_get_interest(srv->ev, hctx->fd) & FDEVENT_IN)
if (!(fdevent_fdnode_interest(hctx->fdn) & FDEVENT_IN)
&& !(con->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_POLLRDHUP))
return HANDLER_GO_ON;
log_error_write(srv, __FILE__, __LINE__, "ssdsb",

12
src/network.c

@ -510,9 +510,11 @@ int network_init(server *srv, int stdin_fd) {
}
void network_unregister_sock(server *srv, server_socket *srv_socket) {
if (-1 == srv_socket->fd || NULL == srv->ev) return;
fdevent_event_del(srv->ev, srv_socket->fd);
fdevent_unregister(srv->ev, srv_socket->fd);
fdnode *fdn = srv_socket->fdn;
if (NULL == fdn) return;
fdevent_fdnode_event_del(srv->ev, fdn);
fdevent_unregister(srv->ev, fdn->fd);
srv_socket->fdn = NULL;
}
int network_register_fdevents(server *srv) {
@ -528,8 +530,8 @@ int network_register_fdevents(server *srv) {
for (i = 0; i < srv->srv_sockets.used; i++) {
server_socket *srv_socket = srv->srv_sockets.ptr[i];
fdevent_register(srv->ev, srv_socket->fd, network_server_handle_fdevent, srv_socket);
fdevent_event_set(srv->ev, srv_socket->fd, FDEVENT_IN);
srv_socket->fdn = fdevent_register(srv->ev, srv_socket->fd, network_server_handle_fdevent, srv_socket);
fdevent_fdnode_event_set(srv->ev, srv_socket->fdn, FDEVENT_IN);
}
return 0;
}

2
src/response.h

@ -42,7 +42,7 @@ typedef int (*http_cgi_header_append_cb)(void *vdata, const char *k, size_t klen
int http_cgi_headers(server *srv, connection *con, http_cgi_opts *opts, http_cgi_header_append_cb cb, void *vdata);
handler_t http_response_parse_headers(server *srv, connection *con, http_response_opts *opts, buffer *hdrs);
handler_t http_response_read(server *srv, connection *con, http_response_opts *opts, buffer *b, int fd);
handler_t http_response_read(server *srv, connection *con, http_response_opts *opts, buffer *b, fdnode *fdn);
handler_t http_response_prepare(server *srv, connection *con);
int http_response_buffer_append_authority(server *srv, connection *con, buffer *b);
int http_response_redirect_to_directory(server *srv, connection *con);

7
src/server.c

@ -357,9 +357,6 @@ static void server_free(server *srv) {
CLEAN(tmp_chunk_len);
#undef CLEAN
#if 0
fdevent_unregister(srv->ev, srv->fd);
#endif
fdevent_free(srv->ev);
free(srv->conns);
@ -899,7 +896,7 @@ __attribute_cold__
static void server_sockets_set_event (server *srv, int event) {
for (size_t i = 0; i < srv->srv_sockets.used; ++i) {
server_socket *srv_socket = srv->srv_sockets.ptr[i];
fdevent_event_set(srv->ev, srv_socket->fd, event);
fdevent_fdnode_event_set(srv->ev, srv_socket->fdn, event);
}
}
@ -1889,7 +1886,7 @@ static void server_handle_sigalrm (server * const srv, time_t min_ts, time_t las
*/
for (size_t ndx = 0; ndx < conns->used; ++ndx) {
connection * const con = conns->ptr[ndx];
const int waitevents = fdevent_event_get_interest(srv->ev, con->fd);
const int waitevents = fdevent_fdnode_interest(con->fdn);
int changed = 0;
int t_diff;

21
src/stat_cache.c

@ -121,6 +121,8 @@ typedef struct stat_cache_fam {
int dir_ndx;
fam_dir_entry *fam_dir;
buffer *dir_name; /* for building the dirname from the filename */
fdnode *fdn;
int fd;
} stat_cache_fam;
static fam_dir_entry * fam_dir_entry_init(void) {
@ -207,11 +209,12 @@ static handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent)
if (revent & (FDEVENT_HUP|FDEVENT_RDHUP)) {
/* fam closed the connection */
fdevent_event_del(srv->ev, FAMCONNECTION_GETFD(&scf->fam));
fdevent_unregister(srv->ev, FAMCONNECTION_GETFD(&scf->fam));
fdevent_fdnode_event_del(srv->ev, scf->fdn);
fdevent_unregister(srv->ev, scf->fd);
scf->fdn = NULL;
FAMClose(&scf->fam);
FAMCONNECTION_GETFD(&scf->fam) = -1;
scf->fd = -1;
}
return HANDLER_GO_ON;
@ -220,6 +223,7 @@ static handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent)
static stat_cache_fam * stat_cache_init_fam(server *srv) {
stat_cache_fam *scf = calloc(1, sizeof(*scf));
scf->dir_name = buffer_init();
scf->fd = -1;
/* setup FAM */
if (0 != FAMOpen2(&scf->fam, "lighttpd")) {
@ -231,9 +235,10 @@ static stat_cache_fam * stat_cache_init_fam(server *srv) {
FAMNoExists(&scf->fam);
#endif
fdevent_setfd_cloexec(FAMCONNECTION_GETFD(&scf->fam));
fdevent_register(srv->ev, FAMCONNECTION_GETFD(&scf->fam), stat_cache_handle_fdevent, NULL);
fdevent_event_set(srv->ev, FAMCONNECTION_GETFD(&scf->fam), FDEVENT_IN | FDEVENT_RDHUP);
scf->fd = FAMCONNECTION_GETFD(&scf->fam);
fdevent_setfd_cloexec(scf->fd);
scf->fdn = fdevent_register(srv->ev, scf->fd, stat_cache_handle_fdevent, NULL);
fdevent_fdnode_event_set(srv->ev, scf->fdn, FDEVENT_IN | FDEVENT_RDHUP);
return scf;
}
@ -258,8 +263,10 @@ static void stat_cache_free_fam(stat_cache_fam *scf) {
}
}
if (-1 != FAMCONNECTION_GETFD(&scf->fam)) {
if (-1 != scf->fd) {
/*scf->fdn already cleaned up in fdevent_free()*/
FAMClose(&scf->fam);
/*scf->fd = -1;*/
}
free(scf);

Loading…
Cancel
Save