mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Network: Refactor AsyncAcceptor to use async_accept overload producing sockets through argument instead of having to preallocate it
* Also improve main() cleanup to fully process all queued async operations (including their cancellations)
This commit is contained in:
@@ -268,7 +268,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
// Set signal handlers (this must be done before starting IoContext threads, because otherwise they would unblock and exit)
|
||||
boost::asio::signal_set signals(*ioContext, SIGINT, SIGTERM);
|
||||
boost::asio::basic_signal_set<Trinity::Asio::IoContext::Executor> signals(*ioContext, SIGINT, SIGTERM);
|
||||
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
|
||||
signals.add(SIGBREAK);
|
||||
#endif
|
||||
@@ -284,7 +284,7 @@ int main(int argc, char** argv)
|
||||
for (int i = 0; i < numThreads; ++i)
|
||||
threadPool->PostWork([ioContext]() { ioContext->run(); });
|
||||
|
||||
auto ioContextStopHandle = Trinity::make_unique_ptr_with_deleter<&Trinity::Asio::IoContext::stop>(ioContext.get());
|
||||
auto signalsCancelHandle = Trinity::make_unique_ptr_with_deleter<[](auto* s) { boost::system::error_code ec; s->cancel(ec); }>(&signals);
|
||||
|
||||
// Set process priority according to configuration settings
|
||||
SetProcessPriority("server.worldserver", sConfigMgr->GetIntDefault(CONFIG_PROCESSOR_AFFINITY, 0), sConfigMgr->GetBoolDefault(CONFIG_HIGH_PRIORITY, false));
|
||||
@@ -445,10 +445,6 @@ int main(int argc, char** argv)
|
||||
WorldPackets::Auth::ConnectTo::ShutdownEncryption();
|
||||
WorldPackets::Auth::EnterEncryptedMode::ShutdownEncryption();
|
||||
|
||||
ioContextStopHandle.reset();
|
||||
|
||||
threadPool.reset();
|
||||
|
||||
sLog->SetSynchronous();
|
||||
|
||||
sScriptMgr->OnShutdown();
|
||||
@@ -636,14 +632,14 @@ std::unique_ptr<Trinity::Net::AsyncAcceptor> StartRaSocketAcceptor(Trinity::Asio
|
||||
if (!acceptor->Bind())
|
||||
{
|
||||
TC_LOG_ERROR("server.worldserver", "Failed to bind RA socket acceptor");
|
||||
return nullptr;
|
||||
acceptor = nullptr;
|
||||
return acceptor;
|
||||
}
|
||||
|
||||
acceptor->AsyncAccept([](Trinity::Net::IoContextTcpSocket&& sock, uint32 /*threadIndex*/)
|
||||
{
|
||||
std::make_shared<RASession>(std::move(sock))->Start();
|
||||
acceptor->AsyncAccept(
|
||||
[&] { return &ioContext; },
|
||||
[](Trinity::Net::IoContextTcpSocket&& sock) { std::make_shared<RASession>(std::move(sock))->Start(); });
|
||||
|
||||
});
|
||||
return acceptor;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user