26#include <system_error>
30#include <asio/error.hpp>
31#include <asio/error_code.hpp>
32#include <asio/post.hpp>
33#include <fmt/format.h>
34#include <fmt/ostream.h>
55template <
typename AsioAcceptorType,
typename AsioSocketType,
56 typename ConcreteAddressType>
59 public std::enable_shared_from_this<
60 Acceptor<AsioAcceptorType, AsioSocketType, ConcreteAddressType>> {
83 const std::shared_ptr<executors::IExecutor>& executor,
85 std::shared_ptr<logging::Logger> logger)
105 [self = this->shared_from_this()] { self->async_accept_next(); });
113 [self = this->shared_from_this()]() { self->stop_in_thread(); });
118 const noexcept
override {
131 [self = this->shared_from_this()](
132 const asio::error_code& error) { self->on_accept(error); });
142 if (error == asio::error::operation_aborted) {
146 fmt::format(
"Error occurred when accepting a connection: {}",
154 auto connection = std::make_shared<ConnectionType>(std::move(*
socket_),
176 addresses::UnixSocketAddress>) {
192 const auto message = std::string(
"Executor is not set.");
195 StatusCode::PRECONDITION_NOT_MET, message);
Definition of BackgroundTaskStateMachine class.
Class of exceptions in cpp-msgpack-rpc library.
Class of configuration of parsers of messages.
config::MessageParserConfig message_parser_config_
void on_accept(const asio::error_code &error)
Handle the result of accept operation.
Acceptor(const ConcreteAddress &local_address, const std::shared_ptr< executors::IExecutor > &executor, const config::MessageParserConfig &message_parser_config, std::shared_ptr< logging::Logger > logger)
Constructor.
void async_accept_next()
Asynchronously accept a connection.
AsioSocketType AsioSocket
Type of sockets in asio library.
Connection< AsioSocket, ConcreteAddress > ConnectionType
Type of connections.
const addresses::IAddress & local_address() const noexcept override
void stop_in_thread()
Stop this acceptor in this thread.
std::shared_ptr< executors::IExecutor > get_executor()
Get the executor.
BackgroundTaskStateMachine state_machine_
void start(ConnectionCallback on_connection) override
Start process of this acceptor.
ConcreteAddress local_address_
std::shared_ptr< ConnectionList< ConnectionType > > connection_list_
std::optional< AsioSocket > socket_
std::weak_ptr< executors::IExecutor > executor_
ConnectionCallback on_connection_
void stop() override
Stop this acceptor.
std::shared_ptr< logging::Logger > logger_
AsioAcceptorType AsioAcceptor
Type of acceptors in asio library.
ConcreteAddressType ConcreteAddress
Type of concrete addresses.
Class of state machines of background tasks in connections and acceptors.
Class of lists of connections.
std::function< void(std::shared_ptr< IConnection >)> ConnectionCallback
Type of callback functions called when a connection is accepted.
Definition of Connection class.
Definition of ConnectionList class.
Definition of IAcceptor class.
Definition of IExecutor class.
Definition of Logger class.
#define MSGPACK_RPC_CRITICAL(LOGGER_PTR,...)
Write a critical log.
#define MSGPACK_RPC_TRACE(LOGGER_PTR,...)
Write a trace log.
#define MSGPACK_RPC_ERROR(LOGGER_PTR,...)
Write a error log.
Definition of MessageParserConfig class.
Definition of MsgpackRPCException class.
Namespace of fmt library.
Namespace of executors to process asynchronous tasks.
Namespace of transport of messages.
Definition of OperationType enumeration.
Definition of StatusCode enumeration.
Definition of UnixSocketAddress class.