refactor(Core/Misc): Use steady_timer instead of deadline_timer (#20940)
This commit is contained in:
@@ -1,34 +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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DeadlineTimer_h__
|
|
||||||
#define DeadlineTimer_h__
|
|
||||||
|
|
||||||
#include <boost/asio/deadline_timer.hpp>
|
|
||||||
|
|
||||||
#define DeadlineTimerBase boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::io_context::executor_type>
|
|
||||||
|
|
||||||
namespace Acore::Asio
|
|
||||||
{
|
|
||||||
class DeadlineTimer : public DeadlineTimerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
using DeadlineTimerBase::basic_deadline_timer;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // DeadlineTimer_h__
|
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#define IoContext_h__
|
#define IoContext_h__
|
||||||
|
|
||||||
#include <boost/version.hpp>
|
#include <boost/version.hpp>
|
||||||
|
|
||||||
#include <boost/asio/io_context.hpp>
|
#include <boost/asio/io_context.hpp>
|
||||||
#include <boost/asio/post.hpp>
|
#include <boost/asio/post.hpp>
|
||||||
#define IoContextBaseNamespace boost::asio
|
#define IoContextBaseNamespace boost::asio
|
||||||
@@ -52,9 +51,9 @@ namespace Acore::Asio
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline decltype(auto) get_io_context(T&& ioObject)
|
inline boost::asio::io_context& get_io_context(T&& ioObject)
|
||||||
{
|
{
|
||||||
return ioObject.get_executor().context();
|
return static_cast<boost::asio::io_context&>(ioObject.get_executor().context());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
#include "Metric.h"
|
#include "Metric.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "DeadlineTimer.h"
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Strand.h"
|
#include "Strand.h"
|
||||||
#include "Tokenize.h"
|
#include "Tokenize.h"
|
||||||
@@ -42,8 +41,8 @@ void Metric::Initialize(std::string const& realmName, Acore::Asio::IoContext& io
|
|||||||
{
|
{
|
||||||
_dataStream = std::make_unique<boost::asio::ip::tcp::iostream>();
|
_dataStream = std::make_unique<boost::asio::ip::tcp::iostream>();
|
||||||
_realmName = FormatInfluxDBTagValue(realmName);
|
_realmName = FormatInfluxDBTagValue(realmName);
|
||||||
_batchTimer = std::make_unique<Acore::Asio::DeadlineTimer>(ioContext);
|
_batchTimer = std::make_unique<boost::asio::steady_timer>(ioContext);
|
||||||
_overallStatusTimer = std::make_unique<Acore::Asio::DeadlineTimer>(ioContext);
|
_overallStatusTimer = std::make_unique<boost::asio::steady_timer>(ioContext);
|
||||||
_overallStatusLogger = overallStatusLogger;
|
_overallStatusLogger = overallStatusLogger;
|
||||||
LoadFromConfigs();
|
LoadFromConfigs();
|
||||||
}
|
}
|
||||||
@@ -247,7 +246,9 @@ void Metric::ScheduleSend()
|
|||||||
{
|
{
|
||||||
if (_enabled)
|
if (_enabled)
|
||||||
{
|
{
|
||||||
_batchTimer->expires_from_now(boost::posix_time::seconds(_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));
|
_batchTimer->async_wait(std::bind(&Metric::SendBatch, this));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -280,7 +281,9 @@ void Metric::ScheduleOverallStatusLog()
|
|||||||
{
|
{
|
||||||
if (_enabled)
|
if (_enabled)
|
||||||
{
|
{
|
||||||
_overallStatusTimer->expires_from_now(boost::posix_time::seconds(_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&)
|
_overallStatusTimer->async_wait([this](const boost::system::error_code&)
|
||||||
{
|
{
|
||||||
_overallStatusTimerTriggered = true;
|
_overallStatusTimerTriggered = true;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "Define.h"
|
#include "Define.h"
|
||||||
#include "Duration.h"
|
#include "Duration.h"
|
||||||
#include "MPSCQueue.h"
|
#include "MPSCQueue.h"
|
||||||
|
#include <boost/asio/steady_timer.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory> // NOTE: this import is NEEDED (even though some IDEs report it as unused)
|
#include <memory> // NOTE: this import is NEEDED (even though some IDEs report it as unused)
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -30,7 +31,6 @@
|
|||||||
namespace Acore::Asio
|
namespace Acore::Asio
|
||||||
{
|
{
|
||||||
class IoContext;
|
class IoContext;
|
||||||
class DeadlineTimer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MetricDataType
|
enum MetricDataType
|
||||||
@@ -62,8 +62,8 @@ private:
|
|||||||
std::iostream& GetDataStream() { return *_dataStream; }
|
std::iostream& GetDataStream() { return *_dataStream; }
|
||||||
std::unique_ptr<std::iostream> _dataStream;
|
std::unique_ptr<std::iostream> _dataStream;
|
||||||
MPSCQueue<MetricData> _queuedData;
|
MPSCQueue<MetricData> _queuedData;
|
||||||
std::unique_ptr<Acore::Asio::DeadlineTimer> _batchTimer;
|
std::unique_ptr<boost::asio::steady_timer> _batchTimer;
|
||||||
std::unique_ptr<Acore::Asio::DeadlineTimer> _overallStatusTimer;
|
std::unique_ptr<boost::asio::steady_timer> _overallStatusTimer;
|
||||||
int32 _updateInterval = 0;
|
int32 _updateInterval = 0;
|
||||||
int32 _overallStatusTimerInterval = 0;
|
int32 _overallStatusTimerInterval = 0;
|
||||||
bool _enabled = false;
|
bool _enabled = false;
|
||||||
|
|||||||
@@ -29,7 +29,6 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "DatabaseEnv.h"
|
#include "DatabaseEnv.h"
|
||||||
#include "DatabaseLoader.h"
|
#include "DatabaseLoader.h"
|
||||||
#include "DeadlineTimer.h"
|
|
||||||
#include "IPLocation.h"
|
#include "IPLocation.h"
|
||||||
#include "IoContext.h"
|
#include "IoContext.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
@@ -60,8 +59,8 @@ namespace fs = std::filesystem;
|
|||||||
bool StartDB();
|
bool StartDB();
|
||||||
void StopDB();
|
void StopDB();
|
||||||
void SignalHandler(std::weak_ptr<Acore::Asio::IoContext> ioContextRef, boost::system::error_code const& error, int signalNumber);
|
void SignalHandler(std::weak_ptr<Acore::Asio::IoContext> ioContextRef, boost::system::error_code const& error, int signalNumber);
|
||||||
void KeepDatabaseAliveHandler(std::weak_ptr<Acore::Asio::DeadlineTimer> dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error);
|
void KeepDatabaseAliveHandler(std::weak_ptr<boost::asio::steady_timer> dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error);
|
||||||
void BanExpiryHandler(std::weak_ptr<Acore::Asio::DeadlineTimer> banExpiryCheckTimerRef, int32 banExpiryCheckInterval, boost::system::error_code const& error);
|
void BanExpiryHandler(std::weak_ptr<boost::asio::steady_timer> banExpiryCheckTimerRef, int32 banExpiryCheckInterval, boost::system::error_code const& error);
|
||||||
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile);
|
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile);
|
||||||
|
|
||||||
/// Launch the auth server
|
/// Launch the auth server
|
||||||
@@ -178,14 +177,20 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
// Enabled a timed callback for handling the database keep alive ping
|
// Enabled a timed callback for handling the database keep alive ping
|
||||||
int32 dbPingInterval = sConfigMgr->GetOption<int32>("MaxPingTime", 30);
|
int32 dbPingInterval = sConfigMgr->GetOption<int32>("MaxPingTime", 30);
|
||||||
std::shared_ptr<Acore::Asio::DeadlineTimer> dbPingTimer = std::make_shared<Acore::Asio::DeadlineTimer>(*ioContext);
|
std::shared_ptr<boost::asio::steady_timer> dbPingTimer = std::make_shared<boost::asio::steady_timer>(*ioContext);
|
||||||
dbPingTimer->expires_from_now(boost::posix_time::minutes(dbPingInterval));
|
|
||||||
dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, std::weak_ptr<Acore::Asio::DeadlineTimer>(dbPingTimer), dbPingInterval, std::placeholders::_1));
|
// 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<boost::asio::steady_timer>(dbPingTimer), dbPingInterval, std::placeholders::_1));
|
||||||
|
|
||||||
int32 banExpiryCheckInterval = sConfigMgr->GetOption<int32>("BanExpiryCheckInterval", 60);
|
int32 banExpiryCheckInterval = sConfigMgr->GetOption<int32>("BanExpiryCheckInterval", 60);
|
||||||
std::shared_ptr<Acore::Asio::DeadlineTimer> banExpiryCheckTimer = std::make_shared<Acore::Asio::DeadlineTimer>(*ioContext);
|
std::shared_ptr<boost::asio::steady_timer> banExpiryCheckTimer = std::make_shared<boost::asio::steady_timer>(*ioContext);
|
||||||
banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(banExpiryCheckInterval));
|
|
||||||
banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, std::weak_ptr<Acore::Asio::DeadlineTimer>(banExpiryCheckTimer), banExpiryCheckInterval, std::placeholders::_1));
|
// 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<boost::asio::steady_timer>(banExpiryCheckTimer), banExpiryCheckInterval, std::placeholders::_1));
|
||||||
|
|
||||||
// Start the io service worker loop
|
// Start the io service worker loop
|
||||||
ioContext->run();
|
ioContext->run();
|
||||||
@@ -238,31 +243,35 @@ void SignalHandler(std::weak_ptr<Acore::Asio::IoContext> ioContextRef, boost::sy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeepDatabaseAliveHandler(std::weak_ptr<Acore::Asio::DeadlineTimer> dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error)
|
void KeepDatabaseAliveHandler(std::weak_ptr<boost::asio::steady_timer> dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error)
|
||||||
{
|
{
|
||||||
if (!error)
|
if (!error)
|
||||||
{
|
{
|
||||||
if (std::shared_ptr<Acore::Asio::DeadlineTimer> dbPingTimer = dbPingTimerRef.lock())
|
if (std::shared_ptr<boost::asio::steady_timer> dbPingTimer = dbPingTimerRef.lock())
|
||||||
{
|
{
|
||||||
LOG_INFO("server.authserver", "Ping MySQL to keep connection alive");
|
LOG_INFO("server.authserver", "Ping MySQL to keep connection alive");
|
||||||
LoginDatabase.KeepAlive();
|
LoginDatabase.KeepAlive();
|
||||||
|
|
||||||
dbPingTimer->expires_from_now(boost::posix_time::minutes(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));
|
dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, dbPingTimerRef, dbPingInterval, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BanExpiryHandler(std::weak_ptr<Acore::Asio::DeadlineTimer> banExpiryCheckTimerRef, int32 banExpiryCheckInterval, boost::system::error_code const& error)
|
void BanExpiryHandler(std::weak_ptr<boost::asio::steady_timer> banExpiryCheckTimerRef, int32 banExpiryCheckInterval, boost::system::error_code const& error)
|
||||||
{
|
{
|
||||||
if (!error)
|
if (!error)
|
||||||
{
|
{
|
||||||
if (std::shared_ptr<Acore::Asio::DeadlineTimer> banExpiryCheckTimer = banExpiryCheckTimerRef.lock())
|
if (std::shared_ptr<boost::asio::steady_timer> banExpiryCheckTimer = banExpiryCheckTimerRef.lock())
|
||||||
{
|
{
|
||||||
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS));
|
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS));
|
||||||
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS));
|
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS));
|
||||||
|
|
||||||
banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(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));
|
banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, banExpiryCheckTimerRef, banExpiryCheckInterval, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "DatabaseEnv.h"
|
#include "DatabaseEnv.h"
|
||||||
#include "DatabaseLoader.h"
|
#include "DatabaseLoader.h"
|
||||||
#include "DeadlineTimer.h"
|
|
||||||
#include "GitRevision.h"
|
#include "GitRevision.h"
|
||||||
#include "IoContext.h"
|
#include "IoContext.h"
|
||||||
#include "MapMgr.h"
|
#include "MapMgr.h"
|
||||||
@@ -91,14 +90,16 @@ public:
|
|||||||
|
|
||||||
static void Start(std::shared_ptr<FreezeDetector> const& freezeDetector)
|
static void Start(std::shared_ptr<FreezeDetector> const& freezeDetector)
|
||||||
{
|
{
|
||||||
freezeDetector->_timer.expires_from_now(boost::posix_time::seconds(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>(freezeDetector), std::placeholders::_1));
|
freezeDetector->_timer.async_wait(std::bind(&FreezeDetector::Handler, std::weak_ptr<FreezeDetector>(freezeDetector), std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
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:
|
private:
|
||||||
Acore::Asio::DeadlineTimer _timer;
|
boost::asio::steady_timer _timer;
|
||||||
uint32 _worldLoopCounter;
|
uint32 _worldLoopCounter;
|
||||||
uint32 _lastChangeMsTime;
|
uint32 _lastChangeMsTime;
|
||||||
uint32 _maxCoreStuckTimeInMs;
|
uint32 _maxCoreStuckTimeInMs;
|
||||||
@@ -631,7 +632,9 @@ void FreezeDetector::Handler(std::weak_ptr<FreezeDetector> freezeDetectorRef, bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
freezeDetector->_timer.expires_from_now(boost::posix_time::seconds(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));
|
freezeDetector->_timer.async_wait(std::bind(&FreezeDetector::Handler, freezeDetectorRef, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,14 @@
|
|||||||
#ifndef NetworkThread_h__
|
#ifndef NetworkThread_h__
|
||||||
#define NetworkThread_h__
|
#define NetworkThread_h__
|
||||||
|
|
||||||
#include "DeadlineTimer.h"
|
|
||||||
#include "Define.h"
|
#include "Define.h"
|
||||||
#include "Errors.h"
|
#include "Errors.h"
|
||||||
#include "IoContext.h"
|
#include "IoContext.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
#include <atomic>
|
|
||||||
#include <boost/asio/ip/tcp.hpp>
|
#include <boost/asio/ip/tcp.hpp>
|
||||||
|
#include <boost/asio/steady_timer.hpp>
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <set>
|
#include <set>
|
||||||
@@ -179,7 +179,7 @@ protected:
|
|||||||
{
|
{
|
||||||
LOG_DEBUG("misc", "Network Thread Starting");
|
LOG_DEBUG("misc", "Network Thread Starting");
|
||||||
|
|
||||||
_updateTimer.expires_from_now(boost::posix_time::milliseconds(1));
|
_updateTimer.expires_at(std::chrono::steady_clock::now());
|
||||||
_updateTimer.async_wait([this](boost::system::error_code const&) { Update(); });
|
_updateTimer.async_wait([this](boost::system::error_code const&) { Update(); });
|
||||||
_ioContext.run();
|
_ioContext.run();
|
||||||
|
|
||||||
@@ -193,7 +193,7 @@ protected:
|
|||||||
if (_stopped)
|
if (_stopped)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_updateTimer.expires_from_now(boost::posix_time::milliseconds(1));
|
_updateTimer.expires_at(std::chrono::steady_clock::now());
|
||||||
_updateTimer.async_wait([this](boost::system::error_code const&) { Update(); });
|
_updateTimer.async_wait([this](boost::system::error_code const&) { Update(); });
|
||||||
|
|
||||||
AddNewSockets();
|
AddNewSockets();
|
||||||
@@ -230,7 +230,7 @@ private:
|
|||||||
|
|
||||||
Acore::Asio::IoContext _ioContext;
|
Acore::Asio::IoContext _ioContext;
|
||||||
tcp::socket _acceptSocket;
|
tcp::socket _acceptSocket;
|
||||||
Acore::Asio::DeadlineTimer _updateTimer;
|
boost::asio::steady_timer _updateTimer;
|
||||||
|
|
||||||
bool _proxyHeaderReadingEnabled;
|
bool _proxyHeaderReadingEnabled;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
#include "RealmList.h"
|
#include "RealmList.h"
|
||||||
#include "DatabaseEnv.h"
|
#include "DatabaseEnv.h"
|
||||||
#include "DeadlineTimer.h"
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Resolver.h"
|
#include "Resolver.h"
|
||||||
#include "QueryResult.h"
|
#include "QueryResult.h"
|
||||||
@@ -37,7 +36,7 @@ RealmList* RealmList::Instance()
|
|||||||
void RealmList::Initialize(Acore::Asio::IoContext& ioContext, uint32 updateInterval)
|
void RealmList::Initialize(Acore::Asio::IoContext& ioContext, uint32 updateInterval)
|
||||||
{
|
{
|
||||||
_updateInterval = updateInterval;
|
_updateInterval = updateInterval;
|
||||||
_updateTimer = std::make_unique<Acore::Asio::DeadlineTimer>(ioContext);
|
_updateTimer = std::make_unique<boost::asio::steady_timer>(ioContext);
|
||||||
_resolver = std::make_unique<Acore::Asio::Resolver>(ioContext);
|
_resolver = std::make_unique<Acore::Asio::Resolver>(ioContext);
|
||||||
|
|
||||||
LoadBuildInfo();
|
LoadBuildInfo();
|
||||||
@@ -228,7 +227,9 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
|
|||||||
|
|
||||||
if (_updateInterval)
|
if (_updateInterval)
|
||||||
{
|
{
|
||||||
_updateTimer->expires_from_now(boost::posix_time::seconds(_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); });
|
_updateTimer->async_wait([this](boost::system::error_code const& errorCode){ UpdateRealms(errorCode); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,22 @@
|
|||||||
|
|
||||||
#include "Define.h"
|
#include "Define.h"
|
||||||
#include "Realm.h"
|
#include "Realm.h"
|
||||||
|
#include <boost/asio/steady_timer.hpp>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory> // NOTE: this import is NEEDED (even though some IDEs report it as unused)
|
#include <memory> // NOTE: this import is NEEDED (even though some IDEs report it as unused)
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Acore::Asio
|
||||||
|
{
|
||||||
|
class IoContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace boost::system
|
||||||
|
{
|
||||||
|
class error_code;
|
||||||
|
}
|
||||||
|
|
||||||
struct RealmBuildInfo
|
struct RealmBuildInfo
|
||||||
{
|
{
|
||||||
uint32 Build;
|
uint32 Build;
|
||||||
@@ -36,11 +47,6 @@ struct RealmBuildInfo
|
|||||||
std::array<uint8, 20> MacHash;
|
std::array<uint8, 20> MacHash;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace boost::system
|
|
||||||
{
|
|
||||||
class error_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Storage object for the list of realms on the server
|
/// Storage object for the list of realms on the server
|
||||||
class AC_SHARED_API RealmList
|
class AC_SHARED_API RealmList
|
||||||
{
|
{
|
||||||
@@ -70,7 +76,7 @@ private:
|
|||||||
std::vector<RealmBuildInfo> _builds;
|
std::vector<RealmBuildInfo> _builds;
|
||||||
RealmMap _realms;
|
RealmMap _realms;
|
||||||
uint32 _updateInterval{0};
|
uint32 _updateInterval{0};
|
||||||
std::unique_ptr<Acore::Asio::DeadlineTimer> _updateTimer;
|
std::unique_ptr<boost::asio::steady_timer> _updateTimer;
|
||||||
std::unique_ptr<Acore::Asio::Resolver> _resolver;
|
std::unique_ptr<Acore::Asio::Resolver> _resolver;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user