Skip to content

Commit ddfae01

Browse files
committed
separate routines for reading output from backends
move code in dynamic handlers (CGI, FastCGI, SCGI, proxy) from *_handle_fdevent() to *_recv_response() for reuse outside the *_handle_fdevent() routine
1 parent f69f209 commit ddfae01

File tree

4 files changed

+94
-36
lines changed

4 files changed

+94
-36
lines changed

src/mod_cgi.c

+15-7
Original file line numberDiff line numberDiff line change
@@ -719,13 +719,7 @@ static handler_t cgi_handle_fdevent_send (server *srv, void *ctx, int revents) {
719719
}
720720

721721

722-
static handler_t cgi_handle_fdevent(server *srv, void *ctx, int revents) {
723-
handler_ctx *hctx = ctx;
724-
connection *con = hctx->remote_conn;
725-
726-
joblist_append(srv, con);
727-
728-
if (revents & FDEVENT_IN) {
722+
static int cgi_recv_response(server *srv, handler_ctx *hctx) {
729723
switch (cgi_demux_response(srv, hctx)) {
730724
case FDEVENT_HANDLED_NOT_FINISHED:
731725
break;
@@ -745,6 +739,20 @@ static handler_t cgi_handle_fdevent(server *srv, void *ctx, int revents) {
745739
cgi_connection_close(srv, hctx);
746740
return HANDLER_FINISHED;
747741
}
742+
743+
return HANDLER_GO_ON;
744+
}
745+
746+
747+
static handler_t cgi_handle_fdevent(server *srv, void *ctx, int revents) {
748+
handler_ctx *hctx = ctx;
749+
connection *con = hctx->remote_conn;
750+
751+
joblist_append(srv, con);
752+
753+
if (revents & FDEVENT_IN) {
754+
handler_t rc = cgi_recv_response(srv, hctx);/*(might invalidate hctx)*/
755+
if (rc != HANDLER_GO_ON) return rc; /*(unless HANDLER_GO_ON)*/
748756
}
749757

750758
/* perhaps this issue is already handled */

src/mod_fastcgi.c

+20-5
Original file line numberDiff line numberDiff line change
@@ -3164,6 +3164,9 @@ static handler_t fcgi_send_request(server *srv, handler_ctx *hctx) {
31643164
}
31653165

31663166

3167+
static handler_t fcgi_recv_response(server *srv, handler_ctx *hctx);
3168+
3169+
31673170
SUBREQUEST_FUNC(mod_fastcgi_handle_subrequest) {
31683171
plugin_data *p = p_d;
31693172

@@ -3201,17 +3204,14 @@ SUBREQUEST_FUNC(mod_fastcgi_handle_subrequest) {
32013204
: HANDLER_WAIT_FOR_EVENT;
32023205
}
32033206

3204-
static handler_t fcgi_handle_fdevent(server *srv, void *ctx, int revents) {
3205-
handler_ctx *hctx = ctx;
3207+
3208+
static handler_t fcgi_recv_response(server *srv, handler_ctx *hctx) {
32063209
connection *con = hctx->remote_conn;
32073210
plugin_data *p = hctx->plugin_data;
32083211

32093212
fcgi_proc *proc = hctx->proc;
32103213
fcgi_extension_host *host= hctx->host;
32113214

3212-
joblist_append(srv, con);
3213-
3214-
if (revents & FDEVENT_IN) {
32153215
switch (fcgi_demux_response(srv, hctx)) {
32163216
case 0:
32173217
break;
@@ -3326,6 +3326,20 @@ static handler_t fcgi_handle_fdevent(server *srv, void *ctx, int revents) {
33263326

33273327
return HANDLER_FINISHED;
33283328
}
3329+
3330+
return HANDLER_GO_ON;
3331+
}
3332+
3333+
3334+
static handler_t fcgi_handle_fdevent(server *srv, void *ctx, int revents) {
3335+
handler_ctx *hctx = ctx;
3336+
connection *con = hctx->remote_conn;
3337+
3338+
joblist_append(srv, con);
3339+
3340+
if (revents & FDEVENT_IN) {
3341+
handler_t rc = fcgi_recv_response(srv, hctx);/*(might invalidate hctx)*/
3342+
if (rc != HANDLER_GO_ON) return rc; /*(unless HANDLER_GO_ON)*/
33293343
}
33303344

33313345
if (revents & FDEVENT_OUT) {
@@ -3354,6 +3368,7 @@ static handler_t fcgi_handle_fdevent(server *srv, void *ctx, int revents) {
33543368
* even if the FCGI_FIN packet is not received yet
33553369
*/
33563370
} else {
3371+
fcgi_proc *proc = hctx->proc;
33573372
log_error_write(srv, __FILE__, __LINE__, "sBSbsbsd",
33583373
"error: unexpected close of fastcgi connection for",
33593374
con->uri.path, "?", con->uri.query,

src/mod_proxy.c

+31-13
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,10 @@ static handler_t proxy_send_request(server *srv, handler_ctx *hctx) {
911911
}
912912
}
913913

914+
915+
static handler_t proxy_recv_response(server *srv, handler_ctx *hctx);
916+
917+
914918
SUBREQUEST_FUNC(mod_proxy_handle_subrequest) {
915919
plugin_data *p = p_d;
916920

@@ -948,19 +952,8 @@ SUBREQUEST_FUNC(mod_proxy_handle_subrequest) {
948952
: HANDLER_WAIT_FOR_EVENT;
949953
}
950954

951-
static handler_t proxy_handle_fdevent(server *srv, void *ctx, int revents) {
952-
handler_ctx *hctx = ctx;
953-
connection *con = hctx->remote_conn;
954-
plugin_data *p = hctx->plugin_data;
955-
956-
joblist_append(srv, con);
957955

958-
if (revents & FDEVENT_IN) {
959-
960-
if (p->conf.debug) {
961-
log_error_write(srv, __FILE__, __LINE__, "sd",
962-
"proxy: fdevent-in", hctx->state);
963-
}
956+
static handler_t proxy_recv_response(server *srv, handler_ctx *hctx) {
964957

965958
switch (proxy_demux_response(srv, hctx)) {
966959
case 0:
@@ -970,7 +963,8 @@ static handler_t proxy_handle_fdevent(server *srv, void *ctx, int revents) {
970963
proxy_connection_close(srv, hctx);
971964

972965
return HANDLER_FINISHED;
973-
case -1:
966+
case -1: {
967+
connection *con = hctx->remote_conn;
974968
if (con->file_started == 0) {
975969
/* reading response headers failed */
976970
} else {
@@ -984,6 +978,30 @@ static handler_t proxy_handle_fdevent(server *srv, void *ctx, int revents) {
984978

985979
return HANDLER_FINISHED;
986980
}
981+
}
982+
983+
return HANDLER_GO_ON;
984+
}
985+
986+
987+
static handler_t proxy_handle_fdevent(server *srv, void *ctx, int revents) {
988+
handler_ctx *hctx = ctx;
989+
connection *con = hctx->remote_conn;
990+
plugin_data *p = hctx->plugin_data;
991+
992+
joblist_append(srv, con);
993+
994+
if (revents & FDEVENT_IN) {
995+
996+
if (p->conf.debug) {
997+
log_error_write(srv, __FILE__, __LINE__, "sd",
998+
"proxy: fdevent-in", hctx->state);
999+
}
1000+
1001+
{
1002+
handler_t rc = proxy_recv_response(srv,hctx);/*(might invalidate hctx)*/
1003+
if (rc != HANDLER_GO_ON) return rc; /*(unless HANDLER_GO_ON)*/
1004+
}
9871005
}
9881006

9891007
if (revents & FDEVENT_OUT) {

src/mod_scgi.c

+28-11
Original file line numberDiff line numberDiff line change
@@ -2519,6 +2519,10 @@ static handler_t scgi_send_request(server *srv, handler_ctx *hctx) {
25192519
}
25202520
}
25212521

2522+
2523+
static handler_t scgi_recv_response(server *srv, handler_ctx *hctx);
2524+
2525+
25222526
SUBREQUEST_FUNC(mod_scgi_handle_subrequest) {
25232527
plugin_data *p = p_d;
25242528

@@ -2557,17 +2561,8 @@ SUBREQUEST_FUNC(mod_scgi_handle_subrequest) {
25572561
}
25582562

25592563

2560-
static handler_t scgi_handle_fdevent(server *srv, void *ctx, int revents) {
2561-
handler_ctx *hctx = ctx;
2562-
connection *con = hctx->remote_conn;
2563-
plugin_data *p = hctx->plugin_data;
2564+
static handler_t scgi_recv_response(server *srv, handler_ctx *hctx) {
25642565

2565-
scgi_proc *proc = hctx->proc;
2566-
scgi_extension_host *host= hctx->host;
2567-
2568-
joblist_append(srv, con);
2569-
2570-
if (revents & FDEVENT_IN) {
25712566
switch (scgi_demux_response(srv, hctx)) {
25722567
case 0:
25732568
break;
@@ -2576,7 +2571,13 @@ static handler_t scgi_handle_fdevent(server *srv, void *ctx, int revents) {
25762571
scgi_connection_close(srv, hctx);
25772572

25782573
return HANDLER_FINISHED;
2579-
case -1:
2574+
case -1: {
2575+
connection *con = hctx->remote_conn;
2576+
plugin_data *p = hctx->plugin_data;
2577+
2578+
scgi_proc *proc = hctx->proc;
2579+
scgi_extension_host *host= hctx->host;
2580+
25802581
if (proc->pid && proc->state != PROC_STATE_DIED) {
25812582
int status;
25822583

@@ -2660,6 +2661,21 @@ static handler_t scgi_handle_fdevent(server *srv, void *ctx, int revents) {
26602661

26612662
return HANDLER_FINISHED;
26622663
}
2664+
}
2665+
2666+
return HANDLER_GO_ON;
2667+
}
2668+
2669+
2670+
static handler_t scgi_handle_fdevent(server *srv, void *ctx, int revents) {
2671+
handler_ctx *hctx = ctx;
2672+
connection *con = hctx->remote_conn;
2673+
2674+
joblist_append(srv, con);
2675+
2676+
if (revents & FDEVENT_IN) {
2677+
handler_t rc = scgi_recv_response(srv, hctx);/*(might invalidate hctx)*/
2678+
if (rc != HANDLER_GO_ON) return rc; /*(unless HANDLER_GO_ON)*/
26632679
}
26642680

26652681
if (revents & FDEVENT_OUT) {
@@ -2680,6 +2696,7 @@ static handler_t scgi_handle_fdevent(server *srv, void *ctx, int revents) {
26802696
*/
26812697
scgi_send_request(srv, hctx);
26822698
} else {
2699+
scgi_extension_host *host= hctx->host;
26832700
log_error_write(srv, __FILE__, __LINE__, "sbSBSDSd",
26842701
"error: unexpected close of scgi connection for",
26852702
con->uri.path,

0 commit comments

Comments
 (0)