[master] 4e7e34994 Turn enum h2_stream_e into a const struct which knows its own name.

Poul-Henning Kamp phk at FreeBSD.org
Wed Oct 3 10:17:10 UTC 2018


commit 4e7e349949d7305dd8d21539b128b0225f7357b7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Oct 3 08:31:17 2018 +0000

    Turn enum h2_stream_e into a const struct which knows its own name.

diff --git a/bin/varnishd/http2/cache_http2.h b/bin/varnishd/http2/cache_http2.h
index 70e31d14e..938f0d6a4 100644
--- a/bin/varnishd/http2/cache_http2.h
+++ b/bin/varnishd/http2/cache_http2.h
@@ -104,12 +104,14 @@ struct h2_setting_s {
 
 /**********************************************************************/
 
-enum h2_stream_e {
-	H2_STREAM__DUMMY = -1,
-#define H2_STREAM(U,s,d) H2_S_##U,
-#include "tbl/h2_stream.h"
+struct h2_stream_s {
+	const char	*name;
+	const char	*desc;
 };
 
+#define H2_STREAM(u,s,d) extern const struct h2_stream_s H2_S_##u[1];
+#include "tbl/h2_stream.h"
+
 #define H2_FRAME_FLAGS(l,u,v)   extern const uint8_t H2FF_##u;
 #include "tbl/h2_frames.h"
 
@@ -118,7 +120,7 @@ struct h2_req {
 #define H2_REQ_MAGIC			0x03411584
 	uint32_t			stream;
 	int				scheduled;
-	enum h2_stream_e		state;
+	const struct h2_stream_s	*state;
 	struct h2_sess			*h2sess;
 	struct req			*req;
 	double				t_send;
diff --git a/bin/varnishd/http2/cache_http2_panic.c b/bin/varnishd/http2/cache_http2_panic.c
index 9e80eb67b..640cdbe53 100644
--- a/bin/varnishd/http2/cache_http2_panic.c
+++ b/bin/varnishd/http2/cache_http2_panic.c
@@ -50,13 +50,11 @@ h2_sess_panic(struct vsb *vsb, const struct sess *sp)
 	VTAILQ_FOREACH(r2, &h2->streams, list) {
 		PAN_CheckMagic(vsb, r2, H2_REQ_MAGIC);
 		VSB_printf(vsb, "0x%08x", r2->stream);
-		switch (r2->state) {
-#define H2_STREAM(U,sd,d) case H2_S_##U: VSB_printf(vsb, " %-6s", sd); break;
-#include <tbl/h2_stream.h>
-		default:
-			VSB_printf(vsb, " State %d", r2->state);
-			break;
-		}
+		if (r2->state == NULL)
+			VSB_printf(vsb, " State NULL");
+		else
+			VSB_printf(vsb, " State %s (%s)",
+			    r2->state->name, r2->state->desc);
 		VSB_printf(vsb, "\n");
 	}
 	VSB_indent(vsb, -2);
diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c
index 070bf2cad..4d4034af5 100644
--- a/bin/varnishd/http2/cache_http2_proto.c
+++ b/bin/varnishd/http2/cache_http2_proto.c
@@ -60,6 +60,10 @@ static const struct h2_error_s H2NN_ERROR[1] = {{
 	1
 }};
 
+#define H2_STREAM(u,s,d) const struct h2_stream_s H2_S_##u[1] = {{ s, d }};
+#include "tbl/h2_stream.h"
+
+
 enum h2frame {
 #define H2_FRAME(l,u,t,f,...)	H2F_##u = t,
 #include "tbl/h2_frames.h"
@@ -213,7 +217,8 @@ h2_kill_req(struct worker *wrk, const struct h2_sess *h2,
 	ASSERT_RXTHR(h2);
 	AN(h2e);
 	Lck_Lock(&h2->sess->mtx);
-	VSLb(h2->vsl, SLT_Debug, "KILL st=%u state=%d", r2->stream, r2->state);
+	VSLb(h2->vsl, SLT_Debug, "KILL st=%u state=%s",
+	    r2->stream, r2->state ? r2->state->name : "NULL");
 	if (r2->error == NULL)
 		r2->error = h2e;
 	if (r2->scheduled) {
@@ -424,18 +429,14 @@ h2_win_adjust(const struct h2_sess *h2, uint32_t oldval, uint32_t newval)
 		CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC);
 		if (r2 == h2->req0)
 			continue; // rfc7540,l,2699,2699
-		switch (r2->state) {
-		case H2_S_IDLE:
-		case H2_S_OPEN:
-		case H2_S_CLOS_REM:
+		if (r2->state == H2_S_IDLE ||
+		    r2->state == H2_S_OPEN ||
+		    r2->state == H2_S_CLOS_REM) {
 			/*
 			 * We allow a window to go negative, as per
 			 * rfc7540,l,2676,2680
 			 */
 			r2->t_window += (int64_t)newval - oldval;
-			break;
-		default:
-			break;
 		}
 	}
 }
@@ -1002,38 +1003,28 @@ h2_sweep(struct worker *wrk, struct h2_sess *h2)
 	VTAILQ_FOREACH_SAFE(r2, &h2->streams, list, r22) {
 		if (r2 == h2->req0) {
 			assert (r2->state == H2_S_IDLE);
-			continue;
-		}
-		switch (r2->state) {
-		case H2_S_CLOSED:
+		} else if (r2->state == H2_S_CLOSED) {
 			if (!r2->scheduled)
 				h2_del_req(wrk, r2);
-			break;
-		case H2_S_CLOS_REM:
+		} else if (r2->state == H2_S_CLOS_REM) {
 			if (!r2->scheduled) {
 				h2_tx_rst(wrk, h2, h2->req0, r2->stream,
 				    H2SE_REFUSED_STREAM);
 				h2_del_req(wrk, r2);
-				continue;
-			}
-			/* FALLTHROUGH */
-		case H2_S_CLOS_LOC:
-		case H2_S_OPEN:
-			if (h2_stream_tmo(h2, r2)) {
+			} else if (h2_stream_tmo(h2, r2)) {
 				tmo = 1;
-				continue;
 			}
-			break;
-		case H2_S_IDLE:
+		} else if (r2->state == H2_S_CLOS_LOC ||
+			   r2->state == H2_S_OPEN) {
+			if (h2_stream_tmo(h2, r2))
+				tmo = 1;
+		} else if(r2->state == H2_S_IDLE) {
 			/* This stream was created from receiving a
 			 * PRIORITY frame, and should not be counted
 			 * as an active stream keeping the connection
 			 * open. */
 			AZ(r2->scheduled);
 			nprio++;
-			break;
-		default:
-			break;
 		}
 	}
 	if (tmo)
diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c
index ce114d390..f38ef6bfd 100644
--- a/bin/varnishd/http2/cache_http2_session.c
+++ b/bin/varnishd/http2/cache_http2_session.c
@@ -420,8 +420,8 @@ h2_new_session(struct worker *wrk, void *arg)
 			break;
 		Lck_Lock(&h2->sess->mtx);
 		VTAILQ_FOREACH(r2, &h2->streams, list)
-			VSLb(h2->vsl, SLT_Debug, "ST %u %d",
-			    r2->stream, r2->state);
+			VSLb(h2->vsl, SLT_Debug, "ST %u %s",
+			    r2->stream, r2->state ? r2->state->name : "NULL");
 		(void)Lck_CondWait(h2->cond, &h2->sess->mtx, VTIM_real() + .1);
 		Lck_Unlock(&h2->sess->mtx);
 	}


More information about the varnish-commit mailing list