1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 17:24:49 +02:00

Change Timer::Tick to return bool, get rid of the repeating field.

This commit is contained in:
Sadie Powell
2026-05-02 14:34:17 +01:00
parent c0bafe10b4
commit f12b590a6d
15 changed files with 52 additions and 53 deletions
+2 -1
View File
@@ -194,12 +194,13 @@ namespace DNS
/** Used to time out the query, xalls OnError and lets the TimerManager /** Used to time out the query, xalls OnError and lets the TimerManager
* delete this request. * delete this request.
*/ */
void Tick() override bool Tick() override
{ {
Log(LOG_DEBUG_2) << "Resolver: timeout for query " << this->name; Log(LOG_DEBUG_2) << "Resolver: timeout for query " << this->name;
Query rr(*this); Query rr(*this);
rr.error = ERROR_TIMEDOUT; rr.error = ERROR_TIMEDOUT;
this->OnError(&rr); this->OnError(&rr);
return false;
} }
}; };
+3 -14
View File
@@ -31,23 +31,17 @@ private:
*/ */
time_t secs; time_t secs;
/** True if this is a repeating timer
*/
bool repeat;
public: public:
/** Constructor, initializes the triggering time /** Constructor, initializes the triggering time
* @param time_from_now The number of seconds from now to trigger the timer * @param time_from_now The number of seconds from now to trigger the timer
* @param repeating Repeat this timer every time_from_now if this is true
*/ */
Timer(time_t time_from_now, bool repeating = false); Timer(time_t time_from_now);
/** Constructor, initializes the triggering time /** Constructor, initializes the triggering time
* @param creator The creator of the timer * @param creator The creator of the timer
* @param time_from_now The number of seconds from now to trigger the timer * @param time_from_now The number of seconds from now to trigger the timer
* @param repeating Repeat this timer every time_from_now if this is true
*/ */
Timer(Module *creator, time_t time_from_now, bool repeating = false); Timer(Module *creator, time_t time_from_now);
/** Destructor, removes the timer from the list /** Destructor, removes the timer from the list
*/ */
@@ -63,11 +57,6 @@ public:
*/ */
time_t GetTimer() const; time_t GetTimer() const;
/** Returns true if the timer is set to repeat
* @return Returns true if the timer is set to repeat
*/
bool GetRepeat() const;
/** Set the interval between ticks /** Set the interval between ticks
* @paramt t The new interval * @paramt t The new interval
*/ */
@@ -86,7 +75,7 @@ public:
/** Called when the timer ticks /** Called when the timer ticks
* This should be overridden with something useful * This should be overridden with something useful
*/ */
virtual void Tick() = 0; virtual bool Tick() = 0;
}; };
/** This class manages sets of Timers, and triggers them at their defined times. /** This class manages sets of Timers, and triggers them at their defined times.
+3 -2
View File
@@ -1030,11 +1030,11 @@ class BanDataPurger final
{ {
public: public:
BanDataPurger(Module *o) BanDataPurger(Module *o)
: Timer(o, 300, true) : Timer(o, 300)
{ {
} }
void Tick() override bool Tick() override
{ {
Log(LOG_DEBUG) << "bs_main: Running bandata purger"; Log(LOG_DEBUG) << "bs_main: Running bandata purger";
@@ -1048,6 +1048,7 @@ public:
c->Shrink<BanData>("bandata"); c->Shrink<BanData>("bandata");
} }
} }
return true;
} }
}; };
+2 -1
View File
@@ -92,11 +92,12 @@ public:
{ {
} }
void Tick() override bool Tick() override
{ {
Channel *c = Channel::Find(chname); Channel *c = Channel::Find(chname);
if (c) if (c)
c->RemoveMode(NULL, "BAN", mask); c->RemoveMode(NULL, "BAN", mask);
return false;
} }
}; };
+4 -2
View File
@@ -82,10 +82,10 @@ public:
/** Called when the delay is up /** Called when the delay is up
* @param The current time * @param The current time
*/ */
void Tick() override bool Tick() override
{ {
if (!c) if (!c)
return; return false; // Dead channel.
/* In the event we don't part */ /* In the event we don't part */
c->RemoveMode(NULL, "SECRET"); c->RemoveMode(NULL, "SECRET");
@@ -101,6 +101,8 @@ public:
/* If someone has rejoined this channel in the meantime, don't part the bot */ /* If someone has rejoined this channel in the meantime, don't part the bot */
else if (c->users.size() <= 1) else if (c->users.size() <= 1)
c->ci->bi->Part(c); c->ci->bi->Part(c);
return false;
} }
}; };
+3 -1
View File
@@ -53,7 +53,7 @@ public:
&& bmask == this->mask; && bmask == this->mask;
} }
void Tick() override bool Tick() override
{ {
// We need to do this to prevent the remove-on-unban logic from double // We need to do this to prevent the remove-on-unban logic from double
// deleting the timer. // deleting the timer.
@@ -62,6 +62,8 @@ public:
Channel *c = Channel::Find(this->channel); Channel *c = Channel::Find(this->channel);
if (c) if (c)
c->RemoveMode(NULL, mode, this->mask); c->RemoveMode(NULL, mode, this->mask);
return false;
} }
}; };
+5 -3
View File
@@ -534,8 +534,9 @@ public:
} }
/* Times out after a few seconds */ /* Times out after a few seconds */
void Tick() override bool Tick() override
{ {
return false;
} }
void Reply(Packet *p) override void Reply(Packet *p) override
@@ -718,7 +719,7 @@ public:
MyManager(Module *creator) MyManager(Module *creator)
: Manager(creator) : Manager(creator)
, Timer(300, true) , Timer(300)
, serial(Anope::CurTime) , serial(Anope::CurTime)
, cur_id(Anope::RandomNumber()) , cur_id(Anope::RandomNumber())
{ {
@@ -1011,7 +1012,7 @@ public:
return serial; return serial;
} }
void Tick() override bool Tick() override
{ {
Log(LOG_DEBUG_2) << "Resolver: Purging DNS cache"; Log(LOG_DEBUG_2) << "Resolver: Purging DNS cache";
@@ -1025,6 +1026,7 @@ public:
if (req.created + static_cast<time_t>(req.ttl) < Anope::CurTime) if (req.created + static_cast<time_t>(req.ttl) < Anope::CurTime)
this->cache.erase(it); this->cache.erase(it);
} }
return true;
} }
private: private:
+3 -2
View File
@@ -298,12 +298,12 @@ public:
MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t, bool s) MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t, bool s)
: Socket(-1, i.find(':') == Anope::string::npos ? AF_INET : AF_INET6) : Socket(-1, i.find(':') == Anope::string::npos ? AF_INET : AF_INET6)
, HTTP::Provider(c, n, i, p, s) , HTTP::Provider(c, n, i, p, s)
, Timer(c, 10, true) , Timer(c, 10)
, timeout(t) , timeout(t)
{ {
} }
void Tick() override bool Tick() override
{ {
while (!this->clients.empty()) while (!this->clients.empty())
{ {
@@ -314,6 +314,7 @@ public:
delete c; delete c;
this->clients.pop_front(); this->clients.pop_front();
} }
return true;
} }
ClientSocket *OnAccept(int fd, const sockaddrs &addr) override ClientSocket *OnAccept(int fd, const sockaddrs &addr) override
+8 -5
View File
@@ -61,16 +61,17 @@ public:
return na; return na;
} }
void Tick() override bool Tick() override
{ {
if (!u || !na || !NickServ::service) if (!u || !na || !NickServ::service)
return; return false;
/* If they identified or don't exist anymore, don't kill them. */ /* If they identified or don't exist anymore, don't kill them. */
if (u->Account() == na->nc || u->timestamp > ts) if (u->Account() == na->nc || u->timestamp > ts)
return; return false;
NickServ::service->Collide(u, na); NickServ::service->Collide(u, na);
return false;
} }
}; };
@@ -90,10 +91,11 @@ public:
n->Extend<bool>("HELD"); n->Extend<bool>("HELD");
} }
void Tick() override bool Tick() override
{ {
if (na) if (na)
na->Shrink<bool>("HELD"); na->Shrink<bool>("HELD");
return false;
} }
}; };
@@ -133,8 +135,9 @@ public:
NickServReleases.erase(this->nick); NickServReleases.erase(this->nick);
} }
void Tick() override bool Tick() override
{ {
return false;
} }
}; };
+3 -2
View File
@@ -29,7 +29,7 @@ public:
SASLService(Module *o) SASLService(Module *o)
: SASL::Service(o) : SASL::Service(o)
, Timer(o, 60, true) , Timer(o, 60)
{ {
} }
@@ -221,7 +221,7 @@ public:
this->SendMessage(session, "M", buf.empty() ? "" : buf.substr(1)); this->SendMessage(session, "M", buf.empty() ? "" : buf.substr(1));
} }
void Tick() override bool Tick() override
{ {
for (auto it = badpasswords.begin(); it != badpasswords.end(); ) for (auto it = badpasswords.begin(); it != badpasswords.end(); )
{ {
@@ -240,6 +240,7 @@ public:
sessions.erase(uid); sessions.erase(uid);
} }
} }
return true;
} }
}; };
+2 -1
View File
@@ -125,7 +125,7 @@ public:
timeout = NULL; timeout = NULL;
} }
void Tick() override bool Tick() override
{ {
if (DConfig.defaultlevel != level) if (DConfig.defaultlevel != level)
{ {
@@ -146,6 +146,7 @@ public:
runDefCon(); runDefCon();
} }
return false;
} }
}; };
+3 -2
View File
@@ -218,11 +218,11 @@ class ModuleProxyScan final
{ {
public: public:
ConnectionTimeout(Module *c, time_t timeout) ConnectionTimeout(Module *c, time_t timeout)
: Timer(c, timeout, true) : Timer(c, timeout)
{ {
} }
void Tick() override bool Tick() override
{ {
for (auto it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end;) for (auto it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end;)
{ {
@@ -232,6 +232,7 @@ class ModuleProxyScan final
if (p->created + this->GetSecs() < Anope::CurTime) if (p->created + this->GetSecs() < Anope::CurTime)
delete p; delete p;
} }
return true;
} }
} connectionTimeout; } connectionTimeout;
+6 -4
View File
@@ -50,13 +50,14 @@ class UpdateTimer final
{ {
public: public:
UpdateTimer(time_t timeout) UpdateTimer(time_t timeout)
: Timer(timeout, true) : Timer(timeout)
{ {
} }
void Tick() override bool Tick() override
{ {
Anope::SaveDatabases(); Anope::SaveDatabases();
return true;
} }
}; };
@@ -65,13 +66,14 @@ class ExpireTimer final
{ {
public: public:
ExpireTimer(time_t timeout) ExpireTimer(time_t timeout)
: Timer(timeout, true) : Timer(timeout)
{ {
} }
void Tick() override bool Tick() override
{ {
FOREACH_MOD(OnExpireTick, ()); FOREACH_MOD(OnExpireTick, ());
return true;
} }
}; };
+3 -12
View File
@@ -17,20 +17,18 @@
std::multimap<time_t, Timer *> TimerManager::Timers; std::multimap<time_t, Timer *> TimerManager::Timers;
Timer::Timer(time_t time_from_now, bool repeating) Timer::Timer(time_t time_from_now)
: trigger(Anope::CurTime + std::abs(time_from_now)) : trigger(Anope::CurTime + std::abs(time_from_now))
, secs(time_from_now) , secs(time_from_now)
, repeat(repeating)
{ {
if (time_from_now) if (time_from_now)
TimerManager::AddTimer(this); TimerManager::AddTimer(this);
} }
Timer::Timer(Module *creator, time_t time_from_now, bool repeating) Timer::Timer(Module *creator, time_t time_from_now)
: owner(creator) : owner(creator)
, trigger(Anope::CurTime + std::abs(time_from_now)) , trigger(Anope::CurTime + std::abs(time_from_now))
, secs(time_from_now) , secs(time_from_now)
, repeat(repeating)
{ {
if (time_from_now) if (time_from_now)
TimerManager::AddTimer(this); TimerManager::AddTimer(this);
@@ -53,11 +51,6 @@ time_t Timer::GetTimer() const
return trigger; return trigger;
} }
bool Timer::GetRepeat() const
{
return repeat;
}
void Timer::SetSecs(time_t t) void Timer::SetSecs(time_t t)
{ {
TimerManager::DelTimer(this); TimerManager::DelTimer(this);
@@ -104,9 +97,7 @@ void TimerManager::TickTimers()
if (t->GetTimer() > Anope::CurTime) if (t->GetTimer() > Anope::CurTime)
break; break;
t->Tick(); if (t->Tick())
if (t->GetRepeat())
t->SetTimer(Anope::CurTime + t->GetSecs()); t->SetTimer(Anope::CurTime + t->GetSecs());
else else
delete t; delete t;
+2 -1
View File
@@ -29,7 +29,7 @@ public:
{ {
} }
void Tick() override bool Tick() override
{ {
try try
{ {
@@ -39,6 +39,7 @@ public:
{ {
Log(LOG_TERMINAL) << "Unable to connect to uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].str() << "): " << ex.GetReason(); Log(LOG_TERMINAL) << "Unable to connect to uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].str() << "): " << ex.GetReason();
} }
return false;
} }
}; };