Browse Source

[mod_cgi] improve chunk buffer reuse from backends

mark and temporarily defer event handling of backend events in order
to handle at same time as the associated front-end connection events
Glenn Strauss 1 month ago
parent
commit
28b2e64720
  1. 36
      src/mod_cgi.c

36
src/mod_cgi.c

@ -71,10 +71,13 @@ typedef struct {
struct cgi_pid_t *cgi_pid;
int fd;
int fdtocgi;
int rd_revents;
int wr_revents;
fdnode *fdn;
fdnode *fdntocgi;
request_st *r;
connection *con; /* dumb pointer */
struct fdevents *ev; /* dumb pointer */
plugin_data *plugin_data; /* dumb pointer */
@ -472,11 +475,13 @@ static int cgi_write_request(handler_ctx *hctx, int fd);
static handler_t cgi_handle_fdevent_send (void *ctx, int revents) {
handler_ctx *hctx = ctx;
request_st * const r = hctx->r;
hctx->wr_revents |= revents;
joblist_append(hctx->con);
return HANDLER_FINISHED;
}
/*(joblist only actually necessary here in mod_cgi fdevent send if returning HANDLER_ERROR)*/
joblist_append(r->con);
static handler_t cgi_process_wr_revents (handler_ctx * const hctx, request_st * const r, int revents) {
if (revents & FDEVENT_OUT) {
if (0 != cgi_write_request(hctx, hctx->fdtocgi)) {
cgi_connection_close(hctx);
@ -505,7 +510,7 @@ static handler_t cgi_handle_fdevent_send (void *ctx, int revents) {
return HANDLER_ERROR;
}
return HANDLER_FINISHED;
return HANDLER_GO_ON;
}
@ -568,10 +573,13 @@ static int cgi_recv_response(request_st * const r, handler_ctx * const hctx) {
static handler_t cgi_handle_fdevent(void *ctx, int revents) {
handler_ctx *hctx = ctx;
request_st * const r = hctx->r;
hctx->rd_revents |= revents;
joblist_append(hctx->con);
return HANDLER_FINISHED;
}
joblist_append(r->con);
static handler_t cgi_process_rd_revents(handler_ctx * const hctx, request_st * const r, int revents) {
if (revents & FDEVENT_IN) {
handler_t rc = cgi_recv_response(r, hctx); /*(might invalidate hctx)*/
if (rc != HANDLER_GO_ON) return rc; /*(unless HANDLER_GO_ON)*/
@ -610,7 +618,7 @@ static handler_t cgi_handle_fdevent(void *ctx, int revents) {
return HANDLER_ERROR;
}
return HANDLER_FINISHED;
return HANDLER_GO_ON;
}
@ -959,6 +967,7 @@ URIHANDLER_FUNC(cgi_is_handled) {
handler_ctx *hctx = cgi_handler_ctx_init();
hctx->ev = r->con->srv->ev;
hctx->r = r;
hctx->con = r->con;
hctx->plugin_data = p;
hctx->cgi_handler = &ds->value;
memcpy(&hctx->conf, &p->conf, sizeof(plugin_config));
@ -1009,6 +1018,19 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) {
handler_ctx * const hctx = r->plugin_ctx[p->id];
if (NULL == hctx) return HANDLER_GO_ON;
const int rd_revents = hctx->rd_revents;
const int wr_revents = hctx->wr_revents;
if (rd_revents) {
hctx->rd_revents = 0;
handler_t rc = cgi_process_rd_revents(hctx, r, rd_revents);
if (rc != HANDLER_GO_ON) return rc; /*(might invalidate hctx)*/
}
if (wr_revents) {
hctx->wr_revents = 0;
handler_t rc = cgi_process_wr_revents(hctx, r, wr_revents);
if (rc != HANDLER_GO_ON) return rc; /*(might invalidate hctx)*/
}
if (__builtin_expect(
(r->conf.stream_request_body & FDEVENT_STREAM_REQUEST_TCP_FIN), 0)
&& hctx->conf.limits && hctx->conf.limits->signal_fin) {

Loading…
Cancel
Save