[core] remove fde_ndx member outside fdevents
(isolated to fdevent framework internals)personal/stbuehler/ci-build
parent
0a46f7ec23
commit
800e9b7349
|
@ -213,7 +213,6 @@ struct connection {
|
|||
*/
|
||||
|
||||
int fd; /* the FD for this connection */
|
||||
int fde_ndx; /* index for the fdevent-handler */
|
||||
int ndx; /* reverse mapping to server->connection[ndx] */
|
||||
|
||||
/* fd states */
|
||||
|
@ -349,7 +348,6 @@ typedef struct {
|
|||
typedef struct server_socket {
|
||||
sock_addr addr;
|
||||
int fd;
|
||||
int fde_ndx;
|
||||
|
||||
unsigned short is_ssl;
|
||||
unsigned short sidx;
|
||||
|
|
|
@ -110,7 +110,7 @@ static int connection_close(server *srv, connection *con) {
|
|||
con->request_count = 0;
|
||||
chunkqueue_reset(con->read_queue);
|
||||
|
||||
fdevent_event_del(srv->ev, &(con->fde_ndx), con->fd);
|
||||
fdevent_event_del(srv->ev, con->fd);
|
||||
fdevent_unregister(srv->ev, con->fd);
|
||||
#ifdef __WIN32
|
||||
if (closesocket(con->fd)) {
|
||||
|
@ -531,7 +531,6 @@ static connection *connection_init(server *srv) {
|
|||
|
||||
con->fd = 0;
|
||||
con->ndx = -1;
|
||||
con->fde_ndx = -1;
|
||||
con->bytes_written = 0;
|
||||
con->bytes_read = 0;
|
||||
con->bytes_header = 0;
|
||||
|
@ -917,7 +916,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->fde_ndx, con->fd, events);
|
||||
fdevent_event_set(srv->ev, con->fd, 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).
|
||||
|
@ -927,7 +926,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->fde_ndx, con->fd, events);
|
||||
fdevent_event_set(srv->ev, con->fd, events);
|
||||
} else {
|
||||
/* Failure of fdevent_is_tcp_half_closed() indicates TCP RST
|
||||
* (or unable to tell (unsupported OS), though should not
|
||||
|
@ -1096,7 +1095,6 @@ connection *connection_accepted(server *srv, server_socket *srv_socket, sock_add
|
|||
con = connections_get_new_connection(srv);
|
||||
|
||||
con->fd = cnt;
|
||||
con->fde_ndx = -1;
|
||||
fdevent_register(srv->ev, con->fd, connection_handle_fdevent, con);
|
||||
con->network_read = connection_read_cq;
|
||||
con->network_write = connection_write_cq;
|
||||
|
@ -1365,7 +1363,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->fde_ndx, con->fd, r);
|
||||
fdevent_event_set(srv->ev, con->fd, r);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -372,8 +372,7 @@ 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 *fde_ndx, int fd) {
|
||||
UNUSED(fde_ndx);
|
||||
void fdevent_event_del(fdevents *ev, int fd) {
|
||||
if (-1 != fd) {
|
||||
fdnode *fdn = ev->fdarray[fd];
|
||||
if ((uintptr_t)fdn & 0x3) return;
|
||||
|
@ -381,21 +380,18 @@ void fdevent_event_del(fdevents *ev, int *fde_ndx, int fd) {
|
|||
}
|
||||
}
|
||||
|
||||
void fdevent_event_set(fdevents *ev, int *fde_ndx, int fd, int events) {
|
||||
UNUSED(fde_ndx);
|
||||
void fdevent_event_set(fdevents *ev, int fd, int events) {
|
||||
if (-1 != fd) fdevent_fdnode_event_set(ev, ev->fdarray[fd], events);
|
||||
}
|
||||
|
||||
void fdevent_event_add(fdevents *ev, int *fde_ndx, int fd, int event) {
|
||||
UNUSED(fde_ndx);
|
||||
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_event_clr(fdevents *ev, int *fde_ndx, int fd, int event) {
|
||||
UNUSED(fde_ndx);
|
||||
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));
|
||||
|
|
|
@ -51,10 +51,10 @@ __attribute_cold__
|
|||
void fdevent_free(fdevents *ev);
|
||||
|
||||
int fdevent_event_get_interest(const fdevents *ev, int fd);
|
||||
void fdevent_event_set(fdevents *ev, int *fde_ndx, int fd, int events); /* events can be FDEVENT_IN, FDEVENT_OUT or FDEVENT_IN | FDEVENT_OUT */
|
||||
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);
|
||||
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);
|
||||
|
||||
int fdevent_poll(fdevents *ev, int timeout_ms);
|
||||
|
||||
|
|
|
@ -1055,8 +1055,6 @@ static gw_handler_ctx * handler_ctx_init(size_t sz) {
|
|||
gw_handler_ctx *hctx = calloc(1, 0 == sz ? sizeof(*hctx) : sz);
|
||||
force_assert(hctx);
|
||||
|
||||
hctx->fde_ndx = -1;
|
||||
|
||||
/*hctx->response = chunk_buffer_acquire();*//*(allocated when needed)*/
|
||||
|
||||
hctx->request_id = 0;
|
||||
|
@ -1106,7 +1104,6 @@ static void handler_ctx_clear(gw_handler_ctx *hctx) {
|
|||
if (hctx->response) buffer_clear(hctx->response);
|
||||
|
||||
hctx->fd = -1;
|
||||
hctx->fde_ndx = -1;
|
||||
hctx->reconnects = 0;
|
||||
hctx->request_id = 0;
|
||||
hctx->send_content_body = 1;
|
||||
|
@ -1646,11 +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->fde_ndx), hctx->fd);
|
||||
fdevent_event_del(srv->ev, hctx->fd);
|
||||
/*fdevent_unregister(srv->ev, hctx->fd);*//*(handled below)*/
|
||||
fdevent_sched_close(srv->ev, hctx->fd, 1);
|
||||
hctx->fd = -1;
|
||||
hctx->fde_ndx = -1;
|
||||
}
|
||||
|
||||
if (hctx->host) {
|
||||
|
@ -1716,7 +1712,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->fde_ndx, hctx->fd, FDEVENT_OUT);
|
||||
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_OUT);
|
||||
}
|
||||
|
||||
static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
|
||||
|
@ -1771,7 +1767,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->fde_ndx), hctx->fd, FDEVENT_OUT);
|
||||
fdevent_event_set(srv->ev, hctx->fd, FDEVENT_OUT);
|
||||
gw_set_state(srv, hctx, GW_STATE_CONNECT_DELAYED);
|
||||
return HANDLER_WAIT_FOR_EVENT;
|
||||
case -1:/* connection error */
|
||||
|
@ -1803,8 +1799,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->fde_ndx), hctx->fd,
|
||||
FDEVENT_OUT);
|
||||
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_OUT);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
@ -1819,8 +1814,7 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
|
|||
}
|
||||
}
|
||||
|
||||
fdevent_event_add(srv->ev, &hctx->fde_ndx, hctx->fd,
|
||||
FDEVENT_IN | FDEVENT_RDHUP);
|
||||
fdevent_event_add(srv->ev, hctx->fd, FDEVENT_IN | FDEVENT_RDHUP);
|
||||
gw_set_state(srv, hctx, GW_STATE_WRITE);
|
||||
/* fall through */
|
||||
case GW_STATE_WRITE:
|
||||
|
@ -1862,7 +1856,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->fde_ndx), hctx->fd, FDEVENT_OUT);
|
||||
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_OUT);
|
||||
gw_set_state(srv, hctx, GW_STATE_READ);
|
||||
} else {
|
||||
off_t wblen = hctx->wb->bytes_in - hctx->wb->bytes_out;
|
||||
|
@ -1878,9 +1872,9 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
|
|||
}
|
||||
}
|
||||
if (0 == wblen) {
|
||||
fdevent_event_clr(srv->ev,&hctx->fde_ndx,hctx->fd,FDEVENT_OUT);
|
||||
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_OUT);
|
||||
} else {
|
||||
fdevent_event_add(srv->ev,&hctx->fde_ndx,hctx->fd,FDEVENT_OUT);
|
||||
fdevent_event_add(srv->ev, hctx->fd, FDEVENT_OUT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1938,14 +1932,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->fde_ndx), hctx->fd, FDEVENT_IN);
|
||||
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_IN);
|
||||
}
|
||||
else if (!(fdevent_event_get_interest(srv->ev, hctx->fd) & 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->fde_ndx), hctx->fd, FDEVENT_IN);
|
||||
fdevent_event_add(srv->ev, hctx->fd, FDEVENT_IN);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2033,8 +2027,8 @@ static handler_t gw_recv_response(server *srv, gw_handler_ctx *hctx) {
|
|||
? chunk_buffer_acquire()
|
||||
: hctx->response;
|
||||
|
||||
handler_t rc = http_response_read(srv, hctx->remote_conn, &hctx->opts,
|
||||
b, hctx->fd, &hctx->fde_ndx);
|
||||
handler_t rc =
|
||||
http_response_read(srv, hctx->remote_conn, &hctx->opts, b, hctx->fd);
|
||||
|
||||
if (b != hctx->response) chunk_buffer_release(b);
|
||||
|
||||
|
|
|
@ -312,7 +312,6 @@ typedef struct gw_handler_ctx {
|
|||
buffer *response;
|
||||
|
||||
int fd; /* fd to the gw process */
|
||||
int fde_ndx; /* index into the fd-event buffer */
|
||||
|
||||
pid_t pid;
|
||||
int reconnects; /* number of reconnect attempts */
|
||||
|
|
|
@ -1175,7 +1175,7 @@ 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, int *fde_ndx) {
|
||||
handler_t http_response_read(server *srv, connection *con, http_response_opts *opts, buffer *b, int fd) {
|
||||
while (1) {
|
||||
ssize_t n;
|
||||
size_t avail = buffer_string_space(b);
|
||||
|
@ -1218,7 +1218,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, fde_ndx, fd, FDEVENT_IN);
|
||||
fdevent_event_clr(srv->ev, fd, FDEVENT_IN);
|
||||
}
|
||||
if (cqlen >= 65536-1) return HANDLER_GO_ON;
|
||||
toread = 65536 - 1 - (unsigned int)cqlen;
|
||||
|
@ -1289,7 +1289,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, fde_ndx, fd, FDEVENT_IN);
|
||||
fdevent_event_clr(srv->ev, fd, FDEVENT_IN);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -82,8 +82,6 @@ typedef struct {
|
|||
pid_t pid;
|
||||
int fd;
|
||||
int fdtocgi;
|
||||
int fde_ndx; /* index into the fd-event buffer */
|
||||
int fde_ndx_tocgi; /* index into the fd-event buffer */
|
||||
|
||||
connection *remote_conn; /* dumb pointer */
|
||||
plugin_data *plugin_data; /* dumb pointer */
|
||||
|
@ -283,7 +281,7 @@ 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->fde_ndx_tocgi), hctx->fdtocgi);
|
||||
fdevent_event_del(srv->ev, hctx->fdtocgi);
|
||||
/*fdevent_unregister(srv->ev, hctx->fdtocgi);*//*(handled below)*/
|
||||
fdevent_sched_close(srv->ev, hctx->fdtocgi, 0);
|
||||
hctx->fdtocgi = -1;
|
||||
|
@ -301,7 +299,7 @@ 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->fde_ndx), hctx->fd);
|
||||
fdevent_event_del(srv->ev, hctx->fd);
|
||||
/*fdevent_unregister(srv->ev, hctx->fd);*//*(handled below)*/
|
||||
fdevent_sched_close(srv->ev, hctx->fd, 0);
|
||||
}
|
||||
|
@ -410,7 +408,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->fde_ndx)) {
|
||||
hctx->response, hctx->fd)) {
|
||||
default:
|
||||
return HANDLER_GO_ON;
|
||||
case HANDLER_ERROR:
|
||||
|
@ -702,16 +700,15 @@ static int cgi_write_request(server *srv, handler_ctx *hctx, int fd) {
|
|||
}
|
||||
if (-1 == hctx->fdtocgi) { /*(not registered yet)*/
|
||||
hctx->fdtocgi = fd;
|
||||
hctx->fde_ndx_tocgi = -1;
|
||||
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->fde_ndx_tocgi), hctx->fdtocgi, 0);
|
||||
fdevent_event_set(srv->ev, hctx->fdtocgi, 0);
|
||||
}
|
||||
} else {
|
||||
/* more request body remains to be sent to CGI so register for fdevents */
|
||||
fdevent_event_set(srv->ev, &(hctx->fde_ndx_tocgi), hctx->fdtocgi, FDEVENT_OUT);
|
||||
fdevent_event_set(srv->ev, hctx->fdtocgi, FDEVENT_OUT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -825,7 +822,6 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, handler_
|
|||
close(to_cgi_fds[0]);
|
||||
|
||||
hctx->fd = from_cgi_fds[0];
|
||||
hctx->fde_ndx = -1;
|
||||
|
||||
++srv->cur_fds;
|
||||
|
||||
|
@ -857,7 +853,7 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, handler_
|
|||
cgi_connection_close(srv, hctx);
|
||||
return -1;
|
||||
}
|
||||
fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN | FDEVENT_RDHUP);
|
||||
fdevent_event_set(srv->ev, hctx->fd, FDEVENT_IN | FDEVENT_RDHUP);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -969,12 +965,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->fde_ndx), hctx->fd, FDEVENT_IN);
|
||||
fdevent_event_clr(srv->ev, hctx->fd, FDEVENT_IN);
|
||||
} else if (!(fdevent_event_get_interest(srv->ev, hctx->fd) & 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->fde_ndx), hctx->fd, FDEVENT_IN);
|
||||
fdevent_event_add(srv->ev, hctx->fd, FDEVENT_IN);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -204,7 +204,6 @@ static int network_server_init(server *srv, buffer *host_token, size_t sidx, int
|
|||
force_assert(NULL != srv_socket);
|
||||
memcpy(&srv_socket->addr, &addr, addr_len);
|
||||
srv_socket->fd = -1;
|
||||
srv_socket->fde_ndx = -1;
|
||||
srv_socket->sidx = sidx;
|
||||
srv_socket->is_ssl = s->ssl_enabled;
|
||||
srv_socket->srv_token = buffer_init_buffer(host_token);
|
||||
|
@ -511,8 +510,8 @@ int network_init(server *srv, int stdin_fd) {
|
|||
}
|
||||
|
||||
void network_unregister_sock(server *srv, server_socket *srv_socket) {
|
||||
if (-1 == srv_socket->fd || -1 == srv_socket->fde_ndx) return;
|
||||
fdevent_event_del(srv->ev, &srv_socket->fde_ndx, srv_socket->fd);
|
||||
if (-1 == srv_socket->fd || NULL == srv->ev) return;
|
||||
fdevent_event_del(srv->ev, srv_socket->fd);
|
||||
fdevent_unregister(srv->ev, srv_socket->fd);
|
||||
}
|
||||
|
||||
|
@ -530,7 +529,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_set(srv->ev, &(srv_socket->fde_ndx), srv_socket->fd, FDEVENT_IN);
|
||||
fdevent_event_set(srv->ev, srv_socket->fd, FDEVENT_IN);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -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, int *fde_ndx);
|
||||
handler_t http_response_read(server *srv, connection *con, http_response_opts *opts, buffer *b, int fd);
|
||||
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);
|
||||
|
|
15
src/server.c
15
src/server.c
|
@ -899,12 +899,14 @@ __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->fde_ndx),srv_socket->fd,event);
|
||||
fdevent_event_set(srv->ev, srv_socket->fd, event);
|
||||
}
|
||||
}
|
||||
|
||||
__attribute_cold__
|
||||
static void server_sockets_unregister (server *srv) {
|
||||
if (2 == srv->sockets_disabled) return;
|
||||
srv->sockets_disabled = 2;
|
||||
for (size_t i = 0; i < srv->srv_sockets.used; ++i)
|
||||
network_unregister_sock(srv, srv->srv_sockets.ptr[i]);
|
||||
}
|
||||
|
@ -916,14 +918,16 @@ static void server_sockets_close (server *srv) {
|
|||
* (e.g. fastcgi, scgi, etc) are independent from lighttpd, rather
|
||||
* than started by lighttpd via "bin-path")
|
||||
*/
|
||||
if (3 == srv->sockets_disabled) return;
|
||||
for (size_t i = 0; i < srv->srv_sockets.used; ++i) {
|
||||
server_socket *srv_socket = srv->srv_sockets.ptr[i];
|
||||
if (-1 == srv_socket->fd) continue;
|
||||
network_unregister_sock(srv, srv_socket);
|
||||
if (2 != srv->sockets_disabled) network_unregister_sock(srv,srv_socket);
|
||||
close(srv_socket->fd);
|
||||
srv_socket->fd = -1;
|
||||
/* network_close() will cleanup after us */
|
||||
}
|
||||
srv->sockets_disabled = 3;
|
||||
}
|
||||
|
||||
__attribute_cold__
|
||||
|
@ -968,10 +972,8 @@ static void server_graceful_state (server *srv) {
|
|||
|
||||
if (!srv_shutdown) server_graceful_shutdown_maint(srv);
|
||||
|
||||
if (!oneshot_fd) {
|
||||
if (0==srv->srv_sockets.used || -1 == srv->srv_sockets.ptr[0]->fde_ndx)
|
||||
return;
|
||||
}
|
||||
if (!oneshot_fd
|
||||
&& (2 == srv->sockets_disabled || 3 == srv->sockets_disabled)) return;
|
||||
|
||||
log_error_write(srv, __FILE__, __LINE__, "s",
|
||||
"[note] graceful shutdown started");
|
||||
|
@ -1980,7 +1982,6 @@ static int server_main_loop (server * const srv) {
|
|||
|
||||
if (graceful_shutdown) {
|
||||
server_graceful_state(srv);
|
||||
srv->sockets_disabled = 1;
|
||||
if (srv->conns->used == 0) {
|
||||
/* we are in graceful shutdown phase and all connections are closed
|
||||
* we are ready to terminate without harming anyone */
|
||||
|
|
|
@ -117,7 +117,6 @@ typedef struct stat_cache_fam {
|
|||
splay_tree *dirs; /* the nodes of the tree are fam_dir_entry */
|
||||
|
||||
FAMConnection fam;
|
||||
int fam_fcce_ndx;
|
||||
|
||||
int dir_ndx;
|
||||
fam_dir_entry *fam_dir;
|
||||
|
@ -208,10 +207,11 @@ 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, &(scf->fam_fcce_ndx), FAMCONNECTION_GETFD(&scf->fam));
|
||||
fdevent_event_del(srv->ev, FAMCONNECTION_GETFD(&scf->fam));
|
||||
fdevent_unregister(srv->ev, FAMCONNECTION_GETFD(&scf->fam));
|
||||
|
||||
FAMClose(&scf->fam);
|
||||
FAMCONNECTION_GETFD(&scf->fam) = -1;
|
||||
}
|
||||
|
||||
return HANDLER_GO_ON;
|
||||
|
@ -219,7 +219,6 @@ 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->fam_fcce_ndx = -1;
|
||||
scf->dir_name = buffer_init();
|
||||
|
||||
/* setup FAM */
|
||||
|
@ -234,7 +233,7 @@ static stat_cache_fam * stat_cache_init_fam(server *srv) {
|
|||
|
||||
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, &(scf->fam_fcce_ndx), FAMCONNECTION_GETFD(&scf->fam), FDEVENT_IN | FDEVENT_RDHUP);
|
||||
fdevent_event_set(srv->ev, FAMCONNECTION_GETFD(&scf->fam), FDEVENT_IN | FDEVENT_RDHUP);
|
||||
|
||||
return scf;
|
||||
}
|
||||
|
@ -259,10 +258,7 @@ static void stat_cache_free_fam(stat_cache_fam *scf) {
|
|||
}
|
||||
}
|
||||
|
||||
if (-1 != scf->fam_fcce_ndx) {
|
||||
/* fd events already gone */
|
||||
scf->fam_fcce_ndx = -1;
|
||||
|
||||
if (-1 != FAMCONNECTION_GETFD(&scf->fam)) {
|
||||
FAMClose(&scf->fam);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue