Skip to content

Commit

Permalink
Boost: Add 1.87 support
Browse files Browse the repository at this point in the history
Co-Authored-By: insuna <[email protected]>
  • Loading branch information
Niam5 and insunaa committed Jan 1, 2025
1 parent 0e869e4 commit 6d68e42
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 353 deletions.
2 changes: 1 addition & 1 deletion src/game/Server/WorldSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ void WorldSession::SendTransferAborted(uint32 mapid, uint8 reason, uint8 arg) co

void WorldSession::SendRedirectClient(std::string& ip, uint16 port) const
{
const uint32 ip2 = static_cast<uint32>(boost::asio::ip::address_v4::from_string(ip).to_ulong());
const uint32 ip2 = static_cast<uint32>(boost::asio::ip::make_address_v4(ip).to_uint());
WorldPacket pkt(SMSG_CONNECT_TO, 4 + 2 + 4 + 20);

pkt << uint32(ip2); // inet_addr(ipstr)
Expand Down
2 changes: 1 addition & 1 deletion src/game/Server/WorldSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ std::deque<uint32> WorldSocket::GetIncOpcodeHistory()
return m_opcodeHistoryInc;
}

WorldSocket::WorldSocket(boost::asio::io_service& service) : AsyncSocket(service), m_lastPingTime(std::chrono::system_clock::time_point::min()), m_overSpeedPings(0),
WorldSocket::WorldSocket(boost::asio::io_context& context) : AsyncSocket(context), m_lastPingTime(std::chrono::system_clock::time_point::min()), m_overSpeedPings(0),
m_session(nullptr), m_seed(urand()), m_loggingPackets(false)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/Server/WorldSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class WorldSocket : public MaNGOS::AsyncSocket<WorldSocket>
bool m_loggingPackets;

public:
WorldSocket(boost::asio::io_service& service);
WorldSocket(boost::asio::io_context& context);

// send a packet \o/
void SendPacket(const WorldPacket& pct, bool immediate = false);
Expand Down
12 changes: 6 additions & 6 deletions src/mangosd/Master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ int Master::Run()
}
std::string bindIp = sConfig.GetStringDefault("BindIP", "0.0.0.0");
int32 port = int32(sWorld.getConfig(CONFIG_UINT32_PORT_WORLD));
MaNGOS::AsyncListener<WorldSocket> listener(m_service, bindIp, port);
MaNGOS::AsyncListener<WorldSocket> listener(m_context, bindIp, port);

std::vector<std::thread> threads;
for (int32 i = 0; i < networkThreadCount; ++i)
threads.emplace_back([&]() { m_service.run(); });
threads.emplace_back([&]() { m_context.run(); });

std::unique_ptr<MaNGOS::AsyncListener<RASocket>> raListener;
std::string raBindIp = sConfig.GetStringDefault("Ra.IP", "0.0.0.0");
Expand All @@ -240,8 +240,8 @@ int Master::Run()
bool raEnable = sConfig.GetBoolDefault("Ra.Enable", false);
if (raEnable)
{
raListener.reset(new MaNGOS::AsyncListener<RASocket>(m_raService, raBindIp, raPort));
m_raThread = std::thread([this]() { m_raService.run(); });
raListener.reset(new MaNGOS::AsyncListener<RASocket>(m_raContext, raBindIp, raPort));
m_raThread = std::thread([this]() { m_raContext.run(); });
}

std::unique_ptr<SOAPThread> soapThread;
Expand All @@ -254,11 +254,11 @@ int Master::Run()

world_thread.wait();

m_service.stop();
m_context.stop();

if (raEnable)
{
m_raService.stop();
m_raContext.stop();
m_raThread.join();
}

Expand Down
4 changes: 2 additions & 2 deletions src/mangosd/Master.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class Master

void clearOnlineAccounts();

boost::asio::io_service m_service;
boost::asio::io_service m_raService;
boost::asio::io_context m_context;
boost::asio::io_context m_raContext;
};

#define sMaster MaNGOS::Singleton<Master>::Instance()
Expand Down
4 changes: 2 additions & 2 deletions src/mangosd/RASocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#include <string>

