Unverified Commit 32ae0413 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune Committed by Nils Goroll

vca: Generalize the sock options test

Using the tmp sock_arg for storage, we can test all values with the same
logic and only differentiate hard-coded options from parameterized ones.

Stylistic polish by @mbgrydeland.

Conflicts:
	bin/varnishd/cache/cache_acceptor.c
parent 763cc6ef
...@@ -158,62 +158,59 @@ vca_periodic(vtim_real t0) ...@@ -158,62 +158,59 @@ vca_periodic(vtim_real t0)
static int static int
vca_sock_opt_init(void) vca_sock_opt_init(void)
{ {
int n;
int one = 1;
struct sock_opt *so; struct sock_opt *so;
union sock_arg tmp; union sock_arg tmp;
int chg = 0; int n, chg = 0;
size_t sz;
memset(&tmp, 0, sizeof tmp); memset(&tmp, 0, sizeof tmp);
for (n = 0; n < n_sock_opts; n++) { for (n = 0; n < n_sock_opts; n++) {
so = &sock_opts[n]; so = &sock_opts[n];
if (!strcmp(so->strname, "SO_LINGER")) {
assert(so->sz == sizeof linger); #define SET_VAL(nm, so, fld, val) \
memcpy(so->arg, &linger, sizeof linger); do { \
so->need = 1; if (!strcmp(#nm, so->strname)) { \
} else if (!strcmp(so->strname, "TCP_NODELAY")) { assert(so->sz == sizeof so->arg->fld); \
assert(so->sz == sizeof one); so->arg->fld = (val); \
memcpy(so->arg, &one, sizeof one); } \
so->need = 1; } while (0)
} else if (!strcmp(so->strname, "SO_KEEPALIVE")) {
assert(so->sz == sizeof one); #define NEW_VAL(nm, so, fld, val) \
memcpy(so->arg, &one, sizeof one);
so->need = 1;
#define NEW_VAL(so, xx) \
do { \ do { \
assert(so->sz == sizeof xx); \ if (!strcmp(#nm, so->strname)) { \
if (memcmp(so->arg, &(xx), sizeof xx)) { \ sz = sizeof tmp.fld; \
memcpy(so->arg, &(xx), sizeof xx); \ assert(so->sz == sz); \
tmp.fld = (val); \
if (memcmp(&so->arg->fld, &(tmp.fld), sz)) { \
memcpy(&so->arg->fld, &(tmp.fld), sz); \
so->need = 1; \ so->need = 1; \
chg = 1; \ chg = 1; \
need_test = 1; \ need_test = 1; \
} \ } \
} \
} while (0) } while (0)
SET_VAL(SO_LINGER, so, lg, linger);
SET_VAL(SO_KEEPALIVE, so, i, 1);
#ifdef SO_SNDTIMEO_WORKS #ifdef SO_SNDTIMEO_WORKS
} else if (!strcmp(so->strname, "SO_SNDTIMEO")) { NEW_VAL(SO_SNDTIMEO, so, tv,
tmp.tv = VTIM_timeval(cache_param->idle_send_timeout); VTIM_timeval(cache_param->idle_send_timeout));
NEW_VAL(so, tmp.tv);
#endif #endif
#ifdef SO_RCVTIMEO_WORKS #ifdef SO_RCVTIMEO_WORKS
} else if (!strcmp(so->strname, "SO_RCVTIMEO")) { NEW_VAL(SO_RCVTIMEO, so, tv,
tmp.tv = VTIM_timeval(cache_param->timeout_idle); VTIM_timeval(cache_param->timeout_idle));
NEW_VAL(so, tmp.tv);
#endif #endif
#ifdef HAVE_TCP_KEEP #ifdef HAVE_TCP_KEEP
} else if (!strcmp(so->strname, "TCP_KEEPIDLE")) { SET_VAL(TCP_NODELAY, so, i, 1);
tmp.i = (int)(cache_param->tcp_keepalive_time); NEW_VAL(TCP_KEEPIDLE, so, i,
NEW_VAL(so, tmp.i); (int)cache_param->tcp_keepalive_time);
} else if (!strcmp(so->strname, "TCP_KEEPCNT")) { NEW_VAL(TCP_KEEPCNT, so, i,
tmp.i = (int)(cache_param->tcp_keepalive_probes); (int)cache_param->tcp_keepalive_probes);
NEW_VAL(so, tmp.i); NEW_VAL(TCP_KEEPINTVL, so, i,
} else if (!strcmp(so->strname, "TCP_KEEPINTVL")) { (int)cache_param->tcp_keepalive_intvl);
tmp.i = (int)(cache_param->tcp_keepalive_intvl);
NEW_VAL(so, tmp.i);
#endif #endif
} }
}
return (chg); return (chg);
} }
......
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