couchbase 3.0.2 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/CMakeLists.txt +3 -0
  4. data/ext/build_version.hxx.in +1 -1
  5. data/ext/cmake/CompilerWarnings.cmake +1 -0
  6. data/ext/cmake/PreventInSourceBuilds.cmake +4 -1
  7. data/ext/couchbase/bucket.hxx +28 -2
  8. data/ext/couchbase/cluster.hxx +8 -2
  9. data/ext/couchbase/couchbase.cxx +955 -511
  10. data/ext/couchbase/error_context/analytics.hxx +46 -0
  11. data/ext/couchbase/error_context/http.hxx +44 -0
  12. data/ext/couchbase/error_context/key_value.hxx +47 -0
  13. data/ext/couchbase/error_context/query.hxx +46 -0
  14. data/ext/couchbase/error_context/search.hxx +47 -0
  15. data/ext/couchbase/error_context/view.hxx +47 -0
  16. data/ext/couchbase/io/dns_codec.hxx +1 -2
  17. data/ext/couchbase/io/http_command.hxx +16 -3
  18. data/ext/couchbase/io/http_context.hxx +1 -1
  19. data/ext/couchbase/io/http_session.hxx +12 -6
  20. data/ext/couchbase/io/http_session_manager.hxx +25 -24
  21. data/ext/couchbase/io/mcbp_session.hxx +8 -2
  22. data/ext/couchbase/io/retry_context.hxx +1 -1
  23. data/ext/couchbase/operations/analytics_dataset_create.hxx +19 -12
  24. data/ext/couchbase/operations/analytics_dataset_drop.hxx +18 -10
  25. data/ext/couchbase/operations/analytics_dataset_get_all.hxx +16 -10
  26. data/ext/couchbase/operations/analytics_dataverse_create.hxx +18 -11
  27. data/ext/couchbase/operations/analytics_dataverse_drop.hxx +17 -11
  28. data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +17 -10
  29. data/ext/couchbase/operations/analytics_index_create.hxx +17 -11
  30. data/ext/couchbase/operations/analytics_index_drop.hxx +16 -10
  31. data/ext/couchbase/operations/analytics_index_get_all.hxx +14 -10
  32. data/ext/couchbase/operations/analytics_link_connect.hxx +15 -9
  33. data/ext/couchbase/operations/analytics_link_disconnect.hxx +16 -10
  34. data/ext/couchbase/operations/bucket_create.hxx +33 -10
  35. data/ext/couchbase/operations/bucket_drop.hxx +9 -8
  36. data/ext/couchbase/operations/bucket_flush.hxx +8 -8
  37. data/ext/couchbase/operations/bucket_get.hxx +15 -10
  38. data/ext/couchbase/operations/bucket_get_all.hxx +14 -7
  39. data/ext/couchbase/operations/bucket_settings.hxx +16 -0
  40. data/ext/couchbase/operations/bucket_update.hxx +32 -10
  41. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +6 -6
  42. data/ext/couchbase/operations/collection_create.hxx +19 -13
  43. data/ext/couchbase/operations/collection_drop.hxx +18 -12
  44. data/ext/couchbase/operations/collections_manifest_get.hxx +5 -10
  45. data/ext/couchbase/operations/document_analytics.hxx +39 -17
  46. data/ext/couchbase/operations/document_append.hxx +5 -10
  47. data/ext/couchbase/operations/document_decrement.hxx +5 -10
  48. data/ext/couchbase/operations/document_exists.hxx +4 -6
  49. data/ext/couchbase/operations/document_get.hxx +6 -10
  50. data/ext/couchbase/operations/document_get_and_lock.hxx +4 -9
  51. data/ext/couchbase/operations/document_get_and_touch.hxx +4 -9
  52. data/ext/couchbase/operations/document_get_projected.hxx +21 -14
  53. data/ext/couchbase/operations/document_increment.hxx +5 -10
  54. data/ext/couchbase/operations/document_insert.hxx +5 -10
  55. data/ext/couchbase/operations/document_lookup_in.hxx +4 -9
  56. data/ext/couchbase/operations/document_mutate_in.hxx +7 -12
  57. data/ext/couchbase/operations/document_prepend.hxx +5 -10
  58. data/ext/couchbase/operations/document_query.hxx +45 -28
  59. data/ext/couchbase/operations/document_remove.hxx +5 -10
  60. data/ext/couchbase/operations/document_replace.hxx +5 -10
  61. data/ext/couchbase/operations/document_search.hxx +37 -16
  62. data/ext/couchbase/operations/document_touch.hxx +4 -9
  63. data/ext/couchbase/operations/document_unlock.hxx +4 -9
  64. data/ext/couchbase/operations/document_upsert.hxx +5 -10
  65. data/ext/couchbase/operations/document_view.hxx +29 -13
  66. data/ext/couchbase/operations/group_drop.hxx +7 -7
  67. data/ext/couchbase/operations/group_get.hxx +14 -10
  68. data/ext/couchbase/operations/group_get_all.hxx +14 -8
  69. data/ext/couchbase/operations/group_upsert.hxx +15 -9
  70. data/ext/couchbase/operations/http_noop.hxx +5 -5
  71. data/ext/couchbase/operations/mcbp_noop.hxx +3 -9
  72. data/ext/couchbase/operations/query_index_build_deferred.hxx +15 -9
  73. data/ext/couchbase/operations/query_index_create.hxx +16 -10
  74. data/ext/couchbase/operations/query_index_drop.hxx +16 -10
  75. data/ext/couchbase/operations/query_index_get_all.hxx +13 -7
  76. data/ext/couchbase/operations/role_get_all.hxx +14 -8
  77. data/ext/couchbase/operations/scope_create.hxx +19 -13
  78. data/ext/couchbase/operations/scope_drop.hxx +17 -11
  79. data/ext/couchbase/operations/scope_get_all.hxx +15 -10
  80. data/ext/couchbase/operations/search_get_stats.hxx +5 -5
  81. data/ext/couchbase/operations/search_index_analyze_document.hxx +25 -13
  82. data/ext/couchbase/operations/search_index_control_ingest.hxx +23 -11
  83. data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +23 -11
  84. data/ext/couchbase/operations/search_index_control_query.hxx +23 -11
  85. data/ext/couchbase/operations/search_index_drop.hxx +22 -10
  86. data/ext/couchbase/operations/search_index_get.hxx +22 -10
  87. data/ext/couchbase/operations/search_index_get_all.hxx +13 -7
  88. data/ext/couchbase/operations/search_index_get_documents_count.hxx +24 -13
  89. data/ext/couchbase/operations/search_index_get_stats.hxx +16 -10
  90. data/ext/couchbase/operations/search_index_upsert.hxx +23 -11
  91. data/ext/couchbase/operations/user_drop.hxx +8 -8
  92. data/ext/couchbase/operations/user_get.hxx +14 -10
  93. data/ext/couchbase/operations/user_get_all.hxx +14 -8
  94. data/ext/couchbase/operations/user_upsert.hxx +15 -9
  95. data/ext/couchbase/operations/view_index_drop.hxx +7 -7
  96. data/ext/couchbase/operations/view_index_get.hxx +15 -9
  97. data/ext/couchbase/operations/view_index_get_all.hxx +15 -9
  98. data/ext/couchbase/operations/view_index_upsert.hxx +8 -8
  99. data/ext/couchbase/origin.hxx +1 -0
  100. data/ext/couchbase/platform/terminate_handler.cc +12 -8
  101. data/ext/couchbase/protocol/client_request.hxx +2 -1
  102. data/ext/couchbase/protocol/client_response.hxx +18 -15
  103. data/ext/couchbase/protocol/cmd_exists.hxx +1 -0
  104. data/ext/couchbase/protocol/cmd_get.hxx +1 -1
  105. data/ext/couchbase/protocol/cmd_mutate_in.hxx +3 -4
  106. data/ext/couchbase/protocol/enhanced_error_info.hxx +28 -0
  107. data/ext/couchbase/utils/connection_string.hxx +1 -1
  108. data/ext/couchbase/version.hxx +1 -1
  109. data/ext/extconf.rb +1 -1
  110. data/ext/test/test_native_binary_operations.cxx +18 -18
  111. data/ext/test/test_native_diagnostics.cxx +2 -2
  112. data/ext/test/test_native_trivial_crud.cxx +2 -2
  113. data/ext/third_party/json/include/tao/json/external/pegtl/internal/file_reader.hpp +1 -5
  114. data/lib/active_support/cache/couchbase_store.rb +362 -0
  115. data/lib/couchbase.rb +2 -0
  116. data/lib/couchbase/authenticator.rb +26 -0
  117. data/lib/couchbase/binary_collection.rb +1 -0
  118. data/lib/couchbase/bucket.rb +1 -0
  119. data/lib/couchbase/cluster.rb +51 -27
  120. data/lib/couchbase/collection.rb +19 -4
  121. data/lib/couchbase/collection_options.rb +10 -0
  122. data/lib/couchbase/configuration.rb +57 -0
  123. data/lib/couchbase/datastructures.rb +6 -0
  124. data/lib/couchbase/errors.rb +111 -3
  125. data/lib/couchbase/management.rb +27 -0
  126. data/lib/couchbase/management/bucket_manager.rb +9 -2
  127. data/lib/couchbase/management/collection_manager.rb +1 -1
  128. data/lib/couchbase/management/user_manager.rb +18 -2
  129. data/lib/couchbase/options.rb +33 -23
  130. data/lib/couchbase/railtie.rb +45 -0
  131. data/lib/couchbase/scope.rb +44 -3
  132. data/lib/couchbase/utils.rb +21 -0
  133. data/lib/couchbase/utils/time.rb +52 -0
  134. data/lib/couchbase/version.rb +1 -1
  135. data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
  136. metadata +19 -5
