Commit a63b2347 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add VSS_open(const char *str) for when you just want a connection and

don't really care about addresses and all that.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2701 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 9995f85a
......@@ -35,3 +35,4 @@ int VSS_resolve(const char *addr, const char *port, struct vss_addr ***ta);
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);
......@@ -124,6 +124,8 @@ VSS_parse(const char *str, char **addr, char **port)
* 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 @@ VSS_connect(const struct vss_addr *va)
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 @@ VSS_connect(const struct vss_addr *va)
}
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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment