[master] dc80d95 Add VTCP_listen_on() which resolves and listens on an address

Poul-Henning Kamp phk at FreeBSD.org
Thu Mar 12 01:36:50 CET 2015


commit dc80d9507de53212bc862e90d5413f343ea2e595
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Mar 12 00:28:50 2015 +0000

    Add VTCP_listen_on() which resolves and listens on an address

diff --git a/include/vtcp.h b/include/vtcp.h
index 8f25974..641cc14 100644
--- a/include/vtcp.h
+++ b/include/vtcp.h
@@ -58,5 +58,7 @@ int VTCP_open(const char *addr, const char *def_port, double timeout,
 void VTCP_close(int *s);
 int VTCP_bind(const struct suckaddr *addr, const char **errp);
 int VTCP_listen(const struct suckaddr *addr, int depth, const char **errp);
+int VTCP_listen_on(const char *addr, const char *def_port, int depth,
+    const char **errp);
 void VTCP_set_read_timeout(int s, double seconds);
 // #endif
diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c
index 0a72c5b..d59b214 100644
--- a/lib/libvarnish/vtcp.c
+++ b/lib/libvarnish/vtcp.c
@@ -445,6 +445,44 @@ VTCP_listen(const struct suckaddr *sa, int depth, const char **errp)
 	return (sd);
 }
 
+/*--------------------------------------------------------------------*/
+
+struct helper {
+	int		depth;
+	const char	**errp;
+};
+
+static int __match_proto__(vss_resolved_f)
+vtcp_lo_cb(void *priv, const struct suckaddr *sa)
+{
+	int sock;
+	struct helper *hp = priv;
+
+	sock = VTCP_listen(sa, hp->depth, hp->errp);
+	if (sock > 0) {
+		*hp->errp = NULL;
+		return (sock);
+	}
+	AN(*hp->errp);
+	return (0);
+}
+
+int
+VTCP_listen_on(const char *addr, const char *def_port, int depth,
+    const char **errp)
+{
+	struct helper h;
+	int sock;
+
+	h.depth = depth;
+	h.errp = errp;
+
+	sock = VSS_resolver(addr, def_port, vtcp_lo_cb, &h, errp);
+	if (*errp != NULL)
+		return (-1);
+	return(sock);
+}
+
 /*--------------------------------------------------------------------
  * Set or reset SO_LINGER flag
  */



More information about the varnish-commit mailing list