/// RASocket constructor
RASocket::RASocket(boost::asio::io_service& service) :
MaNGOS::AsyncSocket<RASocket>(service), m_secure(sConfig.GetBoolDefault("RA.Secure", true)),
RASocket::RASocket(boost::asio::io_context& context) :
MaNGOS::AsyncSocket<RASocket>(context), m_secure(sConfig.GetBoolDefault("RA.Secure", true)),
m_authLevel(AuthLevel::None), m_accountLevel(AccountTypes::SEC_PLAYER), m_accountId(0)
{
if (sConfig.IsSet("RA.Stricted"))
Expand Down
2 changes: 1 addition & 1 deletion src/mangosd/RASocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class RASocket : public MaNGOS::AsyncSocket<RASocket>
void Send(const std::string& message);

public:
RASocket(boost::asio::io_service& service);
RASocket(boost::asio::io_context& context);
virtual ~RASocket();

bool OnOpen() override;
Expand Down
4 changes: 2 additions & 2 deletions src/realmd/AuthSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ const char logonProofVersionInvalid[2] = { CMD_AUTH_LOGON_PROOF, AUTH_LOGON_FAIL
const char logonProofUnknownAccountPinInvalid[4] = { CMD_AUTH_LOGON_PROOF, AUTH_LOGON_FAILED_UNKNOWN_ACCOUNT, 3, 0 };

/// Constructor - set the N and g values for SRP6
AuthSocket::AuthSocket(boost::asio::io_service& service)
: AsyncSocket<AuthSocket>(service), _status(STATUS_CHALLENGE), _build(0), _accountSecurityLevel(SEC_PLAYER), m_timeoutTimer(service)
AuthSocket::AuthSocket(boost::asio::io_context& context)
: AsyncSocket<AuthSocket>(context), _status(STATUS_CHALLENGE), _build(0), _accountSecurityLevel(SEC_PLAYER), m_timeoutTimer(context)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/realmd/AuthSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AuthSocket : public MaNGOS::AsyncSocket<AuthSocket>
public:
const static int s_BYTE_SIZE = 32;

AuthSocket(boost::asio::io_service& service);
AuthSocket(boost::asio::io_context& context);

bool OnOpen() override;

Expand Down
8 changes: 4 additions & 4 deletions src/realmd/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool restart = false;

DatabaseType LoginDatabase; // Accessor to the realm server database

boost::asio::io_service service;
boost::asio::io_context context;

// Launch the realm server
int main(int argc, char* argv[])
Expand Down Expand Up @@ -238,14 +238,14 @@ int main(int argc, char* argv[])
LoginDatabase.CommitTransaction();

uint32 networkThreadCount = sConfig.GetIntDefault("ListenerThreads", 1);
MaNGOS::AsyncListener<AuthSocket> listener(service,
MaNGOS::AsyncListener<AuthSocket> listener(context,
sConfig.GetStringDefault("BindIP", "0.0.0.0"),
sConfig.GetIntDefault("RealmServerPort", DEFAULT_REALMSERVER_PORT)
);

std::vector<std::thread> threads;
for (uint32 i = 0; i < networkThreadCount; ++i)
threads.emplace_back([&]() { service.run(); });
threads.emplace_back([&]() { context.run(); });

// Catch termination signals
HookSignals();
Expand Down Expand Up @@ -319,7 +319,7 @@ int main(int argc, char* argv[])
#endif
}

service.stop();
context.stop();

for (uint32 i = 0; i < networkThreadCount; ++i)
threads[i].join();
Expand Down
35 changes: 20 additions & 15 deletions src/shared/Metric/Metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <boost/asio/executor_work_guard.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <functional>

Expand Down Expand Up @@ -84,12 +86,15 @@ metric::metric::~metric()
if (!m_enabled)
return;

m_writeService.post([&] {
boost::asio::post(m_writeContext, [&] {
m_sendTimer->cancel();
});

m_queueServiceWork.reset();
m_writeServiceWork.reset();
m_queueContextWork.get()->reset();
m_writeContextWork.get()->reset();

m_queueContextWork.reset();
m_writeContextWork.reset();

m_queueServiceThread.join();
m_writeServiceThread.join();
Expand All @@ -108,17 +113,17 @@ void metric::metric::initialize()
sConfig.GetStringDefault("Metric.Password", "")
};

m_sendTimer.reset(new boost::asio::deadline_timer(m_writeService));
m_queueServiceWork.reset(new boost::asio::io_service::work(m_queueService));
m_writeServiceWork.reset(new boost::asio::io_service::work(m_writeService));
m_sendTimer.reset(new boost::asio::deadline_timer(m_writeContext));
m_queueContextWork = std::make_unique<boost::asio::executor_work_guard<boost::asio::io_context::executor_type>>(boost::asio::make_work_guard(m_queueContext));
m_writeContextWork = std::make_unique<boost::asio::executor_work_guard<boost::asio::io_context::executor_type>>(boost::asio::make_work_guard(m_writeContext));

// Start up service thread that will process all queued tasks
m_queueServiceThread = std::thread([&] {
m_queueService.run();
m_queueContext.run();
});

m_writeServiceThread = std::thread([&] {
m_writeService.run();
m_writeContext.run();
});

schedule_timer();
Expand All @@ -138,7 +143,7 @@ void metric::metric::reload_config()
return;
}

m_writeService.post([&]
boost::asio::post(m_writeContext, [&]
{
m_connectionInfo = {
sConfig.GetStringDefault("Metric.Address", "127.0.0.1"),
Expand All @@ -160,7 +165,7 @@ void metric::metric::report(std::string measurement, std::map<std::string, boost
if (!m_enabled)
return;

m_queueService.post([&, measurement, fields, tags]
boost:asio:post(m_queueContext, [&, measurement, fields, tags]
{
std::lock_guard<std::mutex> guard(m_queueWriteLock);
m_measurementQueue.push_back(std::make_unique<Measurement>(measurement, tags, fields));
Expand Down Expand Up @@ -209,9 +214,9 @@ void metric::metric::send()
boost::system::error_code error;

// Hostname resolution
tcp::resolver resolver(m_writeService);
tcp::resolver::query query(m_connectionInfo.hostname, std::to_string(m_connectionInfo.port));
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query, error);
tcp::resolver resolver(m_writeContext);
auto endpoints = resolver.resolve(m_connectionInfo.hostname, std::to_string(m_connectionInfo.port), error);
auto endpoint_iterator = endpoints.begin();

if (error)
{
Expand All @@ -221,9 +226,9 @@ void metric::metric::send()

error = boost::asio::error::host_not_found;

tcp::resolver::iterator end;
auto end = endpoints.end();

tcp::socket socket(m_writeService);
tcp::socket socket(m_writeContext);
while (error && endpoint_iterator != end)
{
socket.close();
Expand Down
10 changes: 6 additions & 4 deletions src/shared/Metric/Metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <boost/any.hpp>
#include <boost/asio.hpp>
#include <boost/asio/executor_work_guard.hpp>
#include <boost/asio/io_context.hpp>
#include <chrono>
#include <functional>
#include <iostream>
Expand Down Expand Up @@ -120,12 +122,12 @@ namespace metric
void report(std::string measurement, std::map<std::string, boost::any> fields, std::map<std::string, std::string> tags = {});

private:
boost::asio::io_service m_queueService;
boost::asio::io_service m_writeService;
boost::asio::io_context m_queueContext;
boost::asio::io_context m_writeContext;

std::unique_ptr<boost::asio::deadline_timer> m_sendTimer;
std::unique_ptr<boost::asio::io_service::work> m_queueServiceWork;
std::unique_ptr<boost::asio::io_service::work> m_writeServiceWork;
std::unique_ptr<boost::asio::executor_work_guard<boost::asio::io_context::executor_type>> m_queueContextWork;
std::unique_ptr<boost::asio::executor_work_guard<boost::asio::io_context::executor_type>> m_writeContextWork;
std::thread m_queueServiceThread;
std::thread m_writeServiceThread;

Expand Down
6 changes: 3 additions & 3 deletions src/shared/Network/AsyncListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace MaNGOS
{
public:
// constructor for accepting connection from client
AsyncListener(boost::asio::io_service& io_service, std::string const& bindIp, unsigned short port) : m_service(io_service), m_acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(bindIp), port))
AsyncListener(boost::asio::io_context& io_context, std::string const& bindIp, unsigned short port) : m_context(io_context), m_acceptor(io_context, boost::asio::ip::tcp::endpoint(boost::asio::ip::make_address(bindIp), port))
{
startAccept();
}
Expand All @@ -43,12 +43,12 @@ namespace MaNGOS
startAccept();
}
private:
boost::asio::io_service& m_service;
boost::asio::io_context& m_context;
boost::asio::ip::tcp::acceptor m_acceptor;
void startAccept()
{
// socket
std::shared_ptr<SocketType> connection = std::make_shared<SocketType>(m_service);
std::shared_ptr<SocketType> connection = std::make_shared<SocketType>(m_context);

// asynchronous accept operation and wait for a new connection.
m_acceptor.async_accept(connection->GetAsioSocket(), boost::bind(&AsyncListener::HandleAccept, this, connection, boost::asio::placeholders::error));
Expand Down
4 changes: 2 additions & 2 deletions src/shared/Network/AsyncSocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace MaNGOS
class AsyncSocket : public std::enable_shared_from_this<SocketType>
{
public:
AsyncSocket(boost::asio::io_service& io_service);
AsyncSocket(boost::asio::io_context& io_context);
virtual ~AsyncSocket();

void Read(char* buffer, size_t length, std::function<void(const boost::system::error_code&, std::size_t)>&& callback);
Expand Down Expand Up @@ -74,7 +74,7 @@ namespace MaNGOS
};

template <typename SocketType>
MaNGOS::AsyncSocket<SocketType>::AsyncSocket(boost::asio::io_service& io_service) : m_socket(io_service), m_address("0.0.0.0"),
MaNGOS::AsyncSocket<SocketType>::AsyncSocket(boost::asio::io_context& io_context) : m_socket(io_context), m_address("0.0.0.0"),
m_remoteAddress(boost::asio::ip::address()), m_remotePort(0)
{

Expand Down
Loading

0 comments on commit 6d68e42

Please sign in to comment.