@@ -0,0 +1,46 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 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
+
20
+ #include <optional>
21
+ #include <set>
22
+ #include <string>
23
+
24
+ #include <io/retry_reason.hxx>
25
+
26
+ namespace couchbase::error_context
27
+ {
28
+
29
+ struct analytics {
30
+ std::error_code ec{};
31
+ std::string client_context_id{};
32
+ std::string statement{};
33
+ std::optional<std::string> parameters{};
34
+
35
+ std::string method{};
36
+ std::string path{};
37
+ std::uint32_t http_status{};
38
+ std::string http_body{};
39
+
40
+ std::optional<std::string> last_dispatched_to{};
41
+ std::optional<std::string> last_dispatched_from{};
42
+ int retry_attempts{ 0 };
43
+ std::set<io::retry_reason> retry_reasons{};
44
+ };
45
+
46
+ } // namespace couchbase::error_context
@@ -0,0 +1,44 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 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
+
20
+ #include <optional>
21
+ #include <set>
22
+ #include <string>
23
+
24
+ #include <io/retry_reason.hxx>
25
+
26
+ namespace couchbase::error_context
27
+ {
28
+
29
+ struct http {
30
+ std::error_code ec{};
31
+ std::string client_context_id{};
32
+
33
+ std::string method{};
34
+ std::string path{};
35
+ std::uint32_t http_status{};
36
+ std::string http_body{};
37
+
38
+ std::optional<std::string> last_dispatched_to{};
39
+ std::optional<std::string> last_dispatched_from{};
40
+ int retry_attempts{ 0 };
41
+ std::set<io::retry_reason> retry_reasons{};
42
+ };
43
+
44
+ } // namespace couchbase::error_context
@@ -0,0 +1,47 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 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
+
20
+ #include <optional>
21
+ #include <set>
22
+ #include <string>
23
+
24
+ #include <document_id.hxx>
25
+ #include <error_map.hxx>
26
+ #include <io/retry_reason.hxx>
27
+ #include <protocol/enhanced_error_info.hxx>
28
+ #include <protocol/status.hxx>
29
+
30
+ namespace couchbase::error_context
31
+ {
32
+
33
+ struct key_value {
34
+ document_id id{};
35
+ std::error_code ec{};
36
+ std::uint32_t opaque{};
37
+ std::optional<protocol::status> status_code{};
38
+ std::optional<error_map::error_info> error_map_info{};
39
+ std::optional<protocol::enhanced_error_info> enhanced_error_info{};
40
+
41
+ std::optional<std::string> last_dispatched_to{};
42
+ std::optional<std::string> last_dispatched_from{};
43
+ int retry_attempts{ 0 };
44
+ std::set<io::retry_reason> retry_reasons{};
45
+ };
46
+
47
+ } // namespace couchbase::error_context
@@ -0,0 +1,46 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 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
+
20
+ #include <optional>
21
+ #include <set>
22
+ #include <string>
23
+
24
+ #include <io/retry_reason.hxx>
25
+
26
+ namespace couchbase::error_context
27
+ {
28
+
29
+ struct query {
30
+ std::error_code ec{};
31
+ std::string client_context_id{};
32
+ std::string statement{};
33
+ std::optional<std::string> parameters{};
34
+
35
+ std::string method{};
36
+ std::string path{};
37
+ std::uint32_t http_status{};
38
+ std::string http_body{};
39
+
40
+ std::optional<std::string> last_dispatched_to{};
41
+ std::optional<std::string> last_dispatched_from{};
42
+ int retry_attempts{ 0 };
43
+ std::set<io::retry_reason> retry_reasons{};
44
+ };
45
+
46
+ } // namespace couchbase::error_context
@@ -0,0 +1,47 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 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
+
20
+ #include <optional>
21
+ #include <set>
22
+ #include <string>
23
+
24
+ #include <io/retry_reason.hxx>
25
+
26
+ namespace couchbase::error_context
27
+ {
28
+
29
+ struct search {
30
+ std::error_code ec{};
31
+ std::string client_context_id{};
32
+ std::string index_name{};
33
+ std::optional<std::string> query{};
34
+ std::optional<std::string> parameters{};
35
+
36
+ std::string method{};
37
+ std::string path{};
38
+ std::uint32_t http_status{};
39
+ std::string http_body{};
40
+
41
+ std::optional<std::string> last_dispatched_to{};
42
+ std::optional<std::string> last_dispatched_from{};
43
+ int retry_attempts{ 0 };
44
+ std::set<io::retry_reason> retry_reasons{};
45
+ };
46
+
47
+ } // namespace couchbase::error_context
@@ -0,0 +1,47 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 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
+
20
+ #include <optional>
21
+ #include <set>
22
+ #include <string>
23
+
24
+ #include <io/retry_reason.hxx>
25
+
26
+ namespace couchbase::error_context
27
+ {
28
+
29
+ struct view {
30
+ std::error_code ec{};
31
+ std::string client_context_id{};
32
+ std::string design_document_name{};
33
+ std::string view_name{};
34
+ std::vector<std::string> query_string{};
35
+
36
+ std::string method{};
37
+ std::string path{};
38
+ std::uint32_t http_status{};
39
+ std::string http_body{};
40
+
41
+ std::optional<std::string> last_dispatched_to{};
42
+ std::optional<std::string> last_dispatched_from{};
43
+ int retry_attempts{ 0 };
44
+ std::set<io::retry_reason> retry_reasons{};
45
+ };
46
+
47
+ } // namespace couchbase::error_context
@@ -19,8 +19,7 @@
19
19
 
