sword_game/include/NetworkService.h

26 lines
524 B
C++

#pragma once
#include <boost/asio.hpp>
#include <thread>
#include <vector>
using boost::asio::ip::tcp;
class NetworkService {
public:
NetworkService(boost::asio::io_context &io_context, uint16_t port,
int threadCount);
~NetworkService();
void Run();
void Stop();
private:
void DoAccept();
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>
work_guard_;
};