Couchbase C++ SDK 1.0.1 (rev. 58d46d7)
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
38 auto preferred_network(std::string network_name) -> network_options&
39 {
40 network_ = network_name;
41 return *this;
42 }
43
45 {
46 enable_tcp_keep_alive_ = enable;
47 return *this;
48 }
49
50 auto tcp_keep_alive_interval(std::chrono::milliseconds interval) -> network_options&
51 {
52 tcp_keep_alive_interval_ = interval;
53 return *this;
54 }
55
56 auto config_poll_interval(std::chrono::milliseconds interval) -> network_options&
57 {
58 if (interval < config_poll_floor_) {
59 interval = config_poll_floor_;
60 }
61 config_poll_interval_ = interval;
62 return *this;
63 }
64
65 auto idle_http_connection_timeout(std::chrono::milliseconds timeout) -> network_options&
66 {
67 idle_http_connection_timeout_ = timeout;
68 return *this;
69 }
70
71 auto max_http_connections(std::size_t number_of_connections) -> network_options&
72 {
73 max_http_connections_ = number_of_connections;
74 return *this;
75 }
76
78 {
79 ip_protocol_ = protocol;
80 return *this;
81 }
82
101 auto preferred_server_group(std::string server_group) -> network_options&
102 {
103 server_group_ = std::move(server_group);
104 return *this;
105 }
106
107 struct built {
108 std::string network;
109 std::string server_group;
112 std::chrono::milliseconds tcp_keep_alive_interval;
113 std::chrono::milliseconds config_poll_interval;
114 std::chrono::milliseconds idle_http_connection_timeout;
115 std::optional<std::size_t> max_http_connections;
116 };
117
118 [[nodiscard]] auto build() const -> built
119 {
120 return {
121 network_,
122 server_group_,
123 enable_tcp_keep_alive_,
124 ip_protocol_,
125 tcp_keep_alive_interval_,
126 config_poll_interval_,
127 idle_http_connection_timeout_,
128 max_http_connections_,
129 };
130 }
131
132private:
133 std::string network_{ "auto" };
134 std::string server_group_{};
135 bool enable_tcp_keep_alive_{ true };
136 ip_protocol ip_protocol_{ ip_protocol::any };
137 std::chrono::milliseconds tcp_keep_alive_interval_{ default_tcp_keep_alive_interval };
138 std::chrono::milliseconds config_poll_interval_{ default_config_poll_interval };
139 std::chrono::milliseconds config_poll_floor_{ default_config_poll_floor };
140 std::chrono::milliseconds idle_http_connection_timeout_{ default_idle_http_connection_timeout };
141 std::optional<std::size_t> max_http_connections_{};
142};
143} // namespace couchbase
Definition network_options.hxx:30
auto preferred_network(std::string network_name) -> network_options &
Definition network_options.hxx:38
auto config_poll_interval(std::chrono::milliseconds interval) -> network_options &
Definition network_options.hxx:56
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:50
auto build() const -> built
Definition network_options.hxx:118
auto idle_http_connection_timeout(std::chrono::milliseconds timeout) -> network_options &
Definition network_options.hxx:65
auto enable_tcp_keep_alive(bool enable) -> network_options &
Definition network_options.hxx:44
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:71
auto preferred_server_group(std::string server_group) -> network_options &
Select server group to use for replica APIs.
Definition network_options.hxx:101
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:77
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:107
std::string network
Definition network_options.hxx:108
std::string server_group
Definition network_options.hxx:109
bool enable_tcp_keep_alive
Definition network_options.hxx:110
couchbase::ip_protocol ip_protocol
Definition network_options.hxx:111
std::chrono::milliseconds config_poll_interval
Definition network_options.hxx:113
std::chrono::milliseconds idle_http_connection_timeout
Definition network_options.hxx:114
std::optional< std::size_t > max_http_connections
Definition network_options.hxx:115
std::chrono::milliseconds tcp_keep_alive_interval
Definition network_options.hxx:112