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, unsigned long now)
\r
20 Pinger pinger = (Pinger)ctx;
\r
22 if (pinger->pending && now == pinger->next) {
\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(Conf *conf, Backend *back, void *backhandle)
\r
48 Pinger pinger = snew(struct pinger_tag);
\r
50 pinger->interval = conf_get_int(conf, CONF_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, Conf *oldconf, Conf *newconf)
\r
61 int newinterval = conf_get_int(newconf, CONF_ping_interval);
\r
62 if (conf_get_int(oldconf, CONF_ping_interval) != newinterval) {
\r
63 pinger->interval = newinterval;
\r
64 pinger_schedule(pinger);
\r
68 void pinger_free(Pinger pinger)
\r
70 expire_timer_context(pinger);
\r