This is how long time we wait for a TCP connection to the backend to
become established.
Typical usage:
backend b1 {
.host = "hex";
.port = "80";
.connect_timeout = 500 ms;
}
It can also be used in backends in director declarations.
Also add a parameter called "connect_timeout" which sets the default
to 400 msec (a number pulled out of my old black magicians hat).
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2642
d4fa192b-c00b-0410-8231-
f00ffab90ce4
struct sockaddr_storage ss;
int fam, sockt, proto;
socklen_t alen;
- int s;
+ int s, i, tmo;
char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE];
char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE];
return (s);
}
- if (connect(s, (void *)&ss, alen) != 0) {
+ tmo = params->connect_timeout;
+ if (sp->backend->vrt->connect_timeout > 10e-3)
+ tmo = sp->backend->vrt->connect_timeout * 1000;
+
+ if (tmo > 0)
+ i = TCP_connect(s, (void *)&ss, alen, tmo);
+ else
+ i = connect(s, (void *)&ss, alen);
+
+ if (i != 0) {
AZ(close(s));
LOCK(&sp->backend->mtx);
return (-1);
/* Cache vbe_conns */
unsigned cache_vbe_conns;
+ /* Default connection_timeout */
+ unsigned connect_timeout;
+
/* CLI buffer size */
unsigned cli_buffer;
"Cache vbe_conn's or rely on malloc, that's the question.",
EXPERIMENTAL,
"off", "bool" },
+ { "connect_timeout", tweak_uint,
+ &master.connect_timeout,0, UINT_MAX,
+ "Default connection timeout for backend connections. "
+ "We only try to connect to the backend for this many "
+ "milliseconds before giving up. "
+ "VCL can override this default value for each backend.",
+ 0,
+ "400", "ms" },
{ "cli_buffer", tweak_uint, &master.cli_buffer, 4096, UINT_MAX,
"Size of buffer for CLI input."
"\nYou may need to increase this if you have big VCL files "
const char *hostname;
const char *vcl_name;
const char *ident;
+ double connect_timeout;
};
/*
struct host *h;
struct fld_spec *fs;
- fs = vcc_FldSpec(tl, "!host", "?port", NULL);
+ fs = vcc_FldSpec(tl, "!host", "?port", "?connect_timeout", NULL);
t_first = tl->t;
if (tl->t->tok == ID) {
t_host = tl->t;
vcc_NextToken(tl);
} else if (vcc_IdIs(t_field, "port")) {
- ExpectErr(tl, CSTR);
assert(tl->t->dec != NULL);
t_port = tl->t;
vcc_NextToken(tl);
+ } else if (vcc_IdIs(t_field, "connect_timeout")) {
+ Fh(tl, 0, "\t.connect_timeout = ");
+ tl->fb = tl->fh;
+ vcc_TimeVal(tl);
+ tl->fb = NULL;
+ ERRCHK(tl);
+ Fh(tl, 0, ",\n");
} else {
ErrInternal(tl);
return;
vsb_cat(sb, " const char *hostname;\n");
vsb_cat(sb, " const char *vcl_name;\n");
vsb_cat(sb, " const char *ident;\n");
+ vsb_cat(sb, " double connect_timeout;\n");
vsb_cat(sb, "};\n");
vsb_cat(sb, "\n");
vsb_cat(sb, "/*\n");