Couchbase C++ SDK 1.0.4 (rev. 5355b0f)
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
117 struct built {
118 std::string network;
119 std::string server_group;
122 std::chrono::milliseconds tcp_keep_alive_interval;
123 std::chrono::milliseconds config_poll_interval;
124 std::chrono::milliseconds idle_http_connection_timeout;
125 std::optional<std::size_t> max_http_connections;
126 };
127
128 [[nodiscard]] auto build() const -> built
129 {
130 return {
131 network_,
132 server_group_,
133 enable_tcp_keep_alive_,
134 ip_protocol_,
135 tcp_keep_alive_interval_,
136 config_poll_interval_,
137 idle_http_connection_timeout_,
138 max_http_connections_,
139 };
140 }
141
142private:
143 std::string network_{ "auto" };
144 std::string server_group_{};
145 bool enable_tcp_keep_alive_{ true };
146 ip_protocol ip_protocol_{ ip_protocol::any };
147 std::chrono::milliseconds tcp_keep_alive_interval_{ default_tcp_keep_alive_interval };
148 std::chrono::milliseconds config_poll_interval_{ default_config_poll_interval };
149 std::chrono::milliseconds config_poll_floor_{ default_config_poll_floor };
150 std::chrono::milliseconds idle_http_connection_timeout_{ default_idle_http_connection_timeout };
151 std::optional<std::size_t> max_http_connections_{};
152};
153} // 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
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:128
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 collection::scan()
Definition allow_querying_search_index_options.hxx:28
ip_protocol
Definition ip_protocol.hxx:22
Definition network_options.hxx:117
std::string network
Definition network_options.hxx:118
std::string server_group
Definition network_options.hxx:119
bool enable_tcp_keep_alive
Definition network_options.hxx:120
couchbase::ip_protocol ip_protocol
Definition network_options.hxx:121
std::chrono::milliseconds config_poll_interval
Definition network_options.hxx:123
std::chrono::milliseconds idle_http_connection_timeout
Definition network_options.hxx:124
std::optional< std::size_t > max_http_connections
Definition network_options.hxx:125
std::chrono::milliseconds tcp_keep_alive_interval
Definition network_options.hxx:122