Couchbase C++ SDK 1.3.1 (rev. fb3f860)
Loading...
Searching...
No Matches
network_options.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2020-Present Couchbase, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
21
22#include <chrono>
23#include <cstdint>
24#include <optional>
25#include <string>
26
27namespace couchbase
28{
30{
31public:
32 static constexpr std::chrono::milliseconds default_tcp_keep_alive_interval{ std::chrono::seconds{
33 60 } };
34 static constexpr std::chrono::milliseconds default_config_poll_interval{ 2'500 };
35 static constexpr std::chrono::milliseconds default_config_poll_floor{ 50 };
36 static constexpr std::chrono::milliseconds default_idle_http_connection_timeout{ 4'500 };
37
48 auto preferred_network(std::string network_name) -> network_options&
49 {
50 network_ = std::move(network_name);
51 return *this;
52 }
53
55 {
56 enable_tcp_keep_alive_ = enable;
57 return *this;
58 }
59
60 auto tcp_keep_alive_interval(std::chrono::milliseconds interval) -> network_options&
61 {
62 tcp_keep_alive_interval_ = interval;
63 return *this;
64 }
65
66 auto config_poll_interval(std::chrono::milliseconds interval) -> network_options&
67 {
68 if (interval < config_poll_floor_) {
69 interval = config_poll_floor_;
70 }
71 config_poll_interval_ = interval;
72 return *this;
73 }
74
75 auto idle_http_connection_timeout(std::chrono::milliseconds timeout) -> network_options&
76 {
77 idle_http_connection_timeout_ = timeout;
78 return *this;
79 }
80
81 auto max_http_connections(std::size_t number_of_connections) -> network_options&
82 {
83 max_http_connections_ = number_of_connections;
84 return *this;
85 }
86
88 {
89 ip_protocol_ = protocol;
90 return *this;
91 }
92
111 auto preferred_server_group(std::string server_group) -> network_options&
112 {
113 server_group_ = std::move(server_group);
114 return *this;
115 }
116
128 {
129 enable_lazy_connections_ = enable;
130 return *this;
131 }
132
133 struct built {
134 std::string network;
135 std::string server_group;
138 std::chrono::milliseconds tcp_keep_alive_interval;
139 std::chrono::milliseconds config_poll_interval;
140 std::chrono::milliseconds idle_http_connection_timeout;
141 std::optional<std::size_t> max_http_connections;
143 };
144
145 [[nodiscard]] auto build() const -> built
146 {
147 return {
148 network_,
149 server_group_,
150 enable_tcp_keep_alive_,
151 ip_protocol_,
152 tcp_keep_alive_interval_,
153 config_poll_interval_,
154 idle_http_connection_timeout_,
155 max_http_connections_,
156 enable_lazy_connections_,
157 };
158 }
159
160private:
161 std::string network_{ "auto" };
162 std::string server_group_{};
163 bool enable_tcp_keep_alive_{ true };
164 ip_protocol ip_protocol_{ ip_protocol::any };
165 std::chrono::milliseconds tcp_keep_alive_interval_{ default_tcp_keep_alive_interval };
166 std::chrono::milliseconds config_poll_interval_{ default_config_poll_interval };
167 std::chrono::milliseconds config_poll_floor_{ default_config_poll_floor };
168 std::chrono::milliseconds idle_http_connection_timeout_{ default_idle_http_connection_timeout };
169 std::optional<std::size_t> max_http_connections_{};
170 bool enable_lazy_connections_{ false };
171};
172} // namespace couchbase
Definition network_options.hxx:30
auto preferred_network(std::string network_name) -> network_options &
Selects network to use.
Definition network_options.hxx:48
auto config_poll_interval(std::chrono::milliseconds interval) -> network_options &
Definition network_options.hxx:66
auto enable_lazy_connections(bool enable) -> network_options &
Enables or disables lazy connection of data endpoints.
Definition network_options.hxx:127
static constexpr std::chrono::milliseconds default_config_poll_floor
Definition network_options.hxx:35
static constexpr std::chrono::milliseconds default_idle_http_connection_timeout
Definition network_options.hxx:36
auto tcp_keep_alive_interval(std::chrono::milliseconds interval) -> network_options &
Definition network_options.hxx:60
auto build() const -> built
Definition network_options.hxx:145
auto idle_http_connection_timeout(std::chrono::milliseconds timeout) -> network_options &
Definition network_options.hxx:75
auto enable_tcp_keep_alive(bool enable) -> network_options &
Definition network_options.hxx:54
static constexpr std::chrono::milliseconds default_tcp_keep_alive_interval
Definition network_options.hxx:32
auto max_http_connections(std::size_t number_of_connections) -> network_options &
Definition network_options.hxx:81
auto preferred_server_group(std::string server_group) -> network_options &
Select server group to use for replica APIs.
Definition network_options.hxx:111
static constexpr std::chrono::milliseconds default_config_poll_interval
Definition network_options.hxx:34
auto force_ip_protocol(ip_protocol protocol) -> network_options &
Definition network_options.hxx:87
Represents a single item from the result of scan().
Definition allow_querying_search_index_options.hxx:28
@ timeout
Definition analytics_status.hxx:34
ip_protocol
Definition ip_protocol.hxx:22
@ any
Definition ip_protocol.hxx:23
Definition network_options.hxx:133
std::string network
Definition network_options.hxx:134
std::string server_group
Definition network_options.hxx:135
bool enable_tcp_keep_alive
Definition network_options.hxx:136
couchbase::ip_protocol ip_protocol
Definition network_options.hxx:137
std::chrono::milliseconds config_poll_interval
Definition network_options.hxx:139
std::chrono::milliseconds idle_http_connection_timeout
Definition network_options.hxx:140
std::optional< std::size_t > max_http_connections
Definition network_options.hxx:141
bool enable_lazy_connections
Definition network_options.hxx:142
std::chrono::milliseconds tcp_keep_alive_interval
Definition network_options.hxx:138