source: filezilla/trunk/fuentes/src/putty/pinger.c @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 1.6 KB
RevLine 
[130]1/*
2 * pinger.c: centralised module that deals with sending TS_PING
3 * keepalives, to avoid replicating this code in multiple backends.
4 */
5
6#include "putty.h"
7
8struct pinger_tag {
9    int interval;
10    int pending;
11    unsigned long next;
12    Backend *back;
13    void *backhandle;
14};
15
16static void pinger_schedule(Pinger pinger);
17
18static void pinger_timer(void *ctx, unsigned long now)
19{
20    Pinger pinger = (Pinger)ctx;
21
22    if (pinger->pending && now == pinger->next) {
23        pinger->back->special(pinger->backhandle, TS_PING);
24        pinger->pending = FALSE;
25        pinger_schedule(pinger);
26    }
27}
28
29static void pinger_schedule(Pinger pinger)
30{
31    int next;
32
33    if (!pinger->interval) {
34        pinger->pending = FALSE;       /* cancel any pending ping */
35        return;
36    }
37
38    next = schedule_timer(pinger->interval * TICKSPERSEC,
39                          pinger_timer, pinger);
40    if (!pinger->pending || next < pinger->next) {
41        pinger->next = next;
42        pinger->pending = TRUE;
43    }
44}
45
46Pinger pinger_new(Conf *conf, Backend *back, void *backhandle)
47{
48    Pinger pinger = snew(struct pinger_tag);
49
50    pinger->interval = conf_get_int(conf, CONF_ping_interval);
51    pinger->pending = FALSE;
52    pinger->back = back;
53    pinger->backhandle = backhandle;
54    pinger_schedule(pinger);
55
56    return pinger;
57}
58
59void pinger_reconfig(Pinger pinger, Conf *oldconf, Conf *newconf)
60{
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);
65    }
66}
67
68void pinger_free(Pinger pinger)
69{
70    expire_timer_context(pinger);
71    sfree(pinger);
72}
Note: See TracBrowser for help on using the repository browser.