62 std::weak_ptr<executors::IExecutor> executor,
63 std::shared_ptr<methods::IMethodProcessor> processor,
64 std::shared_ptr<logging::Logger> logger)
78 [self = this->shared_from_this()](
80 self->on_received(std::move(message));
82 [self = this->shared_from_this()]() { self->on_sent(); },
100 [
this, executor](
auto&& concrete_message) {
102 std::decay_t<
decltype(concrete_message)>>) {
105 [self = this->shared_from_this(),
107 request = std::move(concrete_message)] {
108 self->on_request(request);
110 }
else if constexpr (std::is_same_v<
113 decltype(concrete_message)>>) {
116 [self = this->shared_from_this(),
118 notification = std::move(concrete_message)] {
119 self->on_notification(notification);
137 auto serialized_response =
processor_->call(request);
167 "Unexpectedly received a response from {}, so close the "
172 connection->async_close();
191 is_sending_.store(
true, std::memory_order_relaxed);
197 connection->async_send(next_message);
206 is_sending_.store(
false, std::memory_order_release);
Definition of async_invoke function.
Class of parsed notification.
MethodNameView method_name() const noexcept
Get the method name.
Class of parsed requests.
MethodNameView method_name() const noexcept
Get the method name.
MessageID id() const noexcept
Get the message ID.
std::shared_ptr< logging::Logger > logger_
Logger.
void on_sent()
Handle the condition that a message is sent.
std::queue< messages::SerializedMessage > message_queue_
Messages to be sent.
void start()
Start processing.
std::weak_ptr< transport::IConnection > connection_
Connection.
std::atomic< bool > is_sending_
Whether this connection is sending a message.
void send_next_if_exists()
Send the next message if exists.
std::weak_ptr< executors::IExecutor > executor_
Executor.
std::string formatted_remote_address_
Formatted remote address for logging.
void on_invalid_message()
Handle an invalid message.
ServerConnection(const std::shared_ptr< transport::IConnection > &connection, std::weak_ptr< executors::IExecutor > executor, std::shared_ptr< methods::IMethodProcessor > processor, std::shared_ptr< logging::Logger > logger)
Constructor.
void on_notification(const messages::ParsedNotification ¬ification)
Process a notification.
void on_request(const messages::ParsedRequest &request)
Process a request.
void on_received(messages::ParsedMessage message)
Process a received message.
std::mutex message_queue_mutex_
Mutex of message_queue_.
std::shared_ptr< methods::IMethodProcessor > processor_
Processor of methods.
Definition of IConnection class.
Definition of IExecutor class.
Definition of IMethodProcessor class.
Definition of Logger class.
#define MSGPACK_RPC_DEBUG(LOGGER_PTR,...)
Write a debug log.
#define MSGPACK_RPC_TRACE(LOGGER_PTR,...)
Write a trace log.
Definition of MethodNameView class.
@ CALLBACK
Execution of callbacks.
void async_invoke(const std::shared_ptr< IExecutor > &executor, OperationType type, Function &&function)
Asynchronously invoke a function.
std::variant< ParsedRequest, ParsedResponse, ParsedNotification > ParsedMessage
Type of parsed messages.
Definition of OperationType enumeration.
Definition of ParsedMessage type.
Definition of ParsedNotification class.
Definition of ParsedRequest class.
Definition of SerializedMessage class.
Definition of Status class.