cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
reconnection_config.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 */
21
22#include <chrono>
23#include <ratio>
24
27
28namespace msgpack_rpc::config {
29
30namespace {
31
32constexpr auto RECONNECTION_CONFIG_DEFAULT_INITIAL_WAITING_TIME =
33 std::chrono::milliseconds(125);
34
35constexpr auto RECONNECTION_CONFIG_DEFAULT_MAX_WAITING_TIME =
36 std::chrono::seconds(32);
37
38constexpr auto RECONNECTION_CONFIG_DEFAULT_MAX_JITTER_WAITING_TIME =
39 RECONNECTION_CONFIG_DEFAULT_INITIAL_WAITING_TIME;
40
41} // namespace
42
44 : initial_waiting_time_(RECONNECTION_CONFIG_DEFAULT_INITIAL_WAITING_TIME),
45 max_waiting_time_(RECONNECTION_CONFIG_DEFAULT_MAX_WAITING_TIME),
47 RECONNECTION_CONFIG_DEFAULT_MAX_JITTER_WAITING_TIME) {}
48
50 std::chrono::nanoseconds value) {
51 if (value <= std::chrono::nanoseconds(0)) {
52 throw MsgpackRPCException(StatusCode::INVALID_ARGUMENT,
53 "Waiting time must be larger than zero.");
54 }
56 return *this;
57}
58
60 const noexcept {
62}
63
65 std::chrono::nanoseconds value) {
66 if (value <= std::chrono::nanoseconds(0)) {
67 throw MsgpackRPCException(StatusCode::INVALID_ARGUMENT,
68 "Waiting time must be larger than zero.");
69 }
70 max_waiting_time_ = value;
71 return *this;
72}
73
74std::chrono::nanoseconds ReconnectionConfig::max_waiting_time() const noexcept {
75 return max_waiting_time_;
76}
77
79 std::chrono::nanoseconds value) {
80 if (value < std::chrono::nanoseconds(0)) {
81 throw MsgpackRPCException(StatusCode::INVALID_ARGUMENT,
82 "Jitter must be larger than or equal to zero.");
83 }
85 return *this;
86}
87
89 const noexcept {
91}
92
93} // namespace msgpack_rpc::config
Class of exceptions in cpp-msgpack-rpc library.
std::chrono::nanoseconds initial_waiting_time() const noexcept
Get the initial waiting time.
std::chrono::nanoseconds max_waiting_time() const noexcept
Get the maximum waiting time.
std::chrono::nanoseconds initial_waiting_time_
Initial waiting time.
std::chrono::nanoseconds max_jitter_waiting_time() const noexcept
Get the maximum jitter of waiting time.
std::chrono::nanoseconds max_waiting_time_
Maximum waiting time.
std::chrono::nanoseconds max_jitter_waiting_time_
Maximum jitter of waiting time.
Definition of MsgpackRPCException class.
Namespace of configurations.
Definition of ReconnectionConfig class.
Definition of StatusCode enumeration.