aboutsummaryrefslogtreecommitdiff
path: root/src/server/worldserver
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-04-08 19:15:16 +0200
committerShauren <shauren.trinity@gmail.com>2025-04-08 19:15:16 +0200
commite8b2be3527c7683e8bfca70ed7706fc20da566fd (patch)
tree54d5099554c8628cad719e6f1a49d387c7eced4f /src/server/worldserver
parent40d80f3476ade4898be24659408e82aa4234b099 (diff)
Core/Network: Socket refactors
* Devirtualize calls to Read and Update by marking concrete implementations as final * Removed derived class template argument * Specialize boost::asio::basic_stream_socket for boost::asio::io_context instead of type-erased any_io_executor * Make socket initialization easier composable (before entering Read loop) * Remove use of deprecated boost::asio::null_buffers and boost::beast::ssl_stream
Diffstat (limited to 'src/server/worldserver')
-rw-r--r--src/server/worldserver/Main.cpp22
-rw-r--r--src/server/worldserver/RemoteAccess/RASession.cpp4
-rw-r--r--src/server/worldserver/RemoteAccess/RASession.h9
3 files changed, 18 insertions, 17 deletions
diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp
index a482d109890..ba5c8f9c758 100644
--- a/src/server/worldserver/Main.cpp
+++ b/src/server/worldserver/Main.cpp
@@ -15,10 +15,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/// \addtogroup Trinityd Trinity Daemon
-/// @{
-/// \file
-
#include "Common.h"
#include "AppenderDB.h"
#include "AsyncAcceptor.h"
@@ -122,7 +118,7 @@ private:
};
void SignalHandler(boost::system::error_code const& error, int signalNumber);
-AsyncAcceptor* StartRaSocketAcceptor(Trinity::Asio::IoContext& ioContext);
+std::unique_ptr<Trinity::Net::AsyncAcceptor> StartRaSocketAcceptor(Trinity::Asio::IoContext& ioContext);
bool StartDB();
void StopDB();
void WorldUpdateLoop();
@@ -372,9 +368,9 @@ int main(int argc, char** argv)
auto battlegroundMgrHandle = Trinity::make_unique_ptr_with_deleter<&BattlegroundMgr::DeleteAllBattlegrounds>(sBattlegroundMgr);
// Start the Remote Access port (acceptor) if enabled
- std::unique_ptr<AsyncAcceptor> raAcceptor;
+ std::unique_ptr<Trinity::Net::AsyncAcceptor> raAcceptor;
if (sConfigMgr->GetBoolDefault("Ra.Enable", false))
- raAcceptor.reset(StartRaSocketAcceptor(*ioContext));
+ raAcceptor = StartRaSocketAcceptor(*ioContext);
// Start soap serving thread if enabled
std::unique_ptr<std::thread, ShutdownTCSoapThread> soapThread;
@@ -632,20 +628,23 @@ void FreezeDetector::Handler(std::weak_ptr<FreezeDetector> freezeDetectorRef, bo
}
}
-AsyncAcceptor* StartRaSocketAcceptor(Trinity::Asio::IoContext& ioContext)
+std::unique_ptr<Trinity::Net::AsyncAcceptor> StartRaSocketAcceptor(Trinity::Asio::IoContext& ioContext)
{
uint16 raPort = uint16(sConfigMgr->GetIntDefault("Ra.Port", 3443));
std::string raListener = sConfigMgr->GetStringDefault("Ra.IP", "0.0.0.0");
- AsyncAcceptor* acceptor = new AsyncAcceptor(ioContext, raListener, raPort);
+ std::unique_ptr<Trinity::Net::AsyncAcceptor> acceptor = std::make_unique<Trinity::Net::AsyncAcceptor>(ioContext, raListener, raPort);
if (!acceptor->Bind())
{
TC_LOG_ERROR("server.worldserver", "Failed to bind RA socket acceptor");
- delete acceptor;
return nullptr;
}
- acceptor->AsyncAccept<RASession>();
+ acceptor->AsyncAccept([](Trinity::Net::IoContextTcpSocket&& sock, uint32 /*threadIndex*/)
+ {
+ std::make_shared<RASession>(std::move(sock))->Start();
+
+ });
return acceptor;
}
@@ -696,7 +695,6 @@ void ClearOnlineAccounts(uint32 realmId)
// Battleground instance ids reset at server restart
CharacterDatabase.DirectExecute("UPDATE character_battleground_data SET instanceId = 0");
}
-/// @}
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, fs::path& configDir, [[maybe_unused]] std::string& winServiceAction)
{
diff --git a/src/server/worldserver/RemoteAccess/RASession.cpp b/src/server/worldserver/RemoteAccess/RASession.cpp
index b4e9e6317be..910cfdf5e4f 100644
--- a/src/server/worldserver/RemoteAccess/RASession.cpp
+++ b/src/server/worldserver/RemoteAccess/RASession.cpp
@@ -29,9 +29,11 @@
void RASession::Start()
{
+ _socket.non_blocking(false);
+
// wait 1 second for active connections to send negotiation request
for (int counter = 0; counter < 10 && _socket.available() == 0; counter++)
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ std::this_thread::sleep_for(100ms);
// Check if there are bytes available, if they are, then the client is requesting the negotiation
if (_socket.available() > 0)
diff --git a/src/server/worldserver/RemoteAccess/RASession.h b/src/server/worldserver/RemoteAccess/RASession.h
index e0f4b373f74..23fd4e70c55 100644
--- a/src/server/worldserver/RemoteAccess/RASession.h
+++ b/src/server/worldserver/RemoteAccess/RASession.h
@@ -15,10 +15,11 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef __RASESSION_H__
-#define __RASESSION_H__
+#ifndef TRINITYCORE_RA_SESSION_H
+#define TRINITYCORE_RA_SESSION_H
#include "Define.h"
+#include "Socket.h"
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/streambuf.hpp>
#include <future>
@@ -29,7 +30,7 @@ const size_t bufferSize = 4096;
class RASession : public std::enable_shared_from_this <RASession>
{
public:
- RASession(boost::asio::ip::tcp::socket&& socket) : _socket(std::move(socket)), _commandExecuting(nullptr)
+ RASession(Trinity::Net::IoContextTcpSocket&& socket) : _socket(std::move(socket)), _commandExecuting(nullptr)
{
}
@@ -47,7 +48,7 @@ private:
static void CommandPrint(void* callbackArg, std::string_view text);
static void CommandFinished(void* callbackArg, bool);
- boost::asio::ip::tcp::socket _socket;
+ Trinity::Net::IoContextTcpSocket _socket;
boost::asio::streambuf _readBuffer;
boost::asio::streambuf _writeBuffer;
std::promise<void>* _commandExecuting;