mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Dep: Replace basic_deadline_timer with std::chrono based basic_waitable_timer
This commit is contained in:
@@ -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__
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "IoContext.h"
|
||||
#include "Optional.h"
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -225,7 +225,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([this](boost::system::error_code const&){ SendBatch(); });
|
||||
}
|
||||
else
|
||||
@@ -255,7 +255,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;
|
||||
|
||||
@@ -260,7 +260,7 @@ 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([timerRef = std::weak_ptr(dbPingTimer), dbPingInterval](boost::system::error_code const& error) mutable
|
||||
{
|
||||
KeepDatabaseAliveHandler(std::move(timerRef), dbPingInterval, error);
|
||||
@@ -268,7 +268,7 @@ int main(int argc, char** argv)
|
||||
|
||||
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([timerRef = std::weak_ptr(banExpiryCheckTimer), banExpiryCheckInterval](boost::system::error_code const& error) mutable
|
||||
{
|
||||
BanExpiryHandler(std::move(timerRef), banExpiryCheckInterval, error);
|
||||
@@ -279,7 +279,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([timerRef = std::weak_ptr(serviceStatusWatchTimer), ioContextRef = std::weak_ptr(ioContext)](boost::system::error_code const& error) mutable
|
||||
{
|
||||
ServiceStatusWatcher(std::move(timerRef), std::move(ioContextRef), error);
|
||||
@@ -341,7 +341,7 @@ void KeepDatabaseAliveHandler(std::weak_ptr<Trinity::Asio::DeadlineTimer> dbPing
|
||||
TC_LOG_INFO("server.bnetserver", "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([timerRef = std::move(dbPingTimerRef), dbPingInterval](boost::system::error_code const& error) mutable
|
||||
{
|
||||
KeepDatabaseAliveHandler(std::move(timerRef), dbPingInterval, error);
|
||||
@@ -360,7 +360,7 @@ void BanExpiryHandler(std::weak_ptr<Trinity::Asio::DeadlineTimer> banExpiryCheck
|
||||
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS));
|
||||
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_BNET_EXPIRED_ACCOUNT_BANNED));
|
||||
|
||||
banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(banExpiryCheckInterval));
|
||||
banExpiryCheckTimer->expires_after(std::chrono::seconds(banExpiryCheckInterval));
|
||||
banExpiryCheckTimer->async_wait([timerRef = std::move(banExpiryCheckTimerRef), banExpiryCheckInterval](boost::system::error_code const& error) mutable
|
||||
{
|
||||
BanExpiryHandler(std::move(timerRef), banExpiryCheckInterval, error);
|
||||
@@ -382,7 +382,7 @@ void ServiceStatusWatcher(std::weak_ptr<Trinity::Asio::DeadlineTimer> serviceSta
|
||||
}
|
||||
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([timerRef = std::move(serviceStatusWatchTimerRef), ioContextRef = std::move(ioContextRef)](boost::system::error_code const& error) mutable
|
||||
{
|
||||
ServiceStatusWatcher(std::move(timerRef), std::move(ioContextRef), error);
|
||||
|
||||
@@ -142,7 +142,7 @@ void SessionService::InitAndStoreSessionState(std::shared_ptr<SessionState> stat
|
||||
void SessionService::Start(Asio::IoContext& ioContext)
|
||||
{
|
||||
_inactiveSessionsKillTimer = std::make_unique<Asio::DeadlineTimer>(ioContext);
|
||||
_inactiveSessionsKillTimer->expires_from_now(boost::posix_time::minutes(1));
|
||||
_inactiveSessionsKillTimer->expires_after(1min);
|
||||
_inactiveSessionsKillTimer->async_wait([this](boost::system::error_code const& err)
|
||||
{
|
||||
if (err)
|
||||
@@ -255,7 +255,7 @@ void SessionService::KillInactiveSessions()
|
||||
}
|
||||
}
|
||||
|
||||
_inactiveSessionsKillTimer->expires_from_now(boost::posix_time::minutes(1));
|
||||
_inactiveSessionsKillTimer->expires_after(1min);
|
||||
_inactiveSessionsKillTimer->async_wait([this](boost::system::error_code const& err)
|
||||
{
|
||||
if (err)
|
||||
|
||||
@@ -117,7 +117,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();
|
||||
|
||||
@@ -131,7 +131,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();
|
||||
|
||||
@@ -200,7 +200,7 @@ void RealmList::UpdateRealms()
|
||||
|
||||
if (_updateInterval)
|
||||
{
|
||||
_updateTimer->expires_from_now(boost::posix_time::seconds(_updateInterval));
|
||||
_updateTimer->expires_after(std::chrono::seconds(_updateInterval));
|
||||
_updateTimer->async_wait([this](boost::system::error_code const& error)
|
||||
{
|
||||
if (error)
|
||||
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
|
||||
static void Start(std::shared_ptr<FreezeDetector> const& freezeDetector)
|
||||
{
|
||||
freezeDetector->_timer.expires_from_now(boost::posix_time::seconds(5));
|
||||
freezeDetector->_timer.expires_after(5s);
|
||||
freezeDetector->_timer.async_wait([freezeDetectorRef = std::weak_ptr(freezeDetector)](boost::system::error_code const& error) mutable
|
||||
{
|
||||
Handler(std::move(freezeDetectorRef), error);
|
||||
@@ -624,7 +624,7 @@ void FreezeDetector::Handler(std::weak_ptr<FreezeDetector> freezeDetectorRef, bo
|
||||
}
|
||||
}
|
||||
|
||||
freezeDetector->_timer.expires_from_now(boost::posix_time::seconds(1));
|
||||
freezeDetector->_timer.expires_after(1s);
|
||||
freezeDetector->_timer.async_wait([freezeDetectorRef = std::move(freezeDetectorRef)](boost::system::error_code const& error) mutable
|
||||
{
|
||||
Handler(std::move(freezeDetectorRef), error);
|
||||
|
||||
Reference in New Issue
Block a user