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