refactor: 시그널 관리 컨텍스트와 네트워크 서비스 컨텍스트 통합

This commit is contained in:
bumpsoo 2026-02-05 13:52:11 +00:00
parent 2d35fd6c8b
commit 57756a5f16
3 changed files with 8 additions and 5 deletions

View file

@ -8,7 +8,8 @@ using boost::asio::ip::tcp;
class NetworkService {
public:
NetworkService(uint16_t port, int threadCount);
NetworkService(boost::asio::io_context &io_context, uint16_t port,
int threadCount);
~NetworkService();
void Run();
@ -17,7 +18,7 @@ public:
private:
void DoAccept();
boost::asio::io_context io_context_;
boost::asio::io_context &io_context_;
std::vector<std::jthread> threads_;
tcp::acceptor acceptor_;
boost::asio::executor_work_guard<boost::asio::io_context::executor_type>

View file

@ -2,8 +2,10 @@
#include "Logger.h"
#include "Session.h"
NetworkService::NetworkService(uint16_t port, int threadCount)
: acceptor_(io_context_, tcp::endpoint(tcp::v4(), port)),
NetworkService::NetworkService(boost::asio::io_context &io_context,
uint16_t port, int threadCount)
: io_context_(io_context),
acceptor_(io_context_, tcp::endpoint(tcp::v4(), port)),
work_guard_(boost::asio::make_work_guard(io_context_)) {
threads_.reserve(threadCount);
for (int i = 0; i < threadCount; ++i) {

View file

@ -32,7 +32,7 @@ int main() {
return 1;
}
NetworkService server(port, threadCount);
NetworkService server(main_context, port, threadCount);
server.Run();
boost::asio::signal_set signals(main_context, SIGINT, SIGTERM);