1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00
putty-source/pinger.c
Simon Tatham 96ec2c2500 Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.

All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.

A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 19:10:23 +01:00

73 lines
1.6 KiB
C

/*
* pinger.c: centralised module that deals with sending SS_PING
* keepalives, to avoid replicating this code in multiple backends.
*/
#include "putty.h"
struct Pinger {
int interval;
int pending;
unsigned long when_set, next;
Backend *backend;
};
static void pinger_schedule(Pinger *pinger);
static void pinger_timer(void *ctx, unsigned long now)
{
Pinger *pinger = (Pinger *)ctx;
if (pinger->pending && now == pinger->next) {
backend_special(pinger->backend, SS_PING, 0);
pinger->pending = FALSE;
pinger_schedule(pinger);
}
}
static void pinger_schedule(Pinger *pinger)
{
unsigned long next;
if (!pinger->interval) {
pinger->pending = FALSE; /* cancel any pending ping */
return;
}
next = schedule_timer(pinger->interval * TICKSPERSEC,
pinger_timer, pinger);
if (!pinger->pending ||
(next - pinger->when_set) < (pinger->next - pinger->when_set)) {
pinger->next = next;
pinger->when_set = timing_last_clock();
pinger->pending = TRUE;
}
}
Pinger *pinger_new(Conf *conf, Backend *backend)
{
Pinger *pinger = snew(Pinger);
pinger->interval = conf_get_int(conf, CONF_ping_interval);
pinger->pending = FALSE;
pinger->backend = backend;
pinger_schedule(pinger);
return pinger;
}
void pinger_reconfig(Pinger *pinger, Conf *oldconf, Conf *newconf)
{
int newinterval = conf_get_int(newconf, CONF_ping_interval);
if (conf_get_int(oldconf, CONF_ping_interval) != newinterval) {
pinger->interval = newinterval;
pinger_schedule(pinger);
}
}
void pinger_free(Pinger *pinger)
{
expire_timer_context(pinger);
sfree(pinger);
}