From b2e03a744813a17bf0c01c9ef010e65cac078420 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 20 Feb 2016 13:08:03 +0100 Subject: Core/Networking: Rewrite networking threading model Each network thread has its own io_service - this means that all operations on a given socket except queueing packets run from a single thread, removing the need for locking Sending packets now writes to a lockfree intermediate queue directly, encryption is applied in network thread if it was required at the time of sending the packet (cherry picked from commit 97a79af4701621ec04b88c8b548dbc35d120e99e) --- src/server/authserver/Server/AuthSession.cpp | 5 +---- src/server/authserver/Server/AuthSocketMgr.h | 15 ++++++--------- 2 files changed, 7 insertions(+), 13 deletions(-) (limited to 'src/server/authserver/Server') diff --git a/src/server/authserver/Server/AuthSession.cpp b/src/server/authserver/Server/AuthSession.cpp index 519cd1f19f7..57e5d6682f2 100644 --- a/src/server/authserver/Server/AuthSession.cpp +++ b/src/server/authserver/Server/AuthSession.cpp @@ -274,10 +274,7 @@ void AuthSession::SendPacket(ByteBuffer& packet) { MessageBuffer buffer; buffer.Write(packet.contents(), packet.size()); - - std::unique_lock guard(_writeLock); - - QueuePacket(std::move(buffer), guard); + QueuePacket(std::move(buffer)); } } diff --git a/src/server/authserver/Server/AuthSocketMgr.h b/src/server/authserver/Server/AuthSocketMgr.h index fa96502663f..a16b7d405b9 100644 --- a/src/server/authserver/Server/AuthSocketMgr.h +++ b/src/server/authserver/Server/AuthSocketMgr.h @@ -21,8 +21,6 @@ #include "SocketMgr.h" #include "AuthSession.h" -void OnSocketAccept(tcp::socket&& sock); - class AuthSocketMgr : public SocketMgr { typedef SocketMgr BaseSocketMgr; @@ -39,7 +37,7 @@ public: if (!BaseSocketMgr::StartNetwork(service, bindIp, port)) return false; - _acceptor->AsyncAcceptManaged(&OnSocketAccept); + _acceptor->AsyncAcceptWithCallback<&AuthSocketMgr::OnSocketAccept>(); return true; } @@ -48,14 +46,13 @@ protected: { return new NetworkThread[1]; } + + static void OnSocketAccept(tcp::socket&& sock, uint32 threadIndex) + { + Instance().OnSocketOpen(std::forward(sock), threadIndex); + } }; #define sAuthSocketMgr AuthSocketMgr::Instance() -void OnSocketAccept(tcp::socket&& sock) -{ - sAuthSocketMgr.OnSocketOpen(std::forward(sock)); -} - - #endif // AuthSocketMgr_h__ -- cgit v1.2.3