2 * pinger.c: centralised module that deals with sending TS_PING
3 * keepalives, to avoid replicating this code in multiple backends.
16 static void pinger_schedule(Pinger pinger
);
18 static void pinger_timer(void *ctx
, long now
)
20 Pinger pinger
= (Pinger
)ctx
;
22 if (pinger
->pending
&& now
- pinger
->next
>= 0) {
23 pinger
->back
->special(pinger
->backhandle
, TS_PING
);
24 pinger
->pending
= FALSE
;
25 pinger_schedule(pinger
);
29 static void pinger_schedule(Pinger pinger
)
33 if (!pinger
->interval
) {
34 pinger
->pending
= FALSE
; /* cancel any pending ping */
38 next
= schedule_timer(pinger
->interval
* TICKSPERSEC
,
39 pinger_timer
, pinger
);
40 if (!pinger
->pending
|| next
< pinger
->next
) {
42 pinger
->pending
= TRUE
;
46 Pinger
pinger_new(Conf
*conf
, Backend
*back
, void *backhandle
)
48 Pinger pinger
= snew(struct pinger_tag
);
50 pinger
->interval
= conf_get_int(conf
, CONF_ping_interval
);
51 pinger
->pending
= FALSE
;
53 pinger
->backhandle
= backhandle
;
54 pinger_schedule(pinger
);
59 void pinger_reconfig(Pinger pinger
, Conf
*oldconf
, Conf
*newconf
)
61 int newinterval
= conf_get_int(newconf
, CONF_ping_interval
);
62 if (conf_get_int(oldconf
, CONF_ping_interval
) != newinterval
) {
63 pinger
->interval
= newinterval
;
64 pinger_schedule(pinger
);
68 void pinger_free(Pinger pinger
)
70 expire_timer_context(pinger
);