diff options
author | Shauren <shauren.trinity@gmail.com> | 2024-12-09 21:13:18 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2025-02-18 15:39:41 +0100 |
commit | 1942647c0d0229aca96602f3617365bd477e94de (patch) | |
tree | 7be0db654c17f227d5db3870b455c7bf0a13cb54 /src | |
parent | 8785c0d5a5bf1967ee1469fdaf0d024dd22f0f0d (diff) |
Dep: Replace basic_deadline_timer with std::chrono based basic_waitable_timer
(cherry picked from commit c81183a6600722f3a9bb4996c0849b530fbdd1b0)
Diffstat (limited to 'src')
-rw-r--r-- | src/common/Asio/DeadlineTimer.h | 19 | ||||
-rw-r--r-- | src/common/Metric/Metric.cpp | 4 | ||||
-rw-r--r-- | src/server/authserver/Main.cpp | 12 | ||||
-rw-r--r-- | src/server/shared/Networking/NetworkThread.h | 4 | ||||
-rw-r--r-- | src/server/shared/Realm/RealmList.cpp | 2 | ||||
-rw-r--r-- | src/server/worldserver/Main.cpp | 34 |
6 files changed, 37 insertions, 38 deletions
diff --git a/src/common/Asio/DeadlineTimer.h b/src/common/Asio/DeadlineTimer.h index 94531a28511..c1b2306b257 100644 --- a/src/common/Asio/DeadlineTimer.h +++ b/src/common/Asio/DeadlineTimer.h @@ -18,18 +18,17 @@ #ifndef DeadlineTimer_h__ #define DeadlineTimer_h__ -#include <boost/asio/deadline_timer.hpp> +#include "Duration.h" +#include <boost/asio/basic_waitable_timer.hpp> +#include <boost/asio/io_context.hpp> -namespace Trinity +namespace Trinity::Asio { - namespace Asio - { - class DeadlineTimer : public boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::io_context::executor_type> - { - public: - using basic_deadline_timer::basic_deadline_timer; - }; - } +class DeadlineTimer : public boost::asio::basic_waitable_timer<std::chrono::steady_clock, boost::asio::wait_traits<std::chrono::steady_clock>, boost::asio::io_context::executor_type> +{ +public: + using basic_waitable_timer::basic_waitable_timer; +}; } #endif // DeadlineTimer_h__ diff --git a/src/common/Metric/Metric.cpp b/src/common/Metric/Metric.cpp index 06c084a3c2c..08dff35eb98 100644 --- a/src/common/Metric/Metric.cpp +++ b/src/common/Metric/Metric.cpp @@ -220,7 +220,7 @@ void Metric::ScheduleSend() { if (_enabled) { - _batchTimer->expires_from_now(boost::posix_time::seconds(_updateInterval)); + _batchTimer->expires_after(std::chrono::seconds(_updateInterval)); _batchTimer->async_wait(std::bind(&Metric::SendBatch, this)); } else @@ -250,7 +250,7 @@ void Metric::ScheduleOverallStatusLog() { if (_enabled) { - _overallStatusTimer->expires_from_now(boost::posix_time::seconds(_overallStatusTimerInterval)); + _overallStatusTimer->expires_after(std::chrono::seconds(_overallStatusTimerInterval)); _overallStatusTimer->async_wait([this](const boost::system::error_code&) { _overallStatusTimerTriggered = true; diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp index d58c7a0c0c0..b82727c9338 100644 --- a/src/server/authserver/Main.cpp +++ b/src/server/authserver/Main.cpp @@ -229,12 +229,12 @@ int main(int argc, char** argv) // Enabled a timed callback for handling the database keep alive ping int32 dbPingInterval = sConfigMgr->GetIntDefault("MaxPingTime", 30); std::shared_ptr<Trinity::Asio::DeadlineTimer> dbPingTimer = std::make_shared<Trinity::Asio::DeadlineTimer>(*ioContext); - dbPingTimer->expires_from_now(boost::posix_time::minutes(dbPingInterval)); + dbPingTimer->expires_after(std::chrono::minutes(dbPingInterval)); dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, std::weak_ptr<Trinity::Asio::DeadlineTimer>(dbPingTimer), dbPingInterval, std::placeholders::_1)); int32 banExpiryCheckInterval = sConfigMgr->GetIntDefault("BanExpiryCheckInterval", 60); std::shared_ptr<Trinity::Asio::DeadlineTimer> banExpiryCheckTimer = std::make_shared<Trinity::Asio::DeadlineTimer>(*ioContext); - banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(banExpiryCheckInterval)); + banExpiryCheckTimer->expires_after(std::chrono::seconds(banExpiryCheckInterval)); banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, std::weak_ptr<Trinity::Asio::DeadlineTimer>(banExpiryCheckTimer), banExpiryCheckInterval, std::placeholders::_1)); #if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS @@ -242,7 +242,7 @@ int main(int argc, char** argv) if (m_ServiceStatus != -1) { serviceStatusWatchTimer = std::make_shared<Trinity::Asio::DeadlineTimer>(*ioContext); - serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1)); + serviceStatusWatchTimer->expires_after(1s); serviceStatusWatchTimer->async_wait(std::bind(&ServiceStatusWatcher, std::weak_ptr<Trinity::Asio::DeadlineTimer>(serviceStatusWatchTimer), std::weak_ptr<Trinity::Asio::IoContext>(ioContext), @@ -306,7 +306,7 @@ void KeepDatabaseAliveHandler(std::weak_ptr<Trinity::Asio::DeadlineTimer> dbPing TC_LOG_INFO("server.authserver", "Ping MySQL to keep connection alive"); LoginDatabase.KeepAlive(); - dbPingTimer->expires_from_now(boost::posix_time::minutes(dbPingInterval)); + dbPingTimer->expires_after(std::chrono::minutes(dbPingInterval)); dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, dbPingTimerRef, dbPingInterval, std::placeholders::_1)); } } @@ -321,7 +321,7 @@ void BanExpiryHandler(std::weak_ptr<Trinity::Asio::DeadlineTimer> banExpiryCheck LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS)); LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS)); - banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(banExpiryCheckInterval)); + banExpiryCheckTimer->expires_after(std::chrono::seconds(banExpiryCheckInterval)); banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, banExpiryCheckTimerRef, banExpiryCheckInterval, std::placeholders::_1)); } } @@ -338,7 +338,7 @@ void ServiceStatusWatcher(std::weak_ptr<Trinity::Asio::DeadlineTimer> serviceSta ioContext->stop(); else if (std::shared_ptr<Trinity::Asio::DeadlineTimer> serviceStatusWatchTimer = serviceStatusWatchTimerRef.lock()) { - serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1)); + serviceStatusWatchTimer->expires_after(1s); serviceStatusWatchTimer->async_wait(std::bind(&ServiceStatusWatcher, serviceStatusWatchTimerRef, ioContextRef, std::placeholders::_1)); } } diff --git a/src/server/shared/Networking/NetworkThread.h b/src/server/shared/Networking/NetworkThread.h index 5f9071af656..e149867c962 100644 --- a/src/server/shared/Networking/NetworkThread.h +++ b/src/server/shared/Networking/NetworkThread.h @@ -122,7 +122,7 @@ protected: { TC_LOG_DEBUG("misc", "Network Thread Starting"); - _updateTimer.expires_from_now(boost::posix_time::milliseconds(1)); + _updateTimer.expires_after(1ms); _updateTimer.async_wait([this](boost::system::error_code const&) { Update(); }); _ioContext.run(); @@ -136,7 +136,7 @@ protected: if (_stopped) return; - _updateTimer.expires_from_now(boost::posix_time::milliseconds(1)); + _updateTimer.expires_after(1ms); _updateTimer.async_wait([this](boost::system::error_code const&) { Update(); }); AddNewSockets(); diff --git a/src/server/shared/Realm/RealmList.cpp b/src/server/shared/Realm/RealmList.cpp index f68623c5a5d..b525707cf4d 100644 --- a/src/server/shared/Realm/RealmList.cpp +++ b/src/server/shared/Realm/RealmList.cpp @@ -167,7 +167,7 @@ void RealmList::UpdateRealms(boost::system::error_code const& error) if (_updateInterval) { - _updateTimer->expires_from_now(boost::posix_time::seconds(_updateInterval)); + _updateTimer->expires_after(std::chrono::seconds(_updateInterval)); _updateTimer->async_wait(std::bind(&RealmList::UpdateRealms, this, std::placeholders::_1)); } } diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 70426698405..63145380745 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -93,26 +93,26 @@ int m_ServiceStatus = -1; class FreezeDetector { - public: +public: FreezeDetector(Trinity::Asio::IoContext& ioContext, uint32 maxCoreStuckTime) : _timer(ioContext), _worldLoopCounter(0), _lastChangeMsTime(getMSTime()), _maxCoreStuckTimeInMs(maxCoreStuckTime) { } - static void Start(std::shared_ptr<FreezeDetector> const& freezeDetector) + static void Start(std::shared_ptr<FreezeDetector> const& freezeDetector) + { + freezeDetector->_timer.expires_after(5s); + freezeDetector->_timer.async_wait([freezeDetectorRef = std::weak_ptr(freezeDetector)](boost::system::error_code const& error) mutable { - freezeDetector->_timer.expires_from_now(boost::posix_time::seconds(5)); - freezeDetector->_timer.async_wait([freezeDetectorRef = std::weak_ptr<FreezeDetector>(freezeDetector)](boost::system::error_code const& error) - { - return Handler(freezeDetectorRef, error); - }); - } + Handler(std::move(freezeDetectorRef), error); + }); + } - static void Handler(std::weak_ptr<FreezeDetector> freezeDetectorRef, boost::system::error_code const& error); + static void Handler(std::weak_ptr<FreezeDetector> freezeDetectorRef, boost::system::error_code const& error); - private: - Trinity::Asio::DeadlineTimer _timer; - uint32 _worldLoopCounter; - uint32 _lastChangeMsTime; - uint32 _maxCoreStuckTimeInMs; +private: + Trinity::Asio::DeadlineTimer _timer; + uint32 _worldLoopCounter; + uint32 _lastChangeMsTime; + uint32 _maxCoreStuckTimeInMs; }; void SignalHandler(boost::system::error_code const& error, int signalNumber); @@ -574,10 +574,10 @@ void FreezeDetector::Handler(std::weak_ptr<FreezeDetector> freezeDetectorRef, bo } } - freezeDetector->_timer.expires_from_now(boost::posix_time::seconds(1)); - freezeDetector->_timer.async_wait([freezeDetectorRef](boost::system::error_code const& timerError) + freezeDetector->_timer.expires_after(1s); + freezeDetector->_timer.async_wait([freezeDetectorRef = std::move(freezeDetectorRef)](boost::system::error_code const& error) mutable { - return Handler(freezeDetectorRef, timerError); + Handler(std::move(freezeDetectorRef), error); }); } } |