r4588 - in trunk/varnish-cache: bin/varnishtest include lib/libvarnish
phk at projects.linpro.no
phk at projects.linpro.no
Fri Feb 26 10:35:42 CET 2010
Author: phk
Date: 2010-02-26 10:35:42 +0100 (Fri, 26 Feb 2010)
New Revision: 4588
Modified:
trunk/varnish-cache/bin/varnishtest/vtc_client.c
trunk/varnish-cache/include/vss.h
trunk/varnish-cache/lib/libvarnish/cli_common.c
trunk/varnish-cache/lib/libvarnish/vss.c
Log:
Give VSS_open() a timeout argument.
Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_client.c 2010-02-26 08:57:00 UTC (rev 4587)
+++ trunk/varnish-cache/bin/varnishtest/vtc_client.c 2010-02-26 09:35:42 UTC (rev 4588)
@@ -97,10 +97,10 @@
vtc_log(vl, 2, "Started (%u iterations)", c->repeat);
for (u = 0; u < c->repeat; u++) {
vtc_log(vl, 3, "Connect to %s", vsb_data(vsb));
- fd = VSS_open(vsb_data(vsb));
+ fd = VSS_open(vsb_data(vsb), 0);
for (i = 0; fd < 0 && i < 3; i++) {
(void)sleep(1);
- fd = VSS_open(vsb_data(vsb));
+ fd = VSS_open(vsb_data(vsb), 0);
}
if (fd < 0)
vtc_log(c->vl, 0, "Failed to open %s", vsb_data(vsb));
Modified: trunk/varnish-cache/include/vss.h
===================================================================
--- trunk/varnish-cache/include/vss.h 2010-02-26 08:57:00 UTC (rev 4587)
+++ trunk/varnish-cache/include/vss.h 2010-02-26 09:35:42 UTC (rev 4588)
@@ -35,4 +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 nonblock);
-int VSS_open(const char *str);
+int VSS_open(const char *str, double tmo);
Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/cli_common.c 2010-02-26 08:57:00 UTC (rev 4587)
+++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2010-02-26 09:35:42 UTC (rev 4588)
@@ -156,7 +156,7 @@
*ptr = strdup("CLI communication error (hdr)");
if (i != 0)
return (i);
- return (400);
+ return (*status);
}
assert(i == CLI_LINE0_LEN);
assert(res[3] == ' ');
Modified: trunk/varnish-cache/lib/libvarnish/vss.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/vss.c 2010-02-26 08:57:00 UTC (rev 4587)
+++ trunk/varnish-cache/lib/libvarnish/vss.c 2010-02-26 09:35:42 UTC (rev 4588)
@@ -40,6 +40,7 @@
#include <errno.h>
#include <netdb.h>
+#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -264,12 +265,13 @@
*/
int
-VSS_open(const char *str)
+VSS_open(const char *str, double tmo)
{
int retval;
char *addr = NULL, *port = NULL;
- int nvaddr, n;
+ int nvaddr, n, i;
struct vss_addr **vaddr;
+ struct pollfd pfd;
retval = VSS_parse(str, &addr, &port);
if (retval < 0)
@@ -281,7 +283,16 @@
return (-1);
}
for (n = 0; n < nvaddr; n++) {
- retval = VSS_connect(vaddr[n], 0);
+ retval = VSS_connect(vaddr[n], tmo != 0.0);
+ if (retval >= 0 && tmo != 0.0) {
+ pfd.fd = retval;
+ pfd.events = POLLOUT;
+ i = poll(&pfd, 1, tmo * 1e3);
+ if (i == 0 || pfd.revents != POLLOUT) {
+ (void)close(retval);
+ retval = -1;
+ }
+ }
if (retval >= 0)
break;
}
More information about the varnish-commit
mailing list