Core/Misc: Added compatibility layer for boost 1.66 and future std:: networking stuff

* Based on work done by @dimiandre in PR #21173

Closes #21171
Closes #21173
This commit is contained in:
Shauren
2018-01-06 01:21:59 +01:00
parent 76577ddc3c
commit dfd2660a85
33 changed files with 474 additions and 190 deletions

View File

@@ -64,12 +64,12 @@ char serviceDescription[] = "TrinityCore Battle.net emulator authentication serv
*/
int m_ServiceStatus = -1;
void ServiceStatusWatcher(std::weak_ptr<boost::asio::deadline_timer> serviceStatusWatchTimerRef, std::weak_ptr<boost::asio::io_service> ioServiceRef, boost::system::error_code const& error);
void ServiceStatusWatcher(std::weak_ptr<boost::asio::deadline_timer> serviceStatusWatchTimerRef, std::weak_ptr<Trinity::Asio::IoContext> ioContextRef, boost::system::error_code const& error);
#endif
bool StartDB();
void StopDB();
void SignalHandler(std::weak_ptr<boost::asio::io_service> ioServiceRef, boost::system::error_code const& error, int signalNumber);
void SignalHandler(std::weak_ptr<Trinity::Asio::IoContext> ioContextRef, boost::system::error_code const& error, int signalNumber);
void KeepDatabaseAliveHandler(std::weak_ptr<boost::asio::deadline_timer> dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error);
void BanExpiryHandler(std::weak_ptr<boost::asio::deadline_timer> banExpiryCheckTimerRef, int32 banExpiryCheckInterval, boost::system::error_code const& error);
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& configService);
@@ -153,7 +153,7 @@ int main(int argc, char** argv)
std::shared_ptr<void> dbHandle(nullptr, [](void*) { StopDB(); });
std::shared_ptr<boost::asio::io_service> ioService = std::make_shared<boost::asio::io_service>();
std::shared_ptr<Trinity::Asio::IoContext> ioContext = std::make_shared<Trinity::Asio::IoContext>();
// Start the listening port (acceptor) for auth connections
int32 bnport = sConfigMgr->GetIntDefault("BattlenetPort", 1119);
@@ -163,7 +163,7 @@ int main(int argc, char** argv)
return 1;
}
if (!sLoginService.Start(ioService.get()))
if (!sLoginService.Start(ioContext.get()))
{
TC_LOG_ERROR("server.bnetserver", "Failed to initialize login service");
return 1;
@@ -172,13 +172,13 @@ int main(int argc, char** argv)
std::shared_ptr<void> sLoginServiceHandle(nullptr, [](void*) { sLoginService.Stop(); });
// Get the list of realms for the server
sRealmList->Initialize(*ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10));
sRealmList->Initialize(*ioContext, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10));
std::shared_ptr<void> sRealmListHandle(nullptr, [](void*) { sRealmList->Close(); });
std::string bindIp = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
if (!sSessionMgr.StartNetwork(*ioService, bindIp, bnport))
if (!sSessionMgr.StartNetwork(*ioContext, bindIp, bnport))
{
TC_LOG_ERROR("server.bnetserver", "Failed to initialize network");
return 1;
@@ -187,23 +187,23 @@ int main(int argc, char** argv)
std::shared_ptr<void> sSessionMgrHandle(nullptr, [](void*) { sSessionMgr.StopNetwork(); });
// Set signal handlers
boost::asio::signal_set signals(*ioService, SIGINT, SIGTERM);
boost::asio::signal_set signals(*ioContext, SIGINT, SIGTERM);
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
signals.add(SIGBREAK);
#endif
signals.async_wait(std::bind(&SignalHandler, std::weak_ptr<boost::asio::io_service>(ioService), std::placeholders::_1, std::placeholders::_2));
signals.async_wait(std::bind(&SignalHandler, std::weak_ptr<Trinity::Asio::IoContext>(ioContext), std::placeholders::_1, std::placeholders::_2));
// Set process priority according to configuration settings
SetProcessPriority("server.bnetserver", sConfigMgr->GetIntDefault(CONFIG_PROCESSOR_AFFINITY, 0), sConfigMgr->GetBoolDefault(CONFIG_HIGH_PRIORITY, false));
// Enabled a timed callback for handling the database keep alive ping
int32 dbPingInterval = sConfigMgr->GetIntDefault("MaxPingTime", 30);
std::shared_ptr<boost::asio::deadline_timer> dbPingTimer = std::make_shared<boost::asio::deadline_timer>(*ioService);
std::shared_ptr<boost::asio::deadline_timer> dbPingTimer = std::make_shared<boost::asio::deadline_timer>(*ioContext);
dbPingTimer->expires_from_now(boost::posix_time::minutes(dbPingInterval));
dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, std::weak_ptr<boost::asio::deadline_timer>(dbPingTimer), dbPingInterval, std::placeholders::_1));
int32 banExpiryCheckInterval = sConfigMgr->GetIntDefault("BanExpiryCheckInterval", 60);
std::shared_ptr<boost::asio::deadline_timer> banExpiryCheckTimer = std::make_shared<boost::asio::deadline_timer>(*ioService);
std::shared_ptr<boost::asio::deadline_timer> banExpiryCheckTimer = std::make_shared<boost::asio::deadline_timer>(*ioContext);
banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(banExpiryCheckInterval));
banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, std::weak_ptr<boost::asio::deadline_timer>(banExpiryCheckTimer), banExpiryCheckInterval, std::placeholders::_1));
@@ -211,17 +211,17 @@ int main(int argc, char** argv)
std::shared_ptr<boost::asio::deadline_timer> serviceStatusWatchTimer;
if (m_ServiceStatus != -1)
{
serviceStatusWatchTimer = std::make_shared<boost::asio::deadline_timer>(*ioService);
serviceStatusWatchTimer = std::make_shared<boost::asio::deadline_timer>(*ioContext);
serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1));
serviceStatusWatchTimer->async_wait(std::bind(&ServiceStatusWatcher,
std::weak_ptr<boost::asio::deadline_timer>(serviceStatusWatchTimer),
std::weak_ptr<boost::asio::io_service>(ioService),
std::weak_ptr<Trinity::Asio::IoContext>(ioContext),
std::placeholders::_1));
}
#endif
// Start the io service worker loop
ioService->run();
ioContext->run();
banExpiryCheckTimer->cancel();
dbPingTimer->cancel();
@@ -258,11 +258,11 @@ void StopDB()
MySQL::Library_End();
}
void SignalHandler(std::weak_ptr<boost::asio::io_service> ioServiceRef, boost::system::error_code const& error, int /*signalNumber*/)
void SignalHandler(std::weak_ptr<Trinity::Asio::IoContext> ioContextRef, boost::system::error_code const& error, int /*signalNumber*/)
{
if (!error)
if (std::shared_ptr<boost::asio::io_service> ioService = ioServiceRef.lock())
ioService->stop();
if (std::shared_ptr<Trinity::Asio::IoContext> ioContext = ioContextRef.lock())
ioContext->stop();
}
void KeepDatabaseAliveHandler(std::weak_ptr<boost::asio::deadline_timer> dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error)
@@ -297,20 +297,20 @@ void BanExpiryHandler(std::weak_ptr<boost::asio::deadline_timer> banExpiryCheckT
}
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
void ServiceStatusWatcher(std::weak_ptr<boost::asio::deadline_timer> serviceStatusWatchTimerRef, std::weak_ptr<boost::asio::io_service> ioServiceRef, boost::system::error_code const& error)
void ServiceStatusWatcher(std::weak_ptr<boost::asio::deadline_timer> serviceStatusWatchTimerRef, std::weak_ptr<Trinity::Asio::IoContext> ioContextRef, boost::system::error_code const& error)
{
if (!error)
{
if (std::shared_ptr<boost::asio::io_service> ioService = ioServiceRef.lock())
if (std::shared_ptr<Trinity::Asio::IoContext> ioContext = ioContextRef.lock())
{
if (m_ServiceStatus == 0)
{
ioService->stop();
ioContext->stop();
}
else if (std::shared_ptr<boost::asio::deadline_timer> serviceStatusWatchTimer = serviceStatusWatchTimerRef.lock())
{
serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1));
serviceStatusWatchTimer->async_wait(std::bind(&ServiceStatusWatcher, serviceStatusWatchTimerRef, ioService, std::placeholders::_1));
serviceStatusWatchTimer->async_wait(std::bind(&ServiceStatusWatcher, serviceStatusWatchTimerRef, ioContext, std::placeholders::_1));
}
}
}