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
* delete this request.
*/
void Tick() override
bool Tick() override
{
Log(LOG_DEBUG_2) << "Resolver: timeout for query " << this->name;
Query rr(*this);
rr.error = ERROR_TIMEDOUT;
this->OnError(&rr);
return false;
}
};
+3 -14
View File
@@ -31,23 +31,17 @@ private:
*/
time_t secs;
/** True if this is a repeating timer
*/
bool repeat;
public:
/** Constructor, initializes the triggering time
* @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
* @param creator The creator of 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
*/
@@ -63,11 +57,6 @@ public:
*/
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
* @paramt t The new interval
*/
@@ -86,7 +75,7 @@ public:
/** Called when the timer ticks
* 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.
+3 -2
View File
@@ -1030,11 +1030,11 @@ class BanDataPurger final
{
public:
BanDataPurger(Module *o)
: Timer(o, 300, true)
: Timer(o, 300)
{
}
void Tick() override
bool Tick() override
{
Log(LOG_DEBUG) << "bs_main: Running bandata purger";
@@ -1048,6 +1048,7 @@ public:
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);
if (c)
c->RemoveMode(NULL, "BAN", mask);
return false;
}
};
+4 -2
View File
@@ -82,10 +82,10 @@ public:
/** Called when the delay is up
* @param The current time
*/
void Tick() override
bool Tick() override
{
if (!c)
return;
return false; // Dead channel.
/* In the event we don't part */
c->RemoveMode(NULL, "SECRET");
@@ -101,6 +101,8 @@ public:
/* If someone has rejoined this channel in the meantime, don't part the bot */
else if (c->users.size() <= 1)
c->ci->bi->Part(c);
return false;
}
};
+3 -1
View File
@@ -53,7 +53,7 @@ public:
&& bmask == this->mask;
}
void Tick() override
bool Tick() override
{
// We need to do this to prevent the remove-on-unban logic from double
// deleting the timer.
@@ -62,6 +62,8 @@ public:
Channel *c = Channel::Find(this->channel);
if (c)
c->RemoveMode(NULL, mode, this->mask);
return false;
}
};
+5 -3
View File
@@ -534,8 +534,9 @@ public:
}
/* Times out after a few seconds */
void Tick() override
bool Tick() override
{
return false;
}
void Reply(Packet *p) override
@@ -718,7 +719,7 @@ public:
MyManager(Module *creator)
: Manager(creator)
, Timer(300, true)
, Timer(300)
, serial(Anope::CurTime)
, cur_id(Anope::RandomNumber())
{
@@ -1011,7 +1012,7 @@ public:
return serial;
}
void Tick() override
bool Tick() override
{
Log(LOG_DEBUG_2) << "Resolver: Purging DNS cache";
@@ -1025,6 +1026,7 @@ public:
if (req.created + static_cast<time_t>(req.ttl) < Anope::CurTime)
this->cache.erase(it);
}
return true;
}
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)
: Socket(-1, i.find(':') == Anope::string::npos ? AF_INET : AF_INET6)
, HTTP::Provider(c, n, i, p, s)
, Timer(c, 10, true)
, Timer(c, 10)
, timeout(t)
{
}
void Tick() override
bool Tick() override
{
while (!this->clients.empty())
{
@@ -314,6 +314,7 @@ public:
delete c;
this->clients.pop_front();
}
return true;
}
ClientSocket *OnAccept(int fd, const sockaddrs &addr) override
+8 -5
View File
@@ -61,16 +61,17 @@ public:
return na;
}
void Tick() override
bool Tick() override
{
if (!u || !na || !NickServ::service)
return;
return false;
/* If they identified or don't exist anymore, don't kill them. */
if (u->Account() == na->nc || u->timestamp > ts)
return;
return false;
NickServ::service->Collide(u, na);
return false;
}
};
@@ -90,10 +91,11 @@ public:
n->Extend<bool>("HELD");
}
void Tick() override
bool Tick() override
{
if (na)
na->Shrink<bool>("HELD");
return false;
}
};
@@ -133,8 +135,9 @@ public:
NickServReleases.erase(this->nick);
}
void Tick() override
bool Tick() override
{
return false;
}
};
+3 -2
View File
@@ -29,7 +29,7 @@ public:
SASLService(Module *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));
}
void Tick() override
bool Tick() override
{
for (auto it = badpasswords.begin(); it != badpasswords.end(); )
{
@@ -240,6 +240,7 @@ public:
sessions.erase(uid);
}
}
return true;
}
};
+2 -1
View File
@@ -125,7 +125,7 @@ public:
timeout = NULL;
}
void Tick() override
bool Tick() override
{
if (DConfig.defaultlevel != level)
{
@@ -146,6 +146,7 @@ public:
runDefCon();
}
return false;
}
};
+3 -2
View File
@@ -218,11 +218,11 @@ class ModuleProxyScan final
{
public:
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;)
{
@@ -232,6 +232,7 @@ class ModuleProxyScan final
if (p->created + this->GetSecs() < Anope::CurTime)
delete p;
}
return true;
}
} connectionTimeout;
+6 -4
View File
@@ -50,13 +50,14 @@ class UpdateTimer final
{
public:
UpdateTimer(time_t timeout)
: Timer(timeout, true)
: Timer(timeout)
{
}
void Tick() override
bool Tick() override
{
Anope::SaveDatabases();
return true;
}
};
@@ -65,13 +66,14 @@ class ExpireTimer final
{
public:
ExpireTimer(time_t timeout)
: Timer(timeout, true)
: Timer(timeout)
{
}
void Tick() override
bool Tick() override
{
FOREACH_MOD(OnExpireTick, ());
return true;
}
};
+3 -12
View File
@@ -17,20 +17,18 @@
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))
, secs(time_from_now)
, repeat(repeating)
{
if (time_from_now)
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)
, trigger(Anope::CurTime + std::abs(time_from_now))
, secs(time_from_now)
, repeat(repeating)
{
if (time_from_now)
TimerManager::AddTimer(this);
@@ -53,11 +51,6 @@ time_t Timer::GetTimer() const
return trigger;
}
bool Timer::GetRepeat() const
{
return repeat;
}
void Timer::SetSecs(time_t t)
{
TimerManager::DelTimer(this);
@@ -104,9 +97,7 @@ void TimerManager::TickTimers()
if (t->GetTimer() > Anope::CurTime)
break;
t->Tick();
if (t->GetRepeat())
if (t->Tick())
t->SetTimer(Anope::CurTime + t->GetSecs());
else
delete t;
+2 -1
View File
@@ -29,7 +29,7 @@ public:
{
}
void Tick() override
bool Tick() override
{
try
{
@@ -39,6 +39,7 @@ public:
{
Log(LOG_TERMINAL) << "Unable to connect to uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].str() << "): " << ex.GetReason();
}
return false;
}
};