refactor: integrate shared io_context across all services
This commit is contained in:
parent
2d35fd6c8b
commit
c306c4233a
4 changed files with 11 additions and 5 deletions
|
|
@ -51,3 +51,6 @@ cmake --build build
|
||||||
- SessionManager: 글로벌 세션 관리 및 브로드캐스팅
|
- SessionManager: 글로벌 세션 관리 및 브로드캐스팅
|
||||||
- DatabaseManager: 비동기 데이터베이스 작업 및 락 제어
|
- DatabaseManager: 비동기 데이터베이스 작업 및 락 제어
|
||||||
- Packet: 바이너리 프로토콜 정의 (pragma pack(1))
|
- Packet: 바이너리 프로토콜 정의 (pragma pack(1))
|
||||||
|
|
||||||
|
## TODO: 완성도 위한 개선
|
||||||
|
- 진행중인 검 상태 저장 후 재접속 시 복구
|
||||||
|
|
@ -8,7 +8,8 @@ using boost::asio::ip::tcp;
|
||||||
|
|
||||||
class NetworkService {
|
class NetworkService {
|
||||||
public:
|
public:
|
||||||
NetworkService(uint16_t port, int threadCount);
|
NetworkService(boost::asio::io_context &io_context, uint16_t port,
|
||||||
|
int threadCount);
|
||||||
~NetworkService();
|
~NetworkService();
|
||||||
|
|
||||||
void Run();
|
void Run();
|
||||||
|
|
@ -17,7 +18,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void DoAccept();
|
void DoAccept();
|
||||||
|
|
||||||
boost::asio::io_context io_context_;
|
boost::asio::io_context &io_context_;
|
||||||
std::vector<std::jthread> threads_;
|
std::vector<std::jthread> threads_;
|
||||||
tcp::acceptor acceptor_;
|
tcp::acceptor acceptor_;
|
||||||
boost::asio::executor_work_guard<boost::asio::io_context::executor_type>
|
boost::asio::executor_work_guard<boost::asio::io_context::executor_type>
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Session.h"
|
#include "Session.h"
|
||||||
|
|
||||||
NetworkService::NetworkService(uint16_t port, int threadCount)
|
NetworkService::NetworkService(boost::asio::io_context &io_context,
|
||||||
: acceptor_(io_context_, tcp::endpoint(tcp::v4(), port)),
|
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_)) {
|
work_guard_(boost::asio::make_work_guard(io_context_)) {
|
||||||
threads_.reserve(threadCount);
|
threads_.reserve(threadCount);
|
||||||
for (int i = 0; i < threadCount; ++i) {
|
for (int i = 0; i < threadCount; ++i) {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ int main() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkService server(port, threadCount);
|
NetworkService server(main_context, port, threadCount);
|
||||||
server.Run();
|
server.Run();
|
||||||
|
|
||||||
boost::asio::signal_set signals(main_context, SIGINT, SIGTERM);
|
boost::asio::signal_set signals(main_context, SIGINT, SIGTERM);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue