refactor(Core/Network): Port TrinityCore socket optimizations (#24384)

Co-authored-by: blinkysc <blinkysc@users.noreply.github.com>
Co-authored-by: Shauren <shauren@users.noreply.github.com>
This commit is contained in:
blinkysc
2026-01-15 07:47:58 -06:00
committed by GitHub
parent a8ce95ad71
commit d908b4c2fc
16 changed files with 242 additions and 75 deletions

View File

@@ -162,7 +162,7 @@ void AccountInfo::LoadResult(Field* fields)
Utf8ToUpperOnlyLatin(Login);
}
AuthSession::AuthSession(tcp::socket&& socket) :
AuthSession::AuthSession(IoContextTcpSocket&& socket) :
Socket(std::move(socket)), _status(STATUS_CHALLENGE), _build(0), _expversion(0) { }
void AuthSession::Start()
@@ -216,7 +216,7 @@ void AuthSession::CheckIpCallback(PreparedQueryResult result)
AsyncRead();
}
void AuthSession::ReadHandler()
SocketReadCallbackResult AuthSession::ReadHandler()
{
MessageBuffer& packet = GetReadBuffer();
@@ -234,7 +234,7 @@ void AuthSession::ReadHandler()
if (_status != itr->second.status)
{
CloseSocket();
return;
return SocketReadCallbackResult::Stop;
}
uint16 size = uint16(itr->second.packetSize);
@@ -248,7 +248,7 @@ void AuthSession::ReadHandler()
if (size > MAX_ACCEPTED_CHALLENGE_SIZE)
{
CloseSocket();
return;
return SocketReadCallbackResult::Stop;
}
}
@@ -258,13 +258,13 @@ void AuthSession::ReadHandler()
if (!(*this.*itr->second.handler)())
{
CloseSocket();
return;
return SocketReadCallbackResult::Stop;
}
packet.ReadCompleted(size);
}
AsyncRead();
return SocketReadCallbackResult::KeepReading;
}
void AuthSession::SendPacket(ByteBuffer& packet)

View File

@@ -60,22 +60,22 @@ struct AccountInfo
AccountTypes SecurityLevel = SEC_PLAYER;
};
class AuthSession : public Socket<AuthSession>
class AuthSession final : public Socket<AuthSession>
{
typedef Socket<AuthSession> AuthSocket;
public:
static std::unordered_map<uint8, AuthHandler> InitHandlers();
AuthSession(tcp::socket&& socket);
AuthSession(IoContextTcpSocket&& socket);
void Start() override;
bool Update() override;
bool Update() final;
void SendPacket(ByteBuffer& packet);
protected:
void ReadHandler() override;
SocketReadCallbackResult ReadHandler() final;
private:
bool HandleLogonChallenge();

View File

@@ -54,9 +54,9 @@ protected:
return threads;
}
static void OnSocketAccept(tcp::socket&& sock, uint32 threadIndex)
static void OnSocketAccept(IoContextTcpSocket&& sock, uint32 threadIndex)
{
Instance().OnSocketOpen(std::forward<tcp::socket>(sock), threadIndex);
Instance().OnSocketOpen(std::move(sock), threadIndex);
}
};

View File

@@ -18,18 +18,16 @@
#ifndef __RASESSION_H__
#define __RASESSION_H__
#include <boost/asio/ip/tcp.hpp>
#include "Socket.h"
#include <boost/asio/streambuf.hpp>
#include <future>
using boost::asio::ip::tcp;
const std::size_t bufferSize = 4096;
class RASession : public std::enable_shared_from_this<RASession>
{
public:
RASession(tcp::socket&& socket) :
RASession(IoContextTcpSocket&& socket) :
_socket(std::move(socket)), _commandExecuting(nullptr) { }
void Start();
@@ -47,7 +45,7 @@ private:
static void CommandPrint(void* callbackArg, std::string_view text);
static void CommandFinished(void* callbackArg, bool);
tcp::socket _socket;
IoContextTcpSocket _socket;
boost::asio::streambuf _readBuffer;
boost::asio::streambuf _writeBuffer;
std::promise<void>* _commandExecuting;