r2701 - in trunk/varnish-cache: include lib/libvarnish
phk at projects.linpro.no
phk at projects.linpro.no
Mon Jun 16 23:25:36 CEST 2008
Author: phk
Date: 2008-06-16 23:25:36 +0200 (Mon, 16 Jun 2008)
New Revision: 2701
Modified:
trunk/varnish-cache/include/vss.h
trunk/varnish-cache/lib/libvarnish/vss.c
Log:
Add VSS_open(const char *str) for when you just want a connection and
don't really care about addresses and all that.
Modified: trunk/varnish-cache/include/vss.h
===================================================================
--- trunk/varnish-cache/include/vss.h 2008-06-16 07:10:47 UTC (rev 2700)
+++ trunk/varnish-cache/include/vss.h 2008-06-16 21:25:36 UTC (rev 2701)
@@ -35,3 +35,4 @@
int VSS_bind(const struct vss_addr *addr);
int VSS_listen(const struct vss_addr *addr, int depth);
int VSS_connect(const struct vss_addr *addr);
+int VSS_open(const char *str);
Modified: trunk/varnish-cache/lib/libvarnish/vss.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/vss.c 2008-06-16 07:10:47 UTC (rev 2700)
+++ trunk/varnish-cache/lib/libvarnish/vss.c 2008-06-16 21:25:36 UTC (rev 2701)
@@ -124,6 +124,8 @@
* freeing each individual struct vss_addr as well as the array.
*
* The return value is the number of addresses resoved, or zero.
+ *
+ * XXX: We need a function to free the allocated addresses.
*/
int
VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap)
@@ -240,7 +242,8 @@
sd = socket(va->va_family, va->va_socktype, va->va_protocol);
if (sd < 0) {
- perror("socket()");
+ if (errno != EPROTONOSUPPORT)
+ perror("socket()");
return (-1);
}
if (connect(sd, &va->va_addr.sa, va->va_addrlen) != 0) {
@@ -250,3 +253,37 @@
}
return (sd);
}
+
+/*
+ * And the totally brutal version: Give me connection to this address
+ */
+
+int
+VSS_open(const char *str)
+{
+ int retval;
+ char *addr = NULL, *port = NULL;
+ int nvaddr, n;
+ struct vss_addr **vaddr;
+
+ retval = VSS_parse(str, &addr, &port);
+ if (retval < 0)
+ return (retval);
+ nvaddr = VSS_resolve(addr, port, &vaddr);
+ if (nvaddr <= 0) {
+ free(addr);
+ free(port);
+ return (-1);
+ }
+ for (n = 0; n < nvaddr; n++) {
+ retval = VSS_connect(vaddr[n]);
+ if (retval >= 0)
+ break;
+ }
+ for (n = 0; n < nvaddr; n++)
+ free(vaddr[n]);
+ free(vaddr);
+ free(addr);
+ free(port);
+ return (retval);
+}
More information about the varnish-commit
mailing list