[master] 7a28f076e Move the VTC client connection to its own function

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Nov 13 21:14:09 UTC 2019


commit 7a28f076ebb6845459a5ef108eb4547d0618b1a0
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Nov 13 19:03:36 2019 +0100

    Move the VTC client connection to its own function

diff --git a/bin/varnishtest/vtc_client.c b/bin/varnishtest/vtc_client.c
index 29915a0b3..9777da7ba 100644
--- a/bin/varnishtest/vtc_client.c
+++ b/bin/varnishtest/vtc_client.c
@@ -54,6 +54,7 @@ struct client {
 	char			*spec;
 
 	char			connect[256];
+	const char		*addr;
 	int			rcvbuf;
 
 	char			*proxy_spec;
@@ -180,6 +181,27 @@ client_uds_connect(struct vtclog *vl, const char *path, double tmo,
 	return (fd);
 }
 
+static int
+client_connect(struct vtclog *vl, struct client *c)
+{
+	const char *err;
+	int fd;
+
+	vtc_log(vl, 3, "Connect to %s", c->addr);
+	if (*c->addr == '/')
+		fd = client_uds_connect(vl, c->addr, 10., &err);
+	else
+		fd = client_tcp_connect(vl, c->addr, 10., &err);
+	if (fd < 0)
+		vtc_fatal(c->vl, "Failed to open %s: %s",
+		    c->addr, err);
+	/* VTCP_blocking does its own checks, trust it */
+	VTCP_blocking(fd);
+	if (c->proxy_spec != NULL)
+		client_proxy(vl, fd, c->proxy_version, c->proxy_spec);
+	return (fd);
+}
+
 /**********************************************************************
  * Client thread
  */
@@ -192,7 +214,6 @@ client_thread(void *priv)
 	int fd;
 	int i;
 	struct vsb *vsb;
-	const char *err;
 
 	CAST_OBJ_NOTNULL(c, priv, CLIENT_MAGIC);
 	AN(*c->connect);
@@ -202,6 +223,7 @@ client_thread(void *priv)
 
 	vsb = macro_expand(vl, c->connect);
 	AN(vsb);
+	c->addr = VSB_data(vsb);
 
 	if (c->repeat == 0)
 		c->repeat = 1;
@@ -209,27 +231,15 @@ client_thread(void *priv)
 		vtc_log(vl, 2, "Started (%u iterations%s)", c->repeat,
 			c->keepalive ? " using keepalive" : "");
 	for (i = 0; i < c->repeat; i++) {
-		char *addr = VSB_data(vsb);
+		fd = client_connect(vl, c);
 
-		vtc_log(vl, 3, "Connect to %s", addr);
-		if (*addr == '/')
-			fd = client_uds_connect(vl, addr, 10., &err);
-		else
-			fd = client_tcp_connect(vl, VSB_data(vsb), 10., &err);
-		if (fd < 0)
-			vtc_fatal(c->vl, "Failed to open %s: %s",
-			    VSB_data(vsb), err);
-		/* VTCP_blocking does its own checks, trust it */
-		VTCP_blocking(fd);
-		if (c->proxy_spec != NULL)
-			client_proxy(vl, fd, c->proxy_version, c->proxy_spec);
 		if (! c->keepalive)
-			fd = http_process(vl, c->spec, fd, NULL, addr,
+			fd = http_process(vl, c->spec, fd, NULL, c->addr,
 			    c->rcvbuf);
 		else
 			while (fd >= 0 && i++ < c->repeat)
-				fd = http_process(vl, c->spec, fd, NULL, addr,
-				    c->rcvbuf);
+				fd = http_process(vl, c->spec, fd, NULL,
+				    c->addr, c->rcvbuf);
 		vtc_log(vl, 3, "closing fd %d", fd);
 		VTCP_close(&fd);
 	}


More information about the varnish-commit mailing list