cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
Loading...
Searching...
No Matches
tcp_backend.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2023 MusicScience37 (Kenta Kabashima)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
20
#include "
msgpack_rpc/transport/tcp/tcp_backend.h
"
21
22
#include <memory>
23
#include <utility>
24
25
#include "
msgpack_rpc/addresses/schemes.h
"
26
#include "
msgpack_rpc/common/msgpack_rpc_exception.h
"
27
#include "
msgpack_rpc/common/status_code.h
"
28
#include "
msgpack_rpc/config/message_parser_config.h
"
29
#include "
msgpack_rpc/transport/tcp/tcp_acceptor_factory.h
"
30
#include "
msgpack_rpc/transport/tcp/tcp_connector.h
"
31
32
namespace
msgpack_rpc::transport::tcp
{
33
34
TCPBackend::TCPBackend
(
const
std::shared_ptr<executors::IExecutor>&
executor
,
35
const
config::MessageParserConfig
& message_parser_config,
36
std::shared_ptr<logging::Logger> logger)
37
:
executor_
(
executor
),
38
message_parser_config_
(message_parser_config),
39
logger_
(
std
::move(logger)) {}
40
41
std::string_view
TCPBackend::scheme
() const noexcept {
42
return
addresses::TCP_SCHEME
;
43
}
44
45
std::shared_ptr<IAcceptorFactory>
TCPBackend::create_acceptor_factory
() {
46
return
std::make_shared<TCPAcceptorFactory>(
47
executor
(),
message_parser_config_
,
logger_
);
48
}
49
50
std::shared_ptr<IConnector>
TCPBackend::create_connector
() {
51
return
std::make_shared<TCPConnector>(
52
executor
(),
message_parser_config_
,
logger_
);
53
}
54
55
TCPBackend::~TCPBackend
() noexcept = default;
56
57
std
::shared_ptr<
executors
::IExecutor>
TCPBackend
::
executor
()
const
{
58
auto
locked =
executor_
.lock();
59
if
(!locked) {
60
throw
MsgpackRPCException
(
61
StatusCode::PRECONDITION_NOT_MET,
"Executor has been deleted."
);
62
}
63
return
locked;
64
}
65
66
}
// namespace msgpack_rpc::transport::tcp
msgpack_rpc::MsgpackRPCException
Class of exceptions in cpp-msgpack-rpc library.
Definition
msgpack_rpc_exception.h:35
msgpack_rpc::config::MessageParserConfig
Class of configuration of parsers of messages.
Definition
message_parser_config.h:31
msgpack_rpc::transport::tcp::TCPBackend::TCPBackend
TCPBackend(const std::shared_ptr< executors::IExecutor > &executor, const config::MessageParserConfig &message_parser_config, std::shared_ptr< logging::Logger > logger)
Constructor.
Definition
tcp_backend.cpp:34
msgpack_rpc::transport::tcp::TCPBackend::message_parser_config_
config::MessageParserConfig message_parser_config_
Configuration of parsers of messages.
Definition
tcp_backend.h:80
msgpack_rpc::transport::tcp::TCPBackend::scheme
std::string_view scheme() const noexcept override
Get the scheme.
Definition
tcp_backend.cpp:41
msgpack_rpc::transport::tcp::TCPBackend::logger_
std::shared_ptr< logging::Logger > logger_
Logger.
Definition
tcp_backend.h:83
msgpack_rpc::transport::tcp::TCPBackend::executor
std::shared_ptr< executors::IExecutor > executor() const
Get the executor.
Definition
tcp_backend.cpp:57
msgpack_rpc::transport::tcp::TCPBackend::create_acceptor_factory
std::shared_ptr< IAcceptorFactory > create_acceptor_factory() override
Create a factory to create acceptors.
Definition
tcp_backend.cpp:45
msgpack_rpc::transport::tcp::TCPBackend::executor_
std::weak_ptr< executors::IExecutor > executor_
Executor.
Definition
tcp_backend.h:77
msgpack_rpc::transport::tcp::TCPBackend::~TCPBackend
~TCPBackend() noexcept override
Destructor.
msgpack_rpc::transport::tcp::TCPBackend::create_connector
std::shared_ptr< IConnector > create_connector() override
Create a connector to connect to endpoints of acceptors.
Definition
tcp_backend.cpp:50
message_parser_config.h
Definition of MessageParserConfig class.
msgpack_rpc_exception.h
Definition of MsgpackRPCException class.
msgpack_rpc::addresses::TCP_SCHEME
constexpr std::string_view TCP_SCHEME
Scheme of TCP.
Definition
schemes.h:27
msgpack_rpc::executors
Namespace of executors to process asynchronous tasks.
Definition
asio_context_type.h:24
msgpack_rpc::transport::tcp
Namespace of transport of messages via TCP.
Definition
tcp_acceptor.h:28
std
STL namespace.
schemes.h
Definition of constants of schemes.
status_code.h
Definition of StatusCode enumeration.
tcp_acceptor_factory.h
Definition of TCPAcceptorFactory class.
tcp_backend.h
Definition of TCPBackend class.
tcp_connector.h
Definition of TCPConnector class.
src
msgpack_rpc
transport
tcp
tcp_backend.cpp
Generated on
for cpp-msgpack-rpc by
1.18.0