20
20
  #include <cstring>
21
21
 
22
- #include <arpa/inet.h>
23
-
22
+ #include <asio/ip/udp.hpp>
24
23
  #include <io/dns_message.hxx>
25
24
 
26
25
  namespace couchbase::io::dns
@@ -26,6 +26,7 @@ template<typename Request>
26
26
  struct http_command : public std::enable_shared_from_this<http_command<Request>> {
27
27
  using encoded_request_type = typename Request::encoded_request_type;
28
28
  using encoded_response_type = typename Request::encoded_response_type;
29
+ using error_context_type = typename Request::error_context_type;
29
30
  asio::steady_timer deadline;
30
31
  asio::steady_timer retry_backoff;
31
32
  Request request;
@@ -44,7 +45,10 @@ struct http_command : public std::enable_shared_from_this<http_command<Request>>
44
45
  encoded.type = request.type;
45
46
  auto encoding_ec = request.encode_to(encoded, session->http_context());
46
47
  if (encoding_ec) {
47
- return handler(make_response(encoding_ec, request, {}));
48
+ error_context_type ctx{};
49
+ ctx.ec = encoding_ec;
50
+ ctx.client_context_id = request.client_context_id;
51
+ return handler(make_response(std::move(ctx), request, {}));
48
52
  }
49
53
  encoded.headers["client-context-id"] = request.client_context_id;
50
54
  auto log_prefix = session->log_prefix();
@@ -80,8 +84,17 @@ struct http_command : public std::enable_shared_from_this<http_command<Request>>
80
84
  resp.status_code,
81
85
  spdlog::to_hex(resp.body));
