mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-28 14:35:57 +00:00
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:
@@ -116,7 +116,7 @@ void EncryptableAndCompressiblePacket::CompressIfNeeded()
|
||||
SetOpcode(SMSG_COMPRESSED_UPDATE_OBJECT);
|
||||
}
|
||||
|
||||
WorldSocket::WorldSocket(tcp::socket&& socket)
|
||||
WorldSocket::WorldSocket(IoContextTcpSocket&& socket)
|
||||
: Socket(std::move(socket)), _OverSpeedPings(0), _worldSession(nullptr), _authed(false), _sendBufferSize(4096), _loggingPackets(false)
|
||||
{
|
||||
Acore::Crypto::GetRandomBytes(_authSeed);
|
||||
@@ -238,10 +238,10 @@ void WorldSocket::OnClose()
|
||||
}
|
||||
}
|
||||
|
||||
void WorldSocket::ReadHandler()
|
||||
SocketReadCallbackResult WorldSocket::ReadHandler()
|
||||
{
|
||||
if (!IsOpen())
|
||||
return;
|
||||
return SocketReadCallbackResult::Stop;
|
||||
|
||||
MessageBuffer& packet = GetReadBuffer();
|
||||
while (packet.GetActiveSize() > 0)
|
||||
@@ -264,7 +264,7 @@ void WorldSocket::ReadHandler()
|
||||
if (!ReadHeaderHandler())
|
||||
{
|
||||
CloseSocket();
|
||||
return;
|
||||
return SocketReadCallbackResult::Stop;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,11 +295,11 @@ void WorldSocket::ReadHandler()
|
||||
CloseSocket();
|
||||
}
|
||||
|
||||
return;
|
||||
return SocketReadCallbackResult::Stop;
|
||||
}
|
||||
}
|
||||
|
||||
AsyncRead();
|
||||
return SocketReadCallbackResult::KeepReading;
|
||||
}
|
||||
|
||||
bool WorldSocket::ReadHeaderHandler()
|
||||
|
||||
@@ -67,19 +67,19 @@ struct ClientPktHeader
|
||||
|
||||
struct AuthSession;
|
||||
|
||||
class AC_GAME_API WorldSocket : public Socket<WorldSocket>
|
||||
class AC_GAME_API WorldSocket final : public Socket<WorldSocket>
|
||||
{
|
||||
typedef Socket<WorldSocket> BaseSocket;
|
||||
|
||||
public:
|
||||
WorldSocket(tcp::socket&& socket);
|
||||
WorldSocket(IoContextTcpSocket&& socket);
|
||||
~WorldSocket();
|
||||
|
||||
WorldSocket(WorldSocket const& right) = delete;
|
||||
WorldSocket& operator=(WorldSocket const& right) = delete;
|
||||
|
||||
void Start() override;
|
||||
bool Update() override;
|
||||
bool Update() final;
|
||||
|
||||
void SendPacket(WorldPacket const& packet);
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
|
||||
protected:
|
||||
void OnClose() override;
|
||||
void ReadHandler() override;
|
||||
SocketReadCallbackResult ReadHandler() final;
|
||||
bool ReadHeaderHandler();
|
||||
|
||||
enum class ReadDataHandlerResult
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
class WorldSocketThread : public NetworkThread<WorldSocket>
|
||||
{
|
||||
public:
|
||||
void SocketAdded(std::shared_ptr<WorldSocket> sock) override
|
||||
void SocketAdded(std::shared_ptr<WorldSocket> const& sock) override
|
||||
{
|
||||
sock->SetSendBufferSize(sWorldSocketMgr.GetApplicationSendBufferSize());
|
||||
sScriptMgr->OnSocketOpen(sock);
|
||||
}
|
||||
|
||||
void SocketRemoved(std::shared_ptr<WorldSocket> sock) override
|
||||
void SocketRemoved(std::shared_ptr<WorldSocket> const& sock) override
|
||||
{
|
||||
sScriptMgr->OnSocketClose(sock);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ void WorldSocketMgr::StopNetwork()
|
||||
sScriptMgr->OnNetworkStop();
|
||||
}
|
||||
|
||||
void WorldSocketMgr::OnSocketOpen(tcp::socket&& sock, uint32 threadIndex)
|
||||
void WorldSocketMgr::OnSocketOpen(IoContextTcpSocket&& sock, uint32 threadIndex)
|
||||
{
|
||||
// set some options here
|
||||
if (_socketSystemSendBufferSize >= 0)
|
||||
@@ -109,7 +109,7 @@ void WorldSocketMgr::OnSocketOpen(tcp::socket&& sock, uint32 threadIndex)
|
||||
}
|
||||
}
|
||||
|
||||
BaseSocketMgr::OnSocketOpen(std::forward<tcp::socket>(sock), threadIndex);
|
||||
BaseSocketMgr::OnSocketOpen(std::move(sock), threadIndex);
|
||||
}
|
||||
|
||||
NetworkThread<WorldSocket>* WorldSocketMgr::CreateThreads() const
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
/// Stops all network threads, It will wait for all running threads .
|
||||
void StopNetwork() override;
|
||||
|
||||
void OnSocketOpen(tcp::socket&& sock, uint32 threadIndex) override;
|
||||
void OnSocketOpen(IoContextTcpSocket&& sock, uint32 threadIndex) override;
|
||||
|
||||
std::size_t GetApplicationSendBufferSize() const { return _socketApplicationSendBufferSize; }
|
||||
|
||||
@@ -50,9 +50,9 @@ protected:
|
||||
|
||||
NetworkThread<WorldSocket>* CreateThreads() const override;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user