Commit 119056c4 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

vcc_backend: Initialize undefined timeouts with -1

We can't use NAN in VGC code today, so in order to convey the lack of
timeout setting in a backend definition, only a negative value makes
sense since zero will eventually mean zero instead of undefined.

This is an implicit breakage of the VRT ABI for the meaning of struct
vrt_backend.
parent 1a49e049
......@@ -99,7 +99,7 @@ VBE_Connect_Error(struct VSC_vbe *vsc, int err)
do { \
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); \
dst = bo->tmx; \
if (dst == 0.0) \
if (dst == 0.0 && be->tmx >= 0.0) \
dst = be->tmx; \
if (dst == 0.0) \
dst = cache_param->tmx; \
......
......@@ -64,6 +64,8 @@
* VRT_u_sess_send_timeout() added
* VRT_u_sess_timeout_idle() added
* VRT_u_sess_timeout_linger() added
* (struct vrt_backend).*_timeout must be initialized to a negative value
* VRT_BACKEND_INIT() helper macro added
* 18.1 (2023-12-05)
* vbf_objiterate() implementation changed #4013
* 18.0 (2023-09-15)
......@@ -582,6 +584,14 @@ struct vrt_endpoint {
unsigned max_connections; \
unsigned proxy_header;
#define VRT_BACKEND_INIT(be) \
do { \
INIT_OBJ(be, VRT_BACKEND_MAGIC); \
(be)->connect_timeout = -1.0; \
(be)->first_byte_timeout = -1.0; \
(be)->between_bytes_timeout = -1.0; \
} while(0)
#define VRT_BACKEND_HANDLE() \
do { \
DA(vcl_name); \
......
......@@ -32,6 +32,7 @@
#include "config.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
......@@ -381,9 +382,11 @@ vcc_ParseHostDef(struct vcc *tl, struct symbol *sym,
struct inifin *ifp;
struct vsb *vsb1;
struct symbol *via = NULL;
vtim_dur connect_timeout = NAN;
vtim_dur first_byte_timeout = NAN;
vtim_dur between_bytes_timeout = NAN;
char *p;
unsigned u;
double t;
if (tl->t->tok == ID &&
(vcc_IdIs(tl->t, "none") || vcc_IdIs(tl->t, "None"))) {
......@@ -480,21 +483,21 @@ vcc_ParseHostDef(struct vcc *tl, struct symbol *sym,
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "connect_timeout")) {
Fb(tl, 0, "\t.connect_timeout = ");
vcc_Duration(tl, &t);
vcc_Duration(tl, &connect_timeout);
ERRCHK(tl);
Fb(tl, 0, "%g,\n", t);
Fb(tl, 0, "%g,\n", connect_timeout);
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "first_byte_timeout")) {
Fb(tl, 0, "\t.first_byte_timeout = ");
vcc_Duration(tl, &t);
vcc_Duration(tl, &first_byte_timeout);
ERRCHK(tl);
Fb(tl, 0, "%g,\n", t);
Fb(tl, 0, "%g,\n", first_byte_timeout);
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "between_bytes_timeout")) {
Fb(tl, 0, "\t.between_bytes_timeout = ");
vcc_Duration(tl, &t);
vcc_Duration(tl, &between_bytes_timeout);
ERRCHK(tl);
Fb(tl, 0, "%g,\n", t);
Fb(tl, 0, "%g,\n", between_bytes_timeout);
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "max_connections")) {
u = vcc_UintVal(tl);
......@@ -581,6 +584,13 @@ vcc_ParseHostDef(struct vcc *tl, struct symbol *sym,
free(fs);
ERRCHK(tl);
if (isnan(connect_timeout))
Fb(tl, 0, "\t.connect_timeout = -1.0,\n");
if (isnan(first_byte_timeout))
Fb(tl, 0, "\t.first_byte_timeout = -1.0,\n");
if (isnan(between_bytes_timeout))
Fb(tl, 0, "\t.between_bytes_timeout = -1.0,\n");
ExpectErr(tl, '}');
if (t_host == NULL && t_path == NULL) {
......
......@@ -75,7 +75,7 @@ dyn_dir_init(VRT_CTX, struct xyzzy_debug_dyn *dyn,
CHECK_OBJ_ORNULL(via, DIRECTOR_MAGIC);
INIT_OBJ(&vep, VRT_ENDPOINT_MAGIC);
INIT_OBJ(&vrt, VRT_BACKEND_MAGIC);
VRT_BACKEND_INIT(&vrt);
vrt.endpoint = &vep;
vrt.vcl_name = dyn->vcl_name;
vrt.hosthdr = addr;
......@@ -206,7 +206,7 @@ dyn_uds_init(VRT_CTX, struct xyzzy_debug_dyn_uds *uds, VCL_STRING path)
}
INIT_OBJ(&vep, VRT_ENDPOINT_MAGIC);
INIT_OBJ(&vrt, VRT_BACKEND_MAGIC);
VRT_BACKEND_INIT(&vrt);
vrt.endpoint = &vep;
vep.uds_path = path;
vrt.vcl_name = uds->vcl_name;
......
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