feat(common): introduce common networking and CLI infrastructure

This commit is contained in:
Ваше Имя
2025-09-30 18:33:06 +04:00
parent ad9b11cdbd
commit ba91359db3
12 changed files with 385 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
#include "tcp_server_base.hpp"
#include "logger.hpp"
TcpServerBase::TcpServerBase(IoContext &io, unsigned short port)
: acceptor_(io, TcpEndpoint(boost::asio::ip::tcp::v4(), port))
{
}
void TcpServerBase::start()
{
auto doAccept = [this]() {
acceptor_.async_accept([this](ErrorCode ec, TcpSocket socket) {
if (!ec) {
Logger::info("New client connected");
createSession(std::move(socket));
} else {
Logger::error("Accept error: " + ec.message());
}
start(); // continue accepting
});
};
doAccept();
}