[master] 194c072 Add a VTCP_open() function to replace VSS_open().

Poul-Henning Kamp phk at FreeBSD.org
Thu Mar 12 00:12:00 CET 2015


commit 194c072379b854073ada7564ac9df2f3eee821a8
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Mar 11 23:08:04 2015 +0000

    Add a VTCP_open() function to replace VSS_open().
    
    libc should have had a function like this at least 25 years ago :-/

diff --git a/include/vtcp.h b/include/vtcp.h
index 3165364..174975e 100644
--- a/include/vtcp.h
+++ b/include/vtcp.h
@@ -53,6 +53,8 @@ void VTCP_name(const struct suckaddr *addr, char *abuf, unsigned alen,
     char *pbuf, unsigned plen);
 int VTCP_connected(int s);
 int VTCP_connect(const struct suckaddr *name, int msec);
+int VTCP_open(const char *addr, const char *def_port, double timeout,
+    const char **err);
 void VTCP_close(int *s);
 void VTCP_set_read_timeout(int s, double seconds);
 #endif
diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c
index be7f6e0..d3d34de 100644
--- a/lib/libvarnish/vtcp.c
+++ b/lib/libvarnish/vtcp.c
@@ -50,8 +50,10 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "vdef.h"
 #include "vas.h"
 #include "vsa.h"
+#include "vss.h"
 #include "vtcp.h"
 
 /*--------------------------------------------------------------------*/
@@ -326,6 +328,37 @@ VTCP_set_read_timeout(int s, double seconds)
 }
 
 /*--------------------------------------------------------------------
+ */
+
+static int __match_proto__(vss_resolved_f)
+vtcp_open_callback(void *priv, const struct suckaddr *sa)
+{
+	double *p = priv;
+
+	return (VTCP_connect(sa, (int)floor(*p * 1e3)));
+}
+
+int
+VTCP_open(const char *addr, const char *def_port, double timeout,
+    const char **errp)
+{
+	int error;
+	const char *err;
+
+	if (errp != NULL)
+		*errp = NULL;
+	assert(timeout >= 0);
+	error = VSS_resolver(addr, def_port, vtcp_open_callback,
+	    &timeout, &err);
+	if (err != NULL) {
+		if (errp != NULL)
+			*errp = err;
+		return (-1);
+	}
+	return (error);
+}
+
+/*--------------------------------------------------------------------
  * Set or reset SO_LINGER flag
  */
 



More information about the varnish-commit mailing list