Commit b2930e5d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Give the state engine a explanatory enum, rather than magic values

of 0, 1 and 2.
parent cd4bb90e
...@@ -57,6 +57,16 @@ ...@@ -57,6 +57,16 @@
#include "common/params.h" #include "common/params.h"
/*--------------------------------------------------------------------*/
enum req_fsm_nxt {
REQ_FSM_MORE,
REQ_FSM_DONE,
REQ_FSM_DISEMBARK,
};
/*--------------------------------------------------------------------*/
enum body_status { enum body_status {
#define BODYSTATUS(U,l) BS_##U, #define BODYSTATUS(U,l) BS_##U,
#include "tbl/body_status.h" #include "tbl/body_status.h"
...@@ -786,7 +796,7 @@ int HTTP1_CacheReqBody(struct req *req, ssize_t maxsize); ...@@ -786,7 +796,7 @@ int HTTP1_CacheReqBody(struct req *req, ssize_t maxsize);
int HTTP1_IterateReqBody(struct req *req, req_body_iter_f *func, void *priv); int HTTP1_IterateReqBody(struct req *req, req_body_iter_f *func, void *priv);
/* cache_req_fsm.c [CNT] */ /* cache_req_fsm.c [CNT] */
int CNT_Request(struct worker *, struct req *); enum req_fsm_nxt CNT_Request(struct worker *, struct req *);
/* cache_cli.c [CLI] */ /* cache_cli.c [CLI] */
void CLI_Init(void); void CLI_Init(void);
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
* Collect a request from the client. * Collect a request from the client.
*/ */
static int static enum req_fsm_nxt
http1_wait(struct sess *sp, struct worker *wrk, struct req *req) http1_wait(struct sess *sp, struct worker *wrk, struct req *req)
{ {
int j, tmo; int j, tmo;
...@@ -120,7 +120,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) ...@@ -120,7 +120,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req)
if (hs == HTC_COMPLETE) { if (hs == HTC_COMPLETE) {
/* Got it, run with it */ /* Got it, run with it */
req->t_req = now; req->t_req = now;
return (0); return (REQ_FSM_MORE);
} else if (hs == HTC_ERROR_EOF) { } else if (hs == HTC_ERROR_EOF) {
why = SC_REM_CLOSE; why = SC_REM_CLOSE;
break; break;
...@@ -141,7 +141,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) ...@@ -141,7 +141,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req)
wrk->stats.sess_herd++; wrk->stats.sess_herd++;
SES_ReleaseReq(req); SES_ReleaseReq(req);
WAIT_Enter(sp); WAIT_Enter(sp);
return (1); return (REQ_FSM_DONE);
} }
} else { } else {
/* Working on it */ /* Working on it */
...@@ -158,7 +158,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) ...@@ -158,7 +158,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req)
SES_ReleaseReq(req); SES_ReleaseReq(req);
assert(why != SC_NULL); assert(why != SC_NULL);
SES_Delete(sp, why, now); SES_Delete(sp, why, now);
return (1); return (REQ_FSM_DONE);
} }
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
...@@ -238,7 +238,7 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req) ...@@ -238,7 +238,7 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req)
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
*/ */
static int static enum req_fsm_nxt
http1_dissect(struct worker *wrk, struct req *req) http1_dissect(struct worker *wrk, struct req *req)
{ {
const char *r = "HTTP/1.1 100 Continue\r\n\r\n"; const char *r = "HTTP/1.1 100 Continue\r\n\r\n";
...@@ -266,7 +266,7 @@ http1_dissect(struct worker *wrk, struct req *req) ...@@ -266,7 +266,7 @@ http1_dissect(struct worker *wrk, struct req *req)
if (req->err_code == 400) { if (req->err_code == 400) {
wrk->stats.client_req_400++; wrk->stats.client_req_400++;
SES_Close(req->sp, SC_RX_JUNK); SES_Close(req->sp, SC_RX_JUNK);
return (1); return (REQ_FSM_DONE);
} }
req->acct_req.req++; req->acct_req.req++;
...@@ -280,7 +280,7 @@ http1_dissect(struct worker *wrk, struct req *req) ...@@ -280,7 +280,7 @@ http1_dissect(struct worker *wrk, struct req *req)
req->err_code = 417; req->err_code = 417;
} else if (strlen(r) != write(req->sp->fd, r, strlen(r))) { } else if (strlen(r) != write(req->sp->fd, r, strlen(r))) {
SES_Close(req->sp, SC_REM_CLOSE); SES_Close(req->sp, SC_REM_CLOSE);
return (1); return (REQ_FSM_DONE);
} }
} else if (req->err_code == 413) } else if (req->err_code == 413)
wrk->stats.client_req_413++; wrk->stats.client_req_413++;
...@@ -293,7 +293,7 @@ http1_dissect(struct worker *wrk, struct req *req) ...@@ -293,7 +293,7 @@ http1_dissect(struct worker *wrk, struct req *req)
HTTP_Copy(req->http0, req->http); // For ESI & restart HTTP_Copy(req->http0, req->http); // For ESI & restart
return (0); return (REQ_FSM_MORE);
} }
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
...@@ -302,7 +302,7 @@ http1_dissect(struct worker *wrk, struct req *req) ...@@ -302,7 +302,7 @@ http1_dissect(struct worker *wrk, struct req *req)
void void
HTTP1_Session(struct worker *wrk, struct req *req) HTTP1_Session(struct worker *wrk, struct req *req)
{ {
int done = 0; enum req_fsm_nxt nxt = REQ_FSM_MORE;
struct sess *sp; struct sess *sp;
enum http1_cleanup_ret sdr; enum http1_cleanup_ret sdr;
...@@ -343,12 +343,12 @@ HTTP1_Session(struct worker *wrk, struct req *req) ...@@ -343,12 +343,12 @@ HTTP1_Session(struct worker *wrk, struct req *req)
if (sp->sess_step == S_STP_WORKING) { if (sp->sess_step == S_STP_WORKING) {
if (req->req_step == R_STP_RECV) if (req->req_step == R_STP_RECV)
done = http1_dissect(wrk, req); nxt = http1_dissect(wrk, req);
if (done == 0) if (nxt == REQ_FSM_MORE)
done = CNT_Request(wrk, req); nxt = CNT_Request(wrk, req);
if (done == 2) if (nxt == REQ_FSM_DISEMBARK)
return; return;
assert(done == 1); assert(nxt == REQ_FSM_DONE);
sdr = http1_cleanup(sp, wrk, req); sdr = http1_cleanup(sp, wrk, req);
switch (sdr) { switch (sdr) {
case SESS_DONE_RET_GONE: case SESS_DONE_RET_GONE:
...@@ -366,8 +366,8 @@ HTTP1_Session(struct worker *wrk, struct req *req) ...@@ -366,8 +366,8 @@ HTTP1_Session(struct worker *wrk, struct req *req)
} }
if (sp->sess_step == S_STP_NEWREQ) { if (sp->sess_step == S_STP_NEWREQ) {
done = http1_wait(sp, wrk, req); nxt = http1_wait(sp, wrk, req);
if (done) if (nxt != REQ_FSM_MORE)
return; return;
sp->sess_step = S_STP_WORKING; sp->sess_step = S_STP_WORKING;
req->req_step = R_STP_RECV; req->req_step = R_STP_RECV;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment