[master] fb71118 Try to make the H1 state engine look more like one.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Mar 24 13:02:48 CET 2015
commit fb711185114b2131a6e08d77e2bc6955e3c2f5d9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Mar 24 09:42:07 2015 +0000
Try to make the H1 state engine look more like one.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 15ac93e..615b830 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -989,7 +989,7 @@ enum htc_status_e {
HTC_S_TIMEOUT = -3,
HTC_S_OVERFLOW = -2,
HTC_S_EOF = -1,
- HTC_S_OK = 0,
+ HTC_S_OK = 0,
HTC_S_COMPLETE = 1
};
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index b54fb0a..5ee4cfb 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -330,7 +330,6 @@ SES_Proto_Sess(struct worker *wrk, void *arg)
cache_param->http_req_size, cache_param->http_req_hdr_len);
if (sp->sess_step < S_STP_H1_LAST) {
- sp->sess_step = S_STP_H1NEWREQ;
wrk->task.func = SES_Proto_Req;
wrk->task.priv = req;
} else if (sp->sess_step < S_STP_PROXY_LAST) {
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index 60bec64..2a3c3fb 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -331,31 +331,55 @@ HTTP1_Session(struct worker *wrk, struct req *req)
return;
}
- /*
- * Return from waitinglist. Check to see if the remote has left.
- */
- if (req->req_step == R_STP_LOOKUP && VTCP_check_hup(sp->fd)) {
- AN(req->hash_objhead);
- (void)HSH_DerefObjHead(wrk, &req->hash_objhead);
- AZ(req->hash_objhead);
- SES_Close(sp, SC_REM_CLOSE);
- AN(http1_cleanup(sp, wrk, req));
- return;
- }
while (1) {
- assert(
- sp->sess_step == S_STP_H1NEWREQ ||
- req->req_step == R_STP_LOOKUP ||
- req->req_step == R_STP_RECV);
+ switch (sp->sess_step) {
+ case S_STP_H1NEWSESS:
+ if (VTCP_blocking(sp->fd)) {
+ if (errno == ECONNRESET)
+ SES_Close(sp, SC_REM_CLOSE);
+ else
+ SES_Close(sp, SC_TX_ERROR);
+ AN(http1_cleanup(sp, wrk, req));
+ return;
+ }
+ sp->sess_step = S_STP_H1NEWREQ;
+ break;
+ case S_STP_H1NEWREQ:
+ nxt = http1_wait(sp, wrk, req);
+ if (nxt != REQ_FSM_MORE)
+ return;
+ sp->sess_step = S_STP_H1WORKING;
+ req->req_step = R_STP_RECV;
+ break;
+ case S_STP_H1BUSY:
+ /*
+ * Return from waitinglist.
+ * Check to see if the remote has left.
+ */
+ if (VTCP_check_hup(sp->fd)) {
+ AN(req->hash_objhead);
+ (void)HSH_DerefObjHead(wrk, &req->hash_objhead);
+ AZ(req->hash_objhead);
+ SES_Close(sp, SC_REM_CLOSE);
+ AN(http1_cleanup(sp, wrk, req));
+ return;
+ }
+ sp->sess_step = S_STP_H1WORKING;
+ break;
+ case S_STP_H1WORKING:
+ assert(
+ req->req_step == R_STP_LOOKUP ||
+ req->req_step == R_STP_RECV);
- if (sp->sess_step == S_STP_H1WORKING) {
if (req->req_step == R_STP_RECV)
nxt = http1_dissect(wrk, req);
if (nxt == REQ_FSM_MORE)
nxt = CNT_Request(wrk, req);
- if (nxt == REQ_FSM_DISEMBARK)
+ if (nxt == REQ_FSM_DISEMBARK) {
+ sp->sess_step = S_STP_H1BUSY;
return;
+ }
assert(nxt == REQ_FSM_DONE);
if (http1_cleanup(sp, wrk, req))
return;
@@ -373,14 +397,10 @@ HTTP1_Session(struct worker *wrk, struct req *req)
wrk->stats->sess_readahead++;
sp->sess_step = S_STP_H1NEWREQ;
}
+ break;
+ default:
+ WRONG("Wrong H1 session state");
}
- if (sp->sess_step == S_STP_H1NEWREQ) {
- nxt = http1_wait(sp, wrk, req);
- if (nxt != REQ_FSM_MORE)
- return;
- sp->sess_step = S_STP_H1WORKING;
- req->req_step = R_STP_RECV;
- }
}
}
More information about the varnish-commit
mailing list