Commit 72f9364a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Give VSS_open() a timeout argument.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4588 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 60417404
......@@ -97,10 +97,10 @@ client_thread(void *priv)
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));
......
......@@ -35,4 +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 nonblock);
int VSS_open(const char *str);
int VSS_open(const char *str, double tmo);
......@@ -156,7 +156,7 @@ cli_readres(int fd, unsigned *status, char **ptr, double tmo)
*ptr = strdup("CLI communication error (hdr)");
if (i != 0)
return (i);
return (400);
return (*status);
}
assert(i == CLI_LINE0_LEN);
assert(res[3] == ' ');
......
......@@ -40,6 +40,7 @@ SVNID("$Id$")
#include <errno.h>
#include <netdb.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -264,12 +265,13 @@ VSS_connect(const struct vss_addr *va, int nonblock)
*/
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 @@ VSS_open(const char *str)
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;
}
......
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