feat: server, client 디렉토리 조정 및 client 헤더 파일 추가. 시나리오
혹은 대화형 클라이언트로 수정
This commit is contained in:
parent
b887f15662
commit
1d103d7f16
12 changed files with 281 additions and 112 deletions
32
server/NetworkService.cpp
Normal file
32
server/NetworkService.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include "NetworkService.h"
|
||||
#include "Logger.h"
|
||||
#include "Session.h"
|
||||
|
||||
NetworkService::NetworkService(uint16_t port, int threadCount)
|
||||
: 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) {
|
||||
threads_.emplace_back([this]() { io_context_.run(); });
|
||||
}
|
||||
}
|
||||
|
||||
NetworkService::~NetworkService() { Stop(); }
|
||||
|
||||
void NetworkService::Run() {
|
||||
Logger::Log("서버가 포트 ", acceptor_.local_endpoint().port(),
|
||||
"에서 리스닝을 시작했습니다.");
|
||||
DoAccept();
|
||||
}
|
||||
|
||||
void NetworkService::Stop() { io_context_.stop(); }
|
||||
|
||||
void NetworkService::DoAccept() {
|
||||
acceptor_.async_accept(
|
||||
[this](boost::system::error_code ec, tcp::socket socket) {
|
||||
if (!ec) {
|
||||
std::make_shared<Session>(std::move(socket))->Start();
|
||||
}
|
||||
DoAccept();
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue