From c306c4233a52f8392f3a31e1029d7ac847fce7d8 Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Thu, 5 Feb 2026 13:50:40 +0000 Subject: [PATCH] refactor: integrate shared io_context across all services --- README.md | 3 +++ include/NetworkService.h | 5 +++-- server/NetworkService.cpp | 6 ++++-- server/main.cpp | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7431282..5c6b5a7 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,6 @@ cmake --build build - SessionManager: 글로벌 세션 관리 및 브로드캐스팅 - DatabaseManager: 비동기 데이터베이스 작업 및 락 제어 - Packet: 바이너리 프로토콜 정의 (pragma pack(1)) + +## TODO: 완성도 위한 개선 +- 진행중인 검 상태 저장 후 재접속 시 복구 \ No newline at end of file diff --git a/include/NetworkService.h b/include/NetworkService.h index 4a3d27a..a187b7b 100644 --- a/include/NetworkService.h +++ b/include/NetworkService.h @@ -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 threads_; tcp::acceptor acceptor_; boost::asio::executor_work_guard diff --git a/server/NetworkService.cpp b/server/NetworkService.cpp index 2a13784..f126266 100644 --- a/server/NetworkService.cpp +++ b/server/NetworkService.cpp @@ -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) { diff --git a/server/main.cpp b/server/main.cpp index 3270f08..9abedd4 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -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);