feat(common): introduce common networking and CLI infrastructure
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user