From 2fe4636fa44ad48b801d0e38b892c0e47998327d Mon Sep 17 00:00:00 2001 From: brain Date: Mon, 8 Jan 2007 18:42:13 +0000 Subject: Add repeating timers, and make an hourly prune of the dns cache, otherwise a cache entry might not be cleared until a user with that ip comes back! git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6264 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/dns.h | 3 +++ include/timer.h | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/dns.h b/include/dns.h index 8011d069c..562a49322 100644 --- a/include/dns.h +++ b/include/dns.h @@ -326,6 +326,8 @@ class DNS : public EventHandler */ dnscache* cache; + class CacheTimer* PruneTimer; + /** * Build a dns packet payload */ @@ -450,6 +452,7 @@ class DNS : public EventHandler void DelCache(const std::string &source); int ClearCache(); + int PruneCache(); }; #endif diff --git a/include/timer.h b/include/timer.h index da8e742d9..f8e2bdcdf 100644 --- a/include/timer.h +++ b/include/timer.h @@ -30,12 +30,19 @@ class InspTimer : public Extensible /** The triggering time */ time_t trigger; + long secs; + bool repeat; public: /** Default constructor, initializes the triggering time + * @param secs_from_now The number of seconds from now to trigger the timer + * @param now The time now + * @param repeating Repeat this timer every secs_from_now seconds if set to true */ - InspTimer(long secs_from_now,time_t now) + InspTimer(long secs_from_now,time_t now, bool repeating = false) { trigger = now + secs_from_now; + secs = secs_from_now; + repeat = repeating; } /** Default destructor, does nothing. */ @@ -49,6 +56,16 @@ class InspTimer : public Extensible /** Called when the timer ticks. */ virtual void Tick(time_t TIME) = 0; + + bool GetRepeat() + { + return repeat; + } + + long GetSecs() + { + return secs; + } }; @@ -79,8 +96,13 @@ class TimerManager : public Extensible void TickTimers(time_t TIME); /** Add an InspTimer * @param T an InspTimer derived class to add + * @param secs_from_now You may set this to the number of seconds + * from the current time when the timer will tick, or you may just + * leave this unset and the values set by the InspTimers constructor + * will be used. This is used internally for re-triggering repeating + * timers. */ - void AddTimer(InspTimer* T); + void AddTimer(InspTimer* T, long secs_from_now = 0); /** Delete an InspTimer * @param T an InspTimer derived class to delete */ -- cgit v1.2.3