Commit 789186e9 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune Committed by Martin Blix Grydeland

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.
parent 57c21d9f
...@@ -156,57 +156,54 @@ vca_periodic(vtim_real t0) ...@@ -156,57 +156,54 @@ 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); do { \
so->need = 1; if (!strcmp(#nm, so->strname)) { \
#define NEW_VAL(so, xx) \ sz = sizeof tmp.fld; \
do { \ assert(so->sz == sz); \
assert(so->sz == sizeof xx); \ tmp.fld = (val); \
if (memcmp(so->arg, &(xx), sizeof xx)) { \ if (memcmp(&so->arg->fld, &(tmp.fld), sz)) { \
memcpy(so->arg, &(xx), sizeof xx); \ 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)
} else if (!strcmp(so->strname, "SO_SNDTIMEO")) { SET_VAL(SO_LINGER, so, lg, linger);
tmp.tv = VTIM_timeval(cache_param->idle_send_timeout); SET_VAL(SO_KEEPALIVE, so, i, 1);
NEW_VAL(so, tmp.tv); NEW_VAL(SO_SNDTIMEO, so, tv,
} else if (!strcmp(so->strname, "SO_RCVTIMEO")) { VTIM_timeval(cache_param->idle_send_timeout));
tmp.tv = VTIM_timeval(cache_param->timeout_idle); NEW_VAL(SO_RCVTIMEO, so, tv,
NEW_VAL(so, tmp.tv); VTIM_timeval(cache_param->timeout_idle));
#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