From: phk Date: Mon, 9 Jun 2008 13:01:27 +0000 (+0000) Subject: Add a VSS_bind() function, using the meat of VSS_listen() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46f0a8c8e7751f489f90a637305128f43455fed9;p=varnish Add a VSS_bind() function, using the meat of VSS_listen() git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2657 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/include/vss.h b/varnish-cache/include/vss.h index 77e52d1b..49abeeac 100644 --- a/varnish-cache/include/vss.h +++ b/varnish-cache/include/vss.h @@ -32,5 +32,6 @@ struct vss_addr; int VSS_parse(const char *str, char **addr, char **port); 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); diff --git a/varnish-cache/lib/libvarnish/vss.c b/varnish-cache/lib/libvarnish/vss.c index 2bfff35e..2f9c201b 100644 --- a/varnish-cache/lib/libvarnish/vss.c +++ b/varnish-cache/lib/libvarnish/vss.c @@ -165,14 +165,15 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) } /* - * Given a struct vss_addr, open a socket of the appropriate type, bind it - * to the requested address, and start listening. + * Given a struct vss_addr, open a socket of the appropriate type, and bind + * it to the requested address. * * If the address is an IPv6 address, the IPV6_V6ONLY option is set to * avoid conflicts between INADDR_ANY and IN6ADDR_ANY. */ + int -VSS_listen(const struct vss_addr *va, int depth) +VSS_bind(const struct vss_addr *va) { int sd, val; @@ -202,10 +203,28 @@ VSS_listen(const struct vss_addr *va, int depth) (void)close(sd); return (-1); } - if (listen(sd, depth) != 0) { - perror("listen()"); - (void)close(sd); - return (-1); + return (sd); +} + +/* + * Given a struct vss_addr, open a socket of the appropriate type, bind it + * to the requested address, and start listening. + * + * If the address is an IPv6 address, the IPV6_V6ONLY option is set to + * avoid conflicts between INADDR_ANY and IN6ADDR_ANY. + */ +int +VSS_listen(const struct vss_addr *va, int depth) +{ + int sd; + + sd = VSS_bind(va); + if (sd >= 0) { + if (listen(sd, depth) != 0) { + perror("listen()"); + (void)close(sd); + return (-1); + } } return (sd); }