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

(cherry picked from commit 980f28d2ce099f524abdb6faed3fe59ce4c0963a)

# Conflicts:
#	src/server/authserver/Server/AuthSocketMgr.h
#	src/server/game/Server/WorldSocketMgr.cpp
This commit is contained in:
DDuarte
2016-03-28 02:36:58 +01:00
parent 06b3bca0d2
commit 423bded9a6
6 changed files with 18 additions and 16 deletions
@@ -17,9 +17,9 @@
#include "SessionManager.h"
bool Battlenet::SessionManager::StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port)
bool Battlenet::SessionManager::StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port, int threadCount)
{
if (!BaseSocketMgr::StartNetwork(service, bindIp, port))
if (!BaseSocketMgr::StartNetwork(service, bindIp, port, 1))
return false;
_acceptor->SetSocketFactory(std::bind(&BaseSocketMgr::GetSocketForAccept, this));
@@ -53,7 +53,7 @@ namespace Battlenet
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;
// noop for now, will be needed later to broadcast realmlist updates for example
void AddSession(Session* /*session*/);
+2 -2
View File
@@ -58,7 +58,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);
@@ -76,7 +76,7 @@ bool WorldSocketMgr::StartNetwork(boost::asio::io_service& service, std::string
return false;
}
BaseSocketMgr::StartNetwork(service, bindIp, port);
BaseSocketMgr::StartNetwork(service, bindIp, port, threadCount);
_instanceAcceptor = new AsyncAcceptor(service, bindIp, uint16(sWorld->getIntConfig(CONFIG_PORT_INSTANCE)));
_acceptor->SetSocketFactory(std::bind(&BaseSocketMgr::GetSocketForAccept, this));
+1 -1
View File
@@ -40,7 +40,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;
+3 -9
View File
@@ -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);
+9 -1
View File
@@ -221,7 +221,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);