From b9c72c3c7f1b6090231163f133fe1be4d399b218 Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 11 Mar 2021 10:33:05 +0100 Subject: [PATCH] Dep/Boost: Support for boost 1.74 --- src/common/Asio/AsioHacksFwd.h | 33 +--------- src/common/Asio/Resolver.h | 46 ++++++++------ src/common/Hacks/boost_1_74_fibonacci_heap.h | 61 +++++++++++++++++++ .../bnetserver/Realms/BNetRealmList.cpp | 12 ++-- src/server/bnetserver/Realms/BNetRealmList.h | 11 +--- src/server/game/Combat/ThreatManager.cpp | 3 + src/server/game/Maps/Map.cpp | 3 + src/server/worldserver/Main.cpp | 8 +-- 8 files changed, 109 insertions(+), 68 deletions(-) create mode 100644 src/common/Hacks/boost_1_74_fibonacci_heap.h diff --git a/src/common/Asio/AsioHacksFwd.h b/src/common/Asio/AsioHacksFwd.h index 4f245ee9ae..6030436d39 100644 --- a/src/common/Asio/AsioHacksFwd.h +++ b/src/common/Asio/AsioHacksFwd.h @@ -46,36 +46,6 @@ namespace boost typedef basic_endpoint tcp_endpoint; } -#if BOOST_VERSION >= 107000 - class executor; - - 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 - namespace ip - { - template - class resolver_service; - - template - class basic_resolver; - - typedef basic_resolver> tcp_resolver; - } -#endif } } @@ -83,6 +53,9 @@ namespace Trinity { namespace Asio { + class DeadlineTimer; + class IoContext; + class Resolver; class Strand; } } diff --git a/src/common/Asio/Resolver.h b/src/common/Asio/Resolver.h index 2d8497e7e9..b63747b139 100644 --- a/src/common/Asio/Resolver.h +++ b/src/common/Asio/Resolver.h @@ -18,36 +18,48 @@ #ifndef Resolver_h__ #define Resolver_h__ +#include "IoContext.h" #include "Optional.h" #include #include namespace Trinity { - namespace Net + namespace Asio { - inline Optional Resolve(boost::asio::ip::tcp::resolver& resolver, boost::asio::ip::tcp const& protocol, - std::string const& host, std::string const& service) + /** + Hack to make it possible to forward declare resolver (one of its template arguments is a typedef to something super long and using nested classes) + */ + class Resolver { - boost::system::error_code ec; + public: + explicit Resolver(IoContext& ioContext) : _impl(ioContext) { } + + Optional Resolve(boost::asio::ip::tcp const& protocol, std::string const& host, std::string const& service) + { + boost::system::error_code ec; #if BOOST_VERSION >= 106600 - boost::asio::ip::resolver_base::flags flagsResolver = boost::asio::ip::resolver_base::all_matching; - boost::asio::ip::tcp::resolver::results_type results = resolver.resolve(protocol, host, service, flagsResolver, ec); - if (results.begin() == results.end() || ec) - return {}; + boost::asio::ip::resolver_base::flags flagsResolver = boost::asio::ip::resolver_base::all_matching; + boost::asio::ip::tcp::resolver::results_type results = _impl.resolve(protocol, host, service, flagsResolver, ec); + if (results.begin() == results.end() || ec) + return {}; - return results.begin()->endpoint(); + return results.begin()->endpoint(); #else - boost::asio::ip::resolver_query_base::flags flagsQuery = boost::asio::ip::tcp::resolver::query::all_matching; - boost::asio::ip::tcp::resolver::query query(std::move(protocol), std::move(host), std::move(service), flagsQuery); - boost::asio::ip::tcp::resolver::iterator itr = resolver.resolve(query, ec); - boost::asio::ip::tcp::resolver::iterator end; - if (itr == end || ec) - return {}; + boost::asio::ip::resolver_query_base::flags flagsQuery = boost::asio::ip::tcp::resolver::query::all_matching; + boost::asio::ip::tcp::resolver::query query(std::move(protocol), std::move(host), std::move(service), flagsQuery); + boost::asio::ip::tcp::resolver::iterator itr = _impl.resolve(query, ec); + boost::asio::ip::tcp::resolver::iterator end; + if (itr == end || ec) + return {}; - return itr->endpoint(); + return itr->endpoint(); #endif - } + } + + private: + boost::asio::ip::tcp::resolver _impl; + }; } } diff --git a/src/common/Hacks/boost_1_74_fibonacci_heap.h b/src/common/Hacks/boost_1_74_fibonacci_heap.h new file mode 100644 index 0000000000..0ebf69cdde --- /dev/null +++ b/src/common/Hacks/boost_1_74_fibonacci_heap.h @@ -0,0 +1,61 @@ +/* + * This file is part of the TrinityCore 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 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 HACKS_boost_1_74_fibonacci_heap_h__ +#define HACKS_boost_1_74_fibonacci_heap_h__ + +#include "CompilerDefs.h" +#include + +#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT && BOOST_VERSION == 107400 +#define BOOST_1_74_FIBONACCI_HEAP_MSVC_COMPILE_FIX(T) \ +namespace boost::heap::detail \ +{ \ + template \ + void destroy_node(Node& node) \ + { \ + node.~Node(); \ + } \ + \ + template <> \ + struct node_disposer, \ + boost::heap::detail::heap_node_base, \ + std::allocator>> \ + { \ + using allocator = std::allocator>; \ + using node_pointer = typename boost::allocator_pointer::type; \ + \ + node_disposer(allocator& alloc) : _alloc(alloc) \ + { \ + } \ + \ + void operator()(boost::heap::detail::heap_node_base* base) \ + { \ + node_pointer n = static_cast(base); \ + n->clear_subtree(_alloc); \ + destroy_node(*n); /* <- the change compared to default implementation */ \ + _alloc.deallocate(n, 1); \ + } \ + \ + allocator& _alloc; \ + }; \ +} +#else +#define BOOST_1_74_FIBONACCI_HEAP_MSVC_COMPILE_FIX(T) +#endif + +#endif // HACKS_boost_1_74_fibonacci_heap_h__ diff --git a/src/server/bnetserver/Realms/BNetRealmList.cpp b/src/server/bnetserver/Realms/BNetRealmList.cpp index f2321b5c91..d10e2aa632 100644 --- a/src/server/bnetserver/Realms/BNetRealmList.cpp +++ b/src/server/bnetserver/Realms/BNetRealmList.cpp @@ -31,9 +31,7 @@ BNetRealmList::BNetRealmList() : _updateInterval(0) { } -BNetRealmList::~BNetRealmList() -{ -} +BNetRealmList::~BNetRealmList() = default; BNetRealmList* BNetRealmList::Instance() { @@ -46,7 +44,7 @@ void BNetRealmList::Initialize(Trinity::Asio::IoContext& ioContext, uint32 updat { _updateInterval = updateInterval; _updateTimer = Trinity::make_unique(ioContext); - _resolver = Trinity::make_unique(ioContext); + _resolver = Trinity::make_unique(ioContext); // Get the content of the realmlist table in the database UpdateRealms(boost::system::error_code()); @@ -129,21 +127,21 @@ void BNetRealmList::UpdateRealms(boost::system::error_code const& error) std::string localAddressString = fields[3].GetString(); std::string localSubmaskString = fields[4].GetString(); - Optional externalAddress = Trinity::Net::Resolve(*_resolver, boost::asio::ip::tcp::v4(), externalAddressString, ""); + Optional externalAddress = _resolver->Resolve(boost::asio::ip::tcp::v4(), externalAddressString, ""); if (!externalAddress) { TC_LOG_ERROR("realmlist", "Could not resolve address %s", externalAddressString.c_str()); continue; } - Optional localAddress = Trinity::Net::Resolve(*_resolver, boost::asio::ip::tcp::v4(), localAddressString, ""); + Optional localAddress = _resolver->Resolve(boost::asio::ip::tcp::v4(), localAddressString, ""); if (!localAddress) { TC_LOG_ERROR("realmlist", "Could not resolve address %s", localAddressString.c_str()); continue; } - Optional localSubmask = Trinity::Net::Resolve(*_resolver, boost::asio::ip::tcp::v4(), localSubmaskString, ""); + Optional localSubmask =_resolver->Resolve(boost::asio::ip::tcp::v4(), localSubmaskString, ""); if (!localSubmask) { TC_LOG_ERROR("realmlist", "Could not resolve address %s", localSubmaskString.c_str()); diff --git a/src/server/bnetserver/Realms/BNetRealmList.h b/src/server/bnetserver/Realms/BNetRealmList.h index 0efc9b2e29..601778b706 100644 --- a/src/server/bnetserver/Realms/BNetRealmList.h +++ b/src/server/bnetserver/Realms/BNetRealmList.h @@ -34,15 +34,6 @@ namespace boost } } -namespace Trinity -{ - namespace Asio - { - class IoContext; - class DeadlineTimer; - } -} - /// Storage object for the list of realms on the server class BNetRealmList { @@ -70,7 +61,7 @@ class BNetRealmList RealmMap _realms; uint32 _updateInterval; std::unique_ptr _updateTimer; - std::unique_ptr _resolver; + std::unique_ptr _resolver; std::unique_ptr _worldListener; }; diff --git a/src/server/game/Combat/ThreatManager.cpp b/src/server/game/Combat/ThreatManager.cpp index 8e4bcec4b3..366fe3df76 100644 --- a/src/server/game/Combat/ThreatManager.cpp +++ b/src/server/game/Combat/ThreatManager.cpp @@ -33,6 +33,9 @@ #include "WorldPacket.h" #include +#include "Hacks/boost_1_74_fibonacci_heap.h" +BOOST_1_74_FIBONACCI_HEAP_MSVC_COMPILE_FIX(ThreatManager::threat_list_heap::value_type) + const CompareThreatLessThan ThreatManager::CompareThreat; void ThreatReference::AddThreat(float amount) diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 7b03f92961..bc255741c1 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -52,6 +52,9 @@ #include #include +#include "Hacks/boost_1_74_fibonacci_heap.h" +BOOST_1_74_FIBONACCI_HEAP_MSVC_COMPILE_FIX(RespawnListContainer::value_type) + u_map_magic MapMagic = { {'M','A','P','S'} }; u_map_magic MapVersionMagic = { {'v','1','.','9'} }; u_map_magic MapAreaMagic = { {'A','R','E','A'} }; diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index a934edf1b9..c68ceb2271 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -519,11 +519,11 @@ bool LoadRealmInfo(Trinity::Asio::IoContext& ioContext) if (!result) return false; - boost::asio::ip::tcp::resolver resolver(ioContext); + Trinity::Asio::Resolver resolver(ioContext); Field* fields = result->Fetch(); realm.Name = fields[1].GetString(); - Optional externalAddress = Trinity::Net::Resolve(resolver, boost::asio::ip::tcp::v4(), fields[2].GetString(), ""); + Optional externalAddress = resolver.Resolve(boost::asio::ip::tcp::v4(), fields[2].GetString(), ""); if (!externalAddress) { TC_LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[2].GetString().c_str()); @@ -532,7 +532,7 @@ bool LoadRealmInfo(Trinity::Asio::IoContext& ioContext) realm.ExternalAddress = Trinity::make_unique(externalAddress->address()); - Optional localAddress = Trinity::Net::Resolve(resolver, boost::asio::ip::tcp::v4(), fields[3].GetString(), ""); + Optional localAddress = resolver.Resolve(boost::asio::ip::tcp::v4(), fields[3].GetString(), ""); if (!localAddress) { TC_LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[3].GetString().c_str()); @@ -541,7 +541,7 @@ bool LoadRealmInfo(Trinity::Asio::IoContext& ioContext) realm.LocalAddress = Trinity::make_unique(localAddress->address()); - Optional localSubmask = Trinity::Net::Resolve(resolver, boost::asio::ip::tcp::v4(), fields[4].GetString(), ""); + Optional localSubmask = resolver.Resolve(boost::asio::ip::tcp::v4(), fields[4].GetString(), ""); if (!localSubmask) { TC_LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[4].GetString().c_str());