From 34c81c09549dbb1e2b1c3d643ac84da9989a7739 Mon Sep 17 00:00:00 2001 From: SkelUA Date: Sat, 4 Jan 2025 18:57:41 +0200 Subject: [PATCH] =?UTF-8?q?Revert=20"refactor(Core/Time):=20Introduce=20Ge?= =?UTF-8?q?tExpirationTime=20instead=20of=20calculati=E2=80=A6=20(#21006)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7714ca31a253981d354a452001cca4d3792ab2f5. --- src/common/Asio/SteadyTimer.h | 31 -------------------------- src/common/Metric/Metric.cpp | 9 +++++--- src/server/apps/authserver/Main.cpp | 17 +++++++++----- src/server/apps/worldserver/Main.cpp | 9 +++++--- src/server/shared/Realms/RealmList.cpp | 7 +++--- 5 files changed, 28 insertions(+), 45 deletions(-) delete mode 100644 src/common/Asio/SteadyTimer.h diff --git a/src/common/Asio/SteadyTimer.h b/src/common/Asio/SteadyTimer.h deleted file mode 100644 index 2c5a6fd7fad5b6..00000000000000 --- a/src/common/Asio/SteadyTimer.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by the - * Free Software Foundation; either version 3 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef _STEADYTIMER_H -#define _STEADYTIMER_H - -#include - -namespace Acore::Asio::SteadyTimer -{ - inline auto GetExpirationTime(int32 seconds) - { - return std::chrono::steady_clock::now() + std::chrono::seconds(seconds); - } -} - -#endif // _STEADYTIMER_H diff --git a/src/common/Metric/Metric.cpp b/src/common/Metric/Metric.cpp index 7c4771dcad2db5..a6cd4b1f276ea8 100644 --- a/src/common/Metric/Metric.cpp +++ b/src/common/Metric/Metric.cpp @@ -18,7 +18,6 @@ #include "Metric.h" #include "Config.h" #include "Log.h" -#include "SteadyTimer.h" #include "Strand.h" #include "Tokenize.h" #include @@ -247,7 +246,9 @@ void Metric::ScheduleSend() { if (_enabled) { - _batchTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(_updateInterval)); + // Calculate the expiration time + auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(_updateInterval); + _batchTimer->expires_at(expirationTime); _batchTimer->async_wait(std::bind(&Metric::SendBatch, this)); } else @@ -280,7 +281,9 @@ void Metric::ScheduleOverallStatusLog() { if (_enabled) { - _overallStatusTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(_overallStatusTimerInterval)); + // Calculate the expiration time _overallStatusTimerInterval from now + auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(_overallStatusTimerInterval); + _overallStatusTimer->expires_at(expirationTime); _overallStatusTimer->async_wait([this](const boost::system::error_code&) { _overallStatusTimerTriggered = true; diff --git a/src/server/apps/authserver/Main.cpp b/src/server/apps/authserver/Main.cpp index 903a12134d0c64..6030d9114220ae 100644 --- a/src/server/apps/authserver/Main.cpp +++ b/src/server/apps/authserver/Main.cpp @@ -38,7 +38,6 @@ #include "RealmList.h" #include "SecretMgr.h" #include "SharedDefines.h" -#include "SteadyTimer.h" #include "Util.h" #include #include @@ -180,13 +179,17 @@ int main(int argc, char** argv) int32 dbPingInterval = sConfigMgr->GetOption("MaxPingTime", 30); std::shared_ptr dbPingTimer = std::make_shared(*ioContext); - dbPingTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(dbPingInterval * MINUTE)); + // Calculate the expiration time + auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(dbPingInterval); + dbPingTimer->expires_at(expirationTime); dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, std::weak_ptr(dbPingTimer), dbPingInterval, std::placeholders::_1)); int32 banExpiryCheckInterval = sConfigMgr->GetOption("BanExpiryCheckInterval", 60); std::shared_ptr banExpiryCheckTimer = std::make_shared(*ioContext); - banExpiryCheckTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(banExpiryCheckInterval)); + // Calculate the expiration time + auto expirationTimeBanExpiry = std::chrono::steady_clock::now() + std::chrono::seconds(banExpiryCheckInterval); + banExpiryCheckTimer->expires_at(expirationTimeBanExpiry); banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, std::weak_ptr(banExpiryCheckTimer), banExpiryCheckInterval, std::placeholders::_1)); // Start the io service worker loop @@ -249,7 +252,9 @@ void KeepDatabaseAliveHandler(std::weak_ptr dbPingTim LOG_INFO("server.authserver", "Ping MySQL to keep connection alive"); LoginDatabase.KeepAlive(); - dbPingTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(dbPingInterval)); + // Calculate the expiration time + auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(dbPingInterval); + dbPingTimer->expires_at(expirationTime); dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, dbPingTimerRef, dbPingInterval, std::placeholders::_1)); } } @@ -264,7 +269,9 @@ void BanExpiryHandler(std::weak_ptr banExpiryCheckTim LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS)); LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS)); - banExpiryCheckTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(banExpiryCheckInterval)); + // Calculate the expiration time + auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(banExpiryCheckInterval); + banExpiryCheckTimer->expires_at(expirationTime); banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, banExpiryCheckTimerRef, banExpiryCheckInterval, std::placeholders::_1)); } } diff --git a/src/server/apps/worldserver/Main.cpp b/src/server/apps/worldserver/Main.cpp index 0f5a96208500a4..e95aadc7babfd9 100644 --- a/src/server/apps/worldserver/Main.cpp +++ b/src/server/apps/worldserver/Main.cpp @@ -47,7 +47,6 @@ #include "ScriptMgr.h" #include "SecretMgr.h" #include "SharedDefines.h" -#include "SteadyTimer.h" #include "World.h" #include "WorldSocket.h" #include "WorldSocketMgr.h" @@ -91,7 +90,9 @@ class FreezeDetector static void Start(std::shared_ptr const& freezeDetector) { - freezeDetector->_timer.expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(5)); + // Calculate the expiration time 5seconds from now + auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(5); + freezeDetector->_timer.expires_at(expirationTime); freezeDetector->_timer.async_wait(std::bind(&FreezeDetector::Handler, std::weak_ptr(freezeDetector), std::placeholders::_1)); } @@ -631,7 +632,9 @@ void FreezeDetector::Handler(std::weak_ptr freezeDetectorRef, bo } } - freezeDetector->_timer.expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(1)); + // Calculate the expiration time + auto expirationTime = std::chrono::steady_clock::now() + std::chrono::seconds(1); + freezeDetector->_timer.expires_at(expirationTime); freezeDetector->_timer.async_wait(std::bind(&FreezeDetector::Handler, freezeDetectorRef, std::placeholders::_1)); } } diff --git a/src/server/shared/Realms/RealmList.cpp b/src/server/shared/Realms/RealmList.cpp index b3b3f7656b1215..a1c258edd3d3e1 100644 --- a/src/server/shared/Realms/RealmList.cpp +++ b/src/server/shared/Realms/RealmList.cpp @@ -18,9 +18,8 @@ #include "RealmList.h" #include "DatabaseEnv.h" #include "Log.h" -#include "QueryResult.h" #include "Resolver.h" -#include "SteadyTimer.h" +#include "QueryResult.h" #include "Util.h" #include #include @@ -228,7 +227,9 @@ void RealmList::UpdateRealms(boost::system::error_code const& error) if (_updateInterval) { - _updateTimer->expires_at(Acore::Asio::SteadyTimer::GetExpirationTime(_updateInterval)); + // Calculate the expiration time _updateInterval from now + auto expiration_time = std::chrono::steady_clock::now() + std::chrono::seconds(_updateInterval); + _updateTimer->expires_at(expiration_time); _updateTimer->async_wait([this](boost::system::error_code const& errorCode){ UpdateRealms(errorCode); }); } }