82
86
  try {
83
- handler(make_response(ec, self->request, std::move(msg)));
84
- } catch (priv::retry_http_request) {
87
+ error_context_type ctx{};
88
+ ctx.ec = ec;
89
+ ctx.client_context_id = self->request.client_context_id;
90
+ ctx.method = self->encoded.method;
91
+ ctx.path = self->encoded.path;
92
+ ctx.last_dispatched_from = session->local_address();
93
+ ctx.last_dispatched_to = session->remote_address();
94
+ ctx.http_status = msg.status_code;
95
+ ctx.http_body = msg.body;
96
+ handler(make_response(std::move(ctx), self->request, std::move(msg)));
97
+ } catch (priv::retry_http_request&) {
85
98
  self->send_to(session, std::forward<Handler>(handler));
86
99
  }
87
100
  });
@@ -30,7 +30,7 @@ struct http_context {
30
30
 
31
31
  namespace priv
32
32
  {
33
- class retry_http_request
33
+ class retry_http_request : public std::exception
34
34
  {
35
35
  };
36
36
  } // namespace priv
@@ -17,8 +17,8 @@
17
17
 
18
18
  #pragma once
19
19
 
20
- #include <utility>
21
20
  #include <memory>
21
+ #include <utility>
22
22
 
23
23
  #include <spdlog/spdlog.h>
24
24
 
@@ -30,9 +30,9 @@
30
30
  #include <errors.hxx>
31
31
  #include <version.hxx>
32
32
 
33
- #include <io/http_parser.hxx>
34
- #include <io/http_message.hxx>
35
33
  #include <io/http_context.hxx>
34
+ #include <io/http_message.hxx>
35
+ #include <io/http_parser.hxx>
36
36
  #include <platform/base64.h>
37
37
  #include <timeout_defaults.hxx>
38
38
 
@@ -103,11 +103,17 @@ class http_session : public std::enable_shared_from_this<http_session>
103
103
 
104
104
  std::string remote_address() const
105
105
  {
106
+ if (endpoint_.protocol() == asio::ip::tcp::v6()) {
107
+ return fmt::format("[{}]:{}", endpoint_address_, endpoint_.port());
108
+ }
106
109
  return fmt::format("{}:{}", endpoint_address_, endpoint_.port());
107
110
  }
108
111
 
109
112
  std::string local_address() const
110
113
  {
114
+ if (endpoint_.protocol() == asio::ip::tcp::v6()) {
115
+ return fmt::format("[{}]:{}", local_endpoint_address_, local_endpoint_.port());
116
+ }
111
117
  return fmt::format("{}:{}", local_endpoint_address_, local_endpoint_.port());
112
118
  }
113
119
 
@@ -178,12 +184,12 @@ class http_session : public std::enable_shared_from_this<http_session>
178
184
  state_ = diag::endpoint_state::disconnected;
179
185
  }
180
186
 
181
- bool keep_alive()
187
+ bool keep_alive() const
182
188
  {
183
189
  return keep_alive_;
184
190
  }
185
191
 
186
- bool is_stopped()
192
+ bool is_stopped() const
187
193
  {
188
194
  return stopped_;
189
195
  }
@@ -215,7 +221,7 @@ class http_session : public std::enable_shared_from_this<http_session>
215
221
  do_write();
216
222
  }
217
223
 
218
- void write_and_subscribe(io::http_request& request, std::function<void(std::error_code, io::http_response&&)> handler)
224
+ void write_and_subscribe(io::http_request& request, std::function<void(std::error_code, io::http_response&&)>&& handler)
219
225
  {
220
226
  if (stopped_) {
221
227
  return;
@@ -117,30 +117,31 @@ class http_session_manager : public std::enable_shared_from_this<http_session_ma
117
117
  operations::http_noop_request request{};
118
118
  request.type = type;
119
119
  auto cmd = std::make_shared<operations::http_command<operations::http_noop_request>>(ctx_, request);
120
- cmd->send_to(session,
121
- [start = std::chrono::steady_clock::now(),
122
- self = shared_from_this(),
123
- type,
124
- session,
125
- handler = collector->build_reporter()](operations::http_noop_response&& resp) mutable {
126
- diag::ping_state state = diag::ping_state::ok;
127
- std::optional<std::string> error{};
128
- if (resp.ec) {
129
- state = diag::ping_state::error;
130
- error.emplace(fmt::format(
131
- "code={}, message={}, http_code={}", resp.ec.value(), resp.ec.message(), resp.status_code));
132
- }
133
- handler(diag::endpoint_ping_info{
134
- type,
135
- session->id(),
136
- std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start),
137
- session->remote_address(),
138
- session->local_address(),
139
- state,
140
- {},
141
- error });
142
- self->check_in(type, session);
143
- });
120
+ cmd->send_to(
121
+ session,
122
+ [start = std::chrono::steady_clock::now(),
123
+ self = shared_from_this(),
124
+ type,
125
+ session,
126
+ handler = collector->build_reporter()](operations::http_noop_response&& resp) mutable {
127
+ diag::ping_state state = diag::ping_state::ok;
128
+ std::optional<std::string> error{};
129
+ if (resp.ctx.ec) {
130
+ state = diag::ping_state::error;
131
+ error.emplace(fmt::format(
132
+ "code={}, message={}, http_code={}", resp.ctx.ec.value(), resp.ctx.ec.message(), resp.ctx.http_status));
133
+ }
134
+ handler(diag::endpoint_ping_info{
135
+ type,
136
+ session->id(),
137
+ std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start),
138
+ session->remote_address(),
139
+ session->local_address(),
140
+ state,
141
+ {},
142
+ error });
143
+ self->check_in(type, session);
144
+ });
144
145
  }
145
146
  }
146
147
  }