From d56c6710640e63fff6ead927b10d5135b9813bc6 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sun, 14 Apr 2019 00:13:23 +0200 Subject: Core/Dep: Boost 1.70 compatibility (cherry picked from commit bcda8dd7421cfa1950a3e47081f2f28d032d38ac) --- src/common/Asio/AsioHacksFwd.h | 24 +++++++-------- src/common/Asio/DeadlineTimer.h | 45 ++++++++++++++++++++++++++++ src/common/Asio/IoContext.h | 19 ++++++++++-- src/common/Metric/Metric.cpp | 6 ++-- src/common/Metric/Metric.h | 6 ++-- src/server/authserver/Main.cpp | 33 ++++++++++---------- src/server/shared/Networking/NetworkThread.h | 4 +-- src/server/shared/Realm/RealmList.cpp | 4 +-- src/server/shared/Realm/RealmList.h | 3 +- src/server/worldserver/Main.cpp | 4 +-- 10 files changed, 103 insertions(+), 45 deletions(-) create mode 100644 src/common/Asio/DeadlineTimer.h (limited to 'src') diff --git a/src/common/Asio/AsioHacksFwd.h b/src/common/Asio/AsioHacksFwd.h index 3e65395a3ca..2cb2282a10a 100644 --- a/src/common/Asio/AsioHacksFwd.h +++ b/src/common/Asio/AsioHacksFwd.h @@ -46,29 +46,25 @@ namespace boost typedef basic_endpoint tcp_endpoint; } +#if BOOST_VERSION >= 107000 + class executor; -#if BOOST_VERSION >= 106600 - template - class basic_deadline_timer; - - typedef basic_deadline_timer> deadline_timer; + namespace ip + { + template + class basic_resolver; + typedef basic_resolver tcp_resolver; + } +#elif BOOST_VERSION >= 106600 namespace ip { template class basic_resolver; typedef basic_resolver tcp_resolver; - } + } #else - template - class deadline_timer_service; - - template - class basic_deadline_timer; - - typedef basic_deadline_timer, deadline_timer_service>> deadline_timer; - namespace ip { template diff --git a/src/common/Asio/DeadlineTimer.h b/src/common/Asio/DeadlineTimer.h new file mode 100644 index 00000000000..4e0c3a10b44 --- /dev/null +++ b/src/common/Asio/DeadlineTimer.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2008-2019 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 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 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 DeadlineTimer_h__ +#define DeadlineTimer_h__ + +#include + +#if BOOST_VERSION >= 107000 +#define BasicDeadlineTimerThirdTemplateArg , boost::asio::io_context::executor_type +#elif BOOST_VERSION >= 106600 +#define BasicDeadlineTimerThirdTemplateArg +#else +#define BasicDeadlineTimerThirdTemplateArg , boost::asio::deadline_timer_service> +#endif + +#define DeadlineTimerBase boost::asio::basic_deadline_timer BasicDeadlineTimerThirdTemplateArg> + +namespace Trinity +{ + namespace Asio + { + class DeadlineTimer : public DeadlineTimerBase + { + public: + using DeadlineTimerBase::basic_deadline_timer; + }; + } +} + +#endif // DeadlineTimer_h__ diff --git a/src/common/Asio/IoContext.h b/src/common/Asio/IoContext.h index e92222e8d0a..8ac0cc0a4e1 100644 --- a/src/common/Asio/IoContext.h +++ b/src/common/Asio/IoContext.h @@ -35,9 +35,24 @@ namespace Trinity { namespace Asio { - class IoContext : public IoContextBaseNamespace::IoContextBase + class IoContext { - using IoContextBaseNamespace::IoContextBase::IoContextBase; + public: + IoContext() : _impl() { } + explicit IoContext(int concurrency_hint) : _impl(concurrency_hint) { } + + operator IoContextBaseNamespace::IoContextBase&() { return _impl; } + operator IoContextBaseNamespace::IoContextBase const&() const { return _impl; } + + std::size_t run() { return _impl.run(); } + void stop() { _impl.stop(); } + +#if BOOST_VERSION >= 106600 + boost::asio::io_context::executor_type get_executor() noexcept { return _impl.get_executor(); } +#endif + + private: + IoContextBaseNamespace::IoContextBase _impl; }; template diff --git a/src/common/Metric/Metric.cpp b/src/common/Metric/Metric.cpp index e7780880c3d..826bd2b1ae3 100644 --- a/src/common/Metric/Metric.cpp +++ b/src/common/Metric/Metric.cpp @@ -18,19 +18,19 @@ #include "Metric.h" #include "Common.h" #include "Config.h" +#include "DeadlineTimer.h" #include "Log.h" #include "Strand.h" #include "Util.h" #include -#include #include void Metric::Initialize(std::string const& realmName, Trinity::Asio::IoContext& ioContext, std::function overallStatusLogger) { _dataStream = Trinity::make_unique(); _realmName = FormatInfluxDBTagValue(realmName); - _batchTimer = Trinity::make_unique(ioContext); - _overallStatusTimer = Trinity::make_unique(ioContext); + _batchTimer = Trinity::make_unique(ioContext); + _overallStatusTimer = Trinity::make_unique(ioContext); _overallStatusLogger = overallStatusLogger; LoadFromConfigs(); } diff --git a/src/common/Metric/Metric.h b/src/common/Metric/Metric.h index d83b277841d..ad3a94647be 100644 --- a/src/common/Metric/Metric.h +++ b/src/common/Metric/Metric.h @@ -19,7 +19,6 @@ #define METRIC_H__ #include "Define.h" -#include "AsioHacksFwd.h" #include "MPSCQueue.h" #include #include @@ -32,6 +31,7 @@ namespace Trinity namespace Asio { class IoContext; + class DeadlineTimer; } } @@ -61,8 +61,8 @@ private: std::iostream& GetDataStream() { return *_dataStream; } std::unique_ptr _dataStream; MPSCQueue _queuedData; - std::unique_ptr _batchTimer; - std::unique_ptr _overallStatusTimer; + std::unique_ptr _batchTimer; + std::unique_ptr _overallStatusTimer; int32 _updateInterval = 0; int32 _overallStatusTimerInterval = 0; bool _enabled = false; diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp index 1d9f8d79d61..1b58aa35155 100644 --- a/src/server/authserver/Main.cpp +++ b/src/server/authserver/Main.cpp @@ -30,6 +30,7 @@ #include "Config.h" #include "DatabaseEnv.h" #include "DatabaseLoader.h" +#include "DeadlineTimer.h" #include "IoContext.h" #include "IPLocation.h" #include "GitRevision.h" @@ -66,14 +67,14 @@ char serviceDescription[] = "TrinityCore World of Warcraft emulator auth service */ int m_ServiceStatus = -1; -void ServiceStatusWatcher(std::weak_ptr serviceStatusWatchTimerRef, std::weak_ptr ioContextRef, boost::system::error_code const& error); +void ServiceStatusWatcher(std::weak_ptr serviceStatusWatchTimerRef, std::weak_ptr ioContextRef, boost::system::error_code const& error); #endif bool StartDB(); void StopDB(); void SignalHandler(std::weak_ptr ioContextRef, boost::system::error_code const& error, int signalNumber); -void KeepDatabaseAliveHandler(std::weak_ptr dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error); -void BanExpiryHandler(std::weak_ptr banExpiryCheckTimerRef, int32 banExpiryCheckInterval, boost::system::error_code const& error); +void KeepDatabaseAliveHandler(std::weak_ptr dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error); +void BanExpiryHandler(std::weak_ptr banExpiryCheckTimerRef, int32 banExpiryCheckInterval, boost::system::error_code const& error); variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& configService); int main(int argc, char** argv) @@ -186,23 +187,23 @@ 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 dbPingTimer = std::make_shared(*ioContext); + std::shared_ptr dbPingTimer = std::make_shared(*ioContext); dbPingTimer->expires_from_now(boost::posix_time::minutes(dbPingInterval)); - dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, std::weak_ptr(dbPingTimer), dbPingInterval, std::placeholders::_1)); + dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, std::weak_ptr(dbPingTimer), dbPingInterval, std::placeholders::_1)); int32 banExpiryCheckInterval = sConfigMgr->GetIntDefault("BanExpiryCheckInterval", 60); - std::shared_ptr banExpiryCheckTimer = std::make_shared(*ioContext); + std::shared_ptr banExpiryCheckTimer = std::make_shared(*ioContext); banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(banExpiryCheckInterval)); - banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, std::weak_ptr(banExpiryCheckTimer), banExpiryCheckInterval, std::placeholders::_1)); + banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, std::weak_ptr(banExpiryCheckTimer), banExpiryCheckInterval, std::placeholders::_1)); #if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS - std::shared_ptr serviceStatusWatchTimer; + std::shared_ptr serviceStatusWatchTimer; if (m_ServiceStatus != -1) { - serviceStatusWatchTimer = std::make_shared(*ioContext); + serviceStatusWatchTimer = std::make_shared(*ioContext); serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1)); serviceStatusWatchTimer->async_wait(std::bind(&ServiceStatusWatcher, - std::weak_ptr(serviceStatusWatchTimer), + std::weak_ptr(serviceStatusWatchTimer), std::weak_ptr(ioContext), std::placeholders::_1)); } @@ -255,11 +256,11 @@ void SignalHandler(std::weak_ptr ioContextRef, boost:: ioContext->stop(); } -void KeepDatabaseAliveHandler(std::weak_ptr dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error) +void KeepDatabaseAliveHandler(std::weak_ptr dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error) { if (!error) { - if (std::shared_ptr dbPingTimer = dbPingTimerRef.lock()) + if (std::shared_ptr dbPingTimer = dbPingTimerRef.lock()) { TC_LOG_INFO("server.authserver", "Ping MySQL to keep connection alive"); LoginDatabase.KeepAlive(); @@ -270,11 +271,11 @@ void KeepDatabaseAliveHandler(std::weak_ptr dbPingT } } -void BanExpiryHandler(std::weak_ptr banExpiryCheckTimerRef, int32 banExpiryCheckInterval, boost::system::error_code const& error) +void BanExpiryHandler(std::weak_ptr banExpiryCheckTimerRef, int32 banExpiryCheckInterval, boost::system::error_code const& error) { if (!error) { - if (std::shared_ptr banExpiryCheckTimer = banExpiryCheckTimerRef.lock()) + if (std::shared_ptr banExpiryCheckTimer = banExpiryCheckTimerRef.lock()) { LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS)); LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS)); @@ -286,7 +287,7 @@ void BanExpiryHandler(std::weak_ptr banExpiryCheckT } #if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS -void ServiceStatusWatcher(std::weak_ptr serviceStatusWatchTimerRef, std::weak_ptr ioContextRef, boost::system::error_code const& error) +void ServiceStatusWatcher(std::weak_ptr serviceStatusWatchTimerRef, std::weak_ptr ioContextRef, boost::system::error_code const& error) { if (!error) { @@ -294,7 +295,7 @@ void ServiceStatusWatcher(std::weak_ptr serviceStat { if (m_ServiceStatus == 0) ioContext->stop(); - else if (std::shared_ptr serviceStatusWatchTimer = serviceStatusWatchTimerRef.lock()) + else if (std::shared_ptr serviceStatusWatchTimer = serviceStatusWatchTimerRef.lock()) { serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1)); 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 875f59f4abb..1513ec7d009 100644 --- a/src/server/shared/Networking/NetworkThread.h +++ b/src/server/shared/Networking/NetworkThread.h @@ -19,12 +19,12 @@ #define NetworkThread_h__ #include "Define.h" +#include "DeadlineTimer.h" #include "Errors.h" #include "IoContext.h" #include "Log.h" #include "Timer.h" #include -#include #include #include #include @@ -173,7 +173,7 @@ private: Trinity::Asio::IoContext _ioContext; tcp::socket _acceptSocket; - boost::asio::deadline_timer _updateTimer; + Trinity::Asio::DeadlineTimer _updateTimer; }; #endif // NetworkThread_h__ diff --git a/src/server/shared/Realm/RealmList.cpp b/src/server/shared/Realm/RealmList.cpp index 5d537e65440..ec0a707eb61 100644 --- a/src/server/shared/Realm/RealmList.cpp +++ b/src/server/shared/Realm/RealmList.cpp @@ -18,11 +18,11 @@ #include "RealmList.h" #include "DatabaseEnv.h" +#include "DeadlineTimer.h" #include "IoContext.h" #include "Log.h" #include "Resolver.h" #include "Util.h" -#include #include RealmList::RealmList() : _updateInterval(0) @@ -43,7 +43,7 @@ RealmList* RealmList::Instance() void RealmList::Initialize(Trinity::Asio::IoContext& ioContext, uint32 updateInterval) { _updateInterval = updateInterval; - _updateTimer = Trinity::make_unique(ioContext); + _updateTimer = Trinity::make_unique(ioContext); _resolver = Trinity::make_unique(ioContext); // Get the content of the realmlist table in the database diff --git a/src/server/shared/Realm/RealmList.h b/src/server/shared/Realm/RealmList.h index b1fa837013f..62f615c0cae 100644 --- a/src/server/shared/Realm/RealmList.h +++ b/src/server/shared/Realm/RealmList.h @@ -38,6 +38,7 @@ namespace Trinity namespace Asio { class IoContext; + class DeadlineTimer; } } @@ -67,7 +68,7 @@ private: RealmMap _realms; uint32 _updateInterval; - std::unique_ptr _updateTimer; + std::unique_ptr _updateTimer; std::unique_ptr _resolver; }; diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index c5ccb1fec89..335b553a018 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -30,6 +30,7 @@ #include "Configuration/Config.h" #include "DatabaseEnv.h" #include "DatabaseLoader.h" +#include "DeadlineTimer.h" #include "GitRevision.h" #include "InstanceSaveMgr.h" #include "IoContext.h" @@ -52,7 +53,6 @@ #include "WorldSocketMgr.h" #include #include -#include #include #include #include @@ -97,7 +97,7 @@ class FreezeDetector static void Handler(std::weak_ptr freezeDetectorRef, boost::system::error_code const& error); private: - boost::asio::deadline_timer _timer; + Trinity::Asio::DeadlineTimer _timer; uint32 _worldLoopCounter; uint32 _lastChangeMsTime; uint32 _maxCoreStuckTimeInMs; -- cgit v1.2.3