[master] a3c3e4e Have http_conn point to the fd rather than carry a copy

Poul-Henning Kamp phk at FreeBSD.org
Fri Jan 27 13:45:06 CET 2017


commit a3c3e4ef2fb762bc6cfce1d0586bb69a58b815c7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Jan 27 12:43:43 2017 +0000

    Have http_conn point to the fd rather than carry a copy

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index add792c..ddecdf6 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -218,7 +218,7 @@ struct http_conn {
 	unsigned		magic;
 #define HTTP_CONN_MAGIC		0x3e19edd1
 
-	int			fd;
+	int			*rfd;
 	enum sess_close		doclose;
 	enum body_status	body_status;
 	struct ws		*ws;
diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index cb907a9..d764d1b 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -373,7 +373,7 @@ vca_make_session(struct worker *wrk, void *arg)
 
 	req = Req_New(wrk, sp);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	req->htc->fd = sp->fd;
+	req->htc->rfd = &sp->fd;
 
 	SES_SetTransport(wrk, sp, req, wa->acceptlsock->transport);
 }
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 58a89bd..3e7ecdb 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -119,7 +119,7 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo)
 
 	INIT_OBJ(bo->htc, HTTP_CONN_MAGIC);
 	bo->htc->priv = vc;
-	bo->htc->fd = vc->fd;
+	bo->htc->rfd = &vc->fd;
 	FIND_TMO(first_byte_timeout,
 	    bo->htc->first_byte_timeout, bo, bp);
 	FIND_TMO(between_bytes_timeout,
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 16ecf47..8338490 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -183,7 +183,8 @@ pan_htc(struct vsb *vsb, const struct http_conn *htc)
 		return;
 	VSB_indent(vsb, 2);
 	PAN_CheckMagic(vsb, htc, HTTP_CONN_MAGIC);
-	VSB_printf(vsb, "fd = %d,\n", htc->fd);
+	if (htc->rfd != NULL)
+		VSB_printf(vsb, "fd = %d (@%p),\n", *htc->rfd, htc->rfd);
 	VSB_printf(vsb, "doclose = %s,\n", sess_close_2str(htc->doclose, 0));
 	pan_ws(vsb, htc->ws);
 	VSB_printf(vsb, "{rxbuf_b, rxbuf_e} = {%p, %p},\n",
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index 62f8369..fe1598b 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -68,7 +68,6 @@ Req_New(const struct worker *wrk, struct sess *sp)
 	req->top = req;	// esi overrides
 
 	INIT_OBJ(req->htc, HTTP_CONN_MAGIC);
-	req->htc->fd = -1;
 
 	e = (char*)req + sz;
 	p = (char*)(req + 1);
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 20a2844..10bb4bb 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -238,6 +238,8 @@ HTC_RxStuff(struct http_conn *htc, htc_complete_f *func,
 	int i;
 
 	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
+	AN(htc->rfd);
+	assert(*htc->rfd > 0);
 	AN(htc->ws->r);
 	AN(htc->rxbuf_b);
 	assert(htc->rxbuf_b <= htc->rxbuf_e);
@@ -294,7 +296,7 @@ HTC_RxStuff(struct http_conn *htc, htc_complete_f *func,
 		}
 		if (tmo <= 0.0)
 			tmo = 1e-3;
-		i = VTCP_read(htc->fd, htc->rxbuf_e, i, tmo);
+		i = VTCP_read(*htc->rfd, htc->rxbuf_e, i, tmo);
 		if (i == 0 || i == -1) {
 			WS_ReleaseP(htc->ws, htc->rxbuf_b);
 			return (HTC_S_EOF);
diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c
index f29da00..15cf047 100644
--- a/bin/varnishd/http1/cache_http1_fetch.c
+++ b/bin/varnishd/http1/cache_http1_fetch.c
@@ -88,6 +88,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr,
 	CHECK_OBJ_ORNULL(bo->req, REQ_MAGIC);
 
 	htc = bo->htc;
+	assert(*htc->rfd > 0);
 	hp = bo->bereq;
 
 	if (bo->req != NULL &&
@@ -96,11 +97,11 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr,
 		do_chunked = 1;
 	}
 
-	VTCP_hisname(htc->fd, abuf, sizeof abuf, pbuf, sizeof pbuf);
+	VTCP_hisname(*htc->rfd, abuf, sizeof abuf, pbuf, sizeof pbuf);
 	VSLb(bo->vsl, SLT_BackendStart, "%s %s", abuf, pbuf);
 
-	(void)VTCP_blocking(htc->fd);	/* XXX: we should timeout instead */
-	V1L_Reserve(wrk, wrk->aws, &htc->fd, bo->vsl, bo->t_prev);
+	(void)VTCP_blocking(*htc->rfd);	/* XXX: we should timeout instead */
+	V1L_Reserve(wrk, wrk->aws, htc->rfd, bo->vsl, bo->t_prev);
 	*ctr += HTTP1_Write(wrk, hp, HTTP1_Req);
 
 	/* Deal with any message-body the request might (still) have */
@@ -150,6 +151,7 @@ V1F_FetchRespHdr(struct busyobj *bo)
 	CHECK_OBJ_ORNULL(bo->req, REQ_MAGIC);
 
 	htc = bo->htc;
+	assert(*htc->rfd > 0);
 
 	VSC_C_main->backend_req++;
 
@@ -189,7 +191,7 @@ V1F_FetchRespHdr(struct busyobj *bo)
 		}
 		return (htc->rxbuf_e == htc->rxbuf_b ? 1 : -1);
 	}
-	VTCP_set_read_timeout(htc->fd, htc->between_bytes_timeout);
+	VTCP_set_read_timeout(*htc->rfd, htc->between_bytes_timeout);
 
 	hp = bo->beresp;
 
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index ed1d3fd..b6fd99a 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -130,7 +130,7 @@ http1_unwait(struct worker *wrk, void *arg)
 	WS_Release(sp->ws, 0);
 	req = Req_New(wrk, sp);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	req->htc->fd = sp->fd;
+	req->htc->rfd = &sp->fd;
 	HTC_RxInit(req->htc, req->ws);
 	http1_setstate(sp, H1NEWREQ);
 	wrk->task.func = http1_req;
diff --git a/bin/varnishd/http1/cache_http1_vfp.c b/bin/varnishd/http1/cache_http1_vfp.c
index b836cd3..d287fa5 100644
--- a/bin/varnishd/http1/cache_http1_vfp.c
+++ b/bin/varnishd/http1/cache_http1_vfp.c
@@ -73,7 +73,7 @@ v1f_read(const struct vfp_ctx *vc, struct http_conn *htc, void *d, ssize_t len)
 			htc->pipeline_b = htc->pipeline_e = NULL;
 	}
 	if (len > 0) {
-		i = read(htc->fd, p, len);
+		i = read(*htc->rfd, p, len);
 		if (i < 0) {
 			// XXX: VTCP_Assert(i); // but also: EAGAIN
 			VSLb(vc->wrk->vsl, SLT_FetchError,
diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c
index 7e9ab9e..27872e7 100644
--- a/bin/varnishd/http2/cache_http2_proto.c
+++ b/bin/varnishd/http2/cache_http2_proto.c
@@ -136,7 +136,7 @@ h2_new_sess(const struct worker *wrk, struct sess *sp, struct req *srq)
 		h2->ws = srq->ws;
 		h2->vsl = srq->vsl;
 		h2->vsl->wid = sp->vxid;
-		h2->htc->fd = sp->fd;
+		h2->htc->rfd = &sp->fd;
 		h2->sess = sp;
 		VTAILQ_INIT(&h2->streams);
 #define H2_SETTINGS(n,v,d)					\
@@ -496,7 +496,7 @@ h2_rxframe(struct worker *wrk, struct h2_sess *h2)
 	enum h2frame ft;
 	struct h2_req *r2 = NULL;
 
-	(void)VTCP_blocking(h2->htc->fd);
+	(void)VTCP_blocking(*h2->htc->rfd);
 	h2->sess->t_idle = VTIM_real();
 	hs = HTC_RxStuff(h2->htc, h2_frame_complete,
 	    NULL, NULL, NAN,



More information about the varnish-commit mailing list