4#include <boost/asio/detached.hpp>
5#include <boost/asio/co_spawn.hpp>
6#include <boost/asio/read.hpp>
7#include <boost/asio/write.hpp>
27 boost::asio::local::stream_protocol::socket &&
socket
44 const size_t result =
co_await boost::asio::async_read
47 boost::asio::buffer(
buffer.data + offset, size),
48 boost::asio::use_awaitable
58 co_await boost::asio::async_write
62 boost::asio::use_awaitable
70 std::string s = std::to_string(
id) +
": ";
81 boost::asio::awaitable<void> Server::listener()
87 co_await acceptor.async_accept(boost::asio::use_awaitable)
90 auto*
const session_ptr = session.get();
96 [ending_session = std::move(session),
this]
98 std::exception_ptr exception_ptr
101 ending_session->cleanup();
103 ending_session->log(
"stop");
104 if (exception_ptr && log_level > 1)
108 std::rethrow_exception(exception_ptr);
110 catch (const std::exception &e)
113 ending_session->log(std::string(
"exception: ") + e.what());
146 [
this](
const boost::system::error_code &error,
int signal)
150 if (this->log_level > 0)
152 if (signal == SIGINT)
153 this->
log(
"interrupted by SIGINT");
154 else if (signal == SIGTERM)
155 this->
log(
"interrupted by SIGTERM");
165 boost::asio::co_spawn
169 boost::asio::detached
static void warning(beman::cstring_view message) noexcept
boost::asio::awaitable< void > write_buffer()
Session(Server &server, boost::asio::local::stream_protocol::socket &&socket)
boost::asio::awaitable< size_t > read_buffer(size_t offset, size_t size)
void log(beman::cstring_view message) noexcept override
boost::asio::strand< boost::asio::thread_pool::executor_type > strand
boost::asio::local::stream_protocol::socket socket
boost::asio::local::stream_protocol::endpoint endpoint
const std::string endpoint_path
virtual std::unique_ptr< Session > new_session(boost::asio::local::stream_protocol::socket &&socket)=0
boost::asio::local::stream_protocol::acceptor acceptor
boost::asio::signal_set interrupt_signals
boost::asio::thread_pool thread_pool
Server(Logger &logger, int log_level, int thread_count, std::string endpoint_path)
void log(beman::cstring_view message) noexcept override
virtual void cleanup_after_join()