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 --- src/timer.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/timer.cpp') diff --git a/src/timer.cpp b/src/timer.cpp index 04ff1c15b..6be7aa06c 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -28,7 +28,14 @@ void TimerManager::TickTimers(time_t TIME) { InspTimer* n = *y; n->Tick(TIME); - DELETE(n); + if (n->GetRepeat()) + { + AddTimer(n, n->GetSecs()); + } + else + { + DELETE(n); + } } Timers.erase(found); @@ -78,7 +85,14 @@ void TimerManager::TickMissedTimers(time_t TIME) { InspTimer* z = *y; z->Tick(TIME); - DELETE(z); + if (z->GetRepeat()) + { + AddTimer(z, z->GetSecs()); + } + else + { + DELETE(z); + } } Timers.erase(found); @@ -87,12 +101,18 @@ void TimerManager::TickMissedTimers(time_t TIME) } } -void TimerManager::AddTimer(InspTimer* T) +void TimerManager::AddTimer(InspTimer* T, long secs_from_now) { timergroup* x = NULL; - timerlist::iterator found = Timers.find(T->GetTimer()); - + int time_to_trigger = 0; + if (!secs_from_now) + time_to_trigger = T->GetTimer(); + else + time_to_trigger = secs_from_now + time(NULL); + + timerlist::iterator found = Timers.find(time_to_trigger); + if (found != Timers.end()) { x = found->second; @@ -100,7 +120,7 @@ void TimerManager::AddTimer(InspTimer* T) else { x = new timergroup; - Timers[T->GetTimer()] = x; + Timers[time_to_trigger] = x; } x->push_back(T); -- cgit v1.2.3