mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Network: Change SocketMgr.StartNetwork to take the thread count by arg instead of config
AuthSocketMgr doesn't need "Network.Threads" config Fixes "Missing name Network.Threads in config file authserver.conf" Ref #16859
This commit is contained in:
@@ -32,9 +32,9 @@ public:
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port) override
|
||||
bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port, int threadCount = 1) override
|
||||
{
|
||||
if (!BaseSocketMgr::StartNetwork(service, bindIp, port))
|
||||
if (!BaseSocketMgr::StartNetwork(service, bindIp, port, threadCount))
|
||||
return false;
|
||||
|
||||
_acceptor->AsyncAcceptWithCallback<&AuthSocketMgr::OnSocketAccept>();
|
||||
|
||||
@@ -53,7 +53,7 @@ WorldSocketMgr& WorldSocketMgr::Instance()
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool WorldSocketMgr::StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port)
|
||||
bool WorldSocketMgr::StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port, int threadCount)
|
||||
{
|
||||
_tcpNoDelay = sConfigMgr->GetBoolDefault("Network.TcpNodelay", true);
|
||||
|
||||
@@ -71,7 +71,7 @@ bool WorldSocketMgr::StartNetwork(boost::asio::io_service& service, std::string
|
||||
return false;
|
||||
}
|
||||
|
||||
BaseSocketMgr::StartNetwork(service, bindIp, port);
|
||||
BaseSocketMgr::StartNetwork(service, bindIp, port, threadCount);
|
||||
|
||||
_acceptor->SetSocketFactory(std::bind(&BaseSocketMgr::GetSocketForAccept, this));
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
static WorldSocketMgr& Instance();
|
||||
|
||||
/// Start network, listen at address:port .
|
||||
bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port) override;
|
||||
bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port, int networkThreads) override;
|
||||
|
||||
/// Stops all network threads, It will wait for all running threads .
|
||||
void StopNetwork() override;
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#define SocketMgr_h__
|
||||
|
||||
#include "AsyncAcceptor.h"
|
||||
#include "Config.h"
|
||||
#include "Errors.h"
|
||||
#include "NetworkThread.h"
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
@@ -36,15 +35,9 @@ public:
|
||||
ASSERT(!_threads && !_acceptor && !_threadCount, "StopNetwork must be called prior to SocketMgr destruction");
|
||||
}
|
||||
|
||||
virtual bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port)
|
||||
virtual bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port, int threadCount)
|
||||
{
|
||||
_threadCount = sConfigMgr->GetIntDefault("Network.Threads", 1);
|
||||
|
||||
if (_threadCount <= 0)
|
||||
{
|
||||
TC_LOG_ERROR("misc", "Network.Threads is wrong in your config file");
|
||||
return false;
|
||||
}
|
||||
ASSERT(threadCount > 0);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -56,6 +49,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
_threadCount = threadCount;
|
||||
_threads = CreateThreads();
|
||||
|
||||
ASSERT(_threads);
|
||||
|
||||
@@ -222,7 +222,15 @@ extern int main(int argc, char** argv)
|
||||
uint16 worldPort = uint16(sWorld->getIntConfig(CONFIG_PORT_WORLD));
|
||||
std::string worldListener = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
|
||||
|
||||
sWorldSocketMgr.StartNetwork(_ioService, worldListener, worldPort);
|
||||
int networkThreads = sConfigMgr->GetIntDefault("Network.Threads", 1);
|
||||
|
||||
if (networkThreads <= 0)
|
||||
{
|
||||
TC_LOG_ERROR("server.worldserver", "Network.Threads cannot be less than 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
sWorldSocketMgr.StartNetwork(_ioService, worldListener, worldPort, networkThreads);
|
||||
|
||||
// Set server online (allow connecting now)
|
||||
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = flag & ~%u, population = 0 WHERE id = '%u'", REALM_FLAG_OFFLINE, realm.Id.Realm);
|
||||
|
||||
Reference in New Issue
Block a user