grpc 1.22.1 → 1.23.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +487 -649
- data/include/grpc/grpc_security.h +25 -0
- data/include/grpc/impl/codegen/grpc_types.h +11 -2
- data/include/grpc/impl/codegen/port_platform.h +12 -0
- data/src/core/ext/filters/client_channel/backup_poller.cc +4 -2
- data/src/core/ext/filters/client_channel/client_channel.cc +477 -182
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +25 -16
- data/src/core/ext/filters/client_channel/client_channel_channelz.h +11 -6
- data/src/core/ext/filters/client_channel/connector.h +10 -2
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +3 -3
- data/src/core/ext/filters/client_channel/http_proxy.cc +9 -10
- data/src/core/ext/filters/client_channel/lb_policy.cc +2 -17
- data/src/core/ext/filters/client_channel/lb_policy.h +36 -8
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +22 -8
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +86 -52
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +7 -0
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +73 -72
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -12
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +25 -101
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +5 -5
- data/src/core/ext/filters/client_channel/parse_address.cc +29 -26
- data/src/core/ext/filters/client_channel/resolver.h +3 -11
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +5 -3
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +405 -82
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +44 -51
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +0 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +0 -1
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +11 -6
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +130 -65
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +8 -3
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +31 -14
- data/src/core/ext/filters/client_channel/resolver_factory.h +4 -0
- data/src/core/ext/filters/client_channel/resolver_registry.cc +11 -0
- data/src/core/ext/filters/client_channel/resolver_registry.h +3 -0
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +10 -49
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +1 -14
- data/src/core/ext/filters/client_channel/retry_throttle.h +2 -3
- data/src/core/ext/filters/client_channel/subchannel.cc +65 -58
- data/src/core/ext/filters/client_channel/subchannel.h +65 -45
- data/src/core/ext/filters/client_channel/subchannel_interface.h +15 -30
- data/src/core/ext/filters/client_idle/client_idle_filter.cc +264 -0
- data/src/core/ext/filters/http/client/http_client_filter.cc +4 -5
- data/src/core/ext/filters/http/client_authority_filter.cc +2 -2
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +140 -152
- data/src/core/ext/filters/max_age/max_age_filter.cc +3 -3
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -4
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +7 -6
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +41 -60
- data/src/core/ext/transport/chttp2/transport/context_list.cc +3 -1
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -4
- data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_ping.cc +0 -1
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +0 -8
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +0 -7
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +0 -1
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +37 -22
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +137 -80
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +8 -0
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +7 -166
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +41 -15
- data/src/core/ext/transport/chttp2/transport/internal.h +6 -9
- data/src/core/ext/transport/chttp2/transport/parsing.cc +37 -20
- data/src/core/ext/transport/chttp2/transport/stream_map.cc +28 -18
- data/src/core/ext/transport/chttp2/transport/writing.cc +0 -1
- data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
- data/src/core/lib/channel/channelz.cc +80 -33
- data/src/core/lib/channel/channelz.h +28 -13
- data/src/core/lib/compression/compression.cc +1 -2
- data/src/core/lib/compression/compression_args.cc +13 -6
- data/src/core/lib/compression/compression_args.h +3 -2
- data/src/core/lib/compression/compression_internal.cc +1 -1
- data/src/core/lib/gpr/env_linux.cc +10 -21
- data/src/core/lib/gpr/env_posix.cc +0 -5
- data/src/core/lib/gpr/string.cc +7 -2
- data/src/core/lib/gpr/string.h +1 -0
- data/src/core/lib/gpr/sync_posix.cc +0 -129
- data/src/core/lib/gprpp/debug_location.h +3 -2
- data/src/core/lib/gprpp/fork.cc +14 -21
- data/src/core/lib/gprpp/fork.h +15 -4
- data/src/core/lib/gprpp/host_port.cc +118 -0
- data/src/core/lib/{gpr → gprpp}/host_port.h +27 -11
- data/src/core/lib/gprpp/map.h +25 -0
- data/src/core/lib/gprpp/memory.h +26 -9
- data/src/core/lib/gprpp/ref_counted.h +63 -21
- data/src/core/lib/gprpp/string_view.h +143 -0
- data/src/core/lib/gprpp/thd.h +10 -1
- data/src/core/lib/gprpp/thd_posix.cc +25 -0
- data/src/core/lib/gprpp/thd_windows.cc +9 -1
- data/src/core/lib/http/httpcli_security_connector.cc +3 -1
- data/src/core/lib/iomgr/cfstream_handle.cc +6 -1
- data/src/core/lib/iomgr/cfstream_handle.h +8 -2
- data/src/core/lib/iomgr/combiner.cc +4 -4
- data/src/core/lib/iomgr/error.cc +18 -8
- data/src/core/lib/iomgr/error.h +2 -0
- data/src/core/lib/iomgr/ev_posix.cc +4 -2
- data/src/core/lib/iomgr/executor.cc +4 -1
- data/src/core/lib/iomgr/executor/mpmcqueue.cc +183 -0
- data/src/core/lib/iomgr/executor/mpmcqueue.h +178 -0
- data/src/core/lib/iomgr/executor/threadpool.cc +138 -0
- data/src/core/lib/iomgr/executor/threadpool.h +153 -0
- data/src/core/lib/iomgr/fork_posix.cc +4 -2
- data/src/core/lib/iomgr/iocp_windows.cc +2 -2
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +14 -0
- data/src/core/lib/iomgr/iomgr_uv.cc +3 -0
- data/src/core/lib/iomgr/lockfree_event.cc +3 -3
- data/src/core/lib/iomgr/resolve_address_custom.cc +16 -20
- data/src/core/lib/iomgr/resolve_address_posix.cc +8 -10
- data/src/core/lib/iomgr/resolve_address_windows.cc +6 -8
- data/src/core/lib/iomgr/sockaddr_utils.cc +5 -3
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +0 -1
- data/src/core/lib/iomgr/socket_windows.h +1 -1
- data/src/core/lib/iomgr/tcp_client_cfstream.cc +7 -6
- data/src/core/lib/iomgr/tcp_client_custom.cc +1 -0
- data/src/core/lib/iomgr/tcp_custom.cc +4 -0
- data/src/core/lib/iomgr/tcp_posix.cc +8 -2
- data/src/core/lib/iomgr/tcp_server_custom.cc +1 -0
- data/src/core/lib/iomgr/tcp_server_windows.cc +1 -1
- data/src/core/lib/iomgr/tcp_windows.cc +7 -7
- data/src/core/lib/iomgr/timer_custom.cc +1 -0
- data/src/core/lib/iomgr/timer_manager.cc +0 -29
- data/src/core/lib/security/credentials/credentials.cc +84 -0
- data/src/core/lib/security/credentials/credentials.h +58 -2
- data/src/core/lib/security/credentials/jwt/json_token.cc +6 -2
- data/src/core/lib/security/credentials/jwt/json_token.h +1 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +245 -24
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +16 -0
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +3 -2
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +21 -25
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +3 -2
- data/src/core/lib/security/security_connector/security_connector.cc +1 -1
- data/src/core/lib/security/security_connector/security_connector.h +1 -1
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +19 -19
- data/src/core/lib/security/security_connector/ssl_utils.cc +26 -31
- data/src/core/lib/security/security_connector/ssl_utils.h +11 -8
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +16 -20
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +4 -3
- data/src/core/lib/security/transport/client_auth_filter.cc +1 -2
- data/src/core/lib/security/util/json_util.cc +19 -5
- data/src/core/lib/security/util/json_util.h +3 -1
- data/src/core/lib/slice/slice.cc +69 -50
- data/src/core/lib/slice/slice_buffer.cc +6 -5
- data/src/core/lib/slice/slice_hash_table.h +3 -7
- data/src/core/lib/slice/slice_intern.cc +130 -39
- data/src/core/lib/slice/slice_internal.h +8 -0
- data/src/core/lib/slice/slice_utils.h +120 -0
- data/src/core/lib/slice/slice_weak_hash_table.h +2 -7
- data/src/core/lib/surface/call.cc +8 -3
- data/src/core/lib/surface/channel.cc +31 -8
- data/src/core/lib/surface/completion_queue.cc +17 -7
- data/src/core/lib/surface/init_secure.cc +4 -1
- data/src/core/lib/surface/lame_client.cc +2 -2
- data/src/core/lib/surface/server.cc +34 -35
- data/src/core/lib/surface/server.h +8 -17
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/lib/transport/byte_stream.cc +3 -5
- data/src/core/lib/transport/byte_stream.h +1 -2
- data/src/core/lib/transport/error_utils.cc +10 -1
- data/src/core/lib/transport/metadata.cc +202 -35
- data/src/core/lib/transport/metadata.h +81 -6
- data/src/core/lib/transport/static_metadata.cc +1257 -465
- data/src/core/lib/transport/static_metadata.h +190 -347
- data/src/core/lib/transport/timeout_encoding.cc +7 -0
- data/src/core/lib/transport/timeout_encoding.h +3 -2
- data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +0 -1
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +2 -7
- data/src/core/tsi/ssl_transport_security.cc +35 -43
- data/src/core/tsi/ssl_transport_security.h +2 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
- data/src/ruby/lib/grpc/grpc.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- metadata +38 -32
- data/src/core/lib/gpr/host_port.cc +0 -98
@@ -25,10 +25,12 @@ namespace grpc_core {
|
|
25
25
|
// No-op for non-debug builds.
|
26
26
|
// Callers can use the DEBUG_LOCATION macro in either case.
|
27
27
|
#ifndef NDEBUG
|
28
|
+
// TODO(roth): See if there's a way to automatically populate this,
|
29
|
+
// similarly to how absl::SourceLocation::current() works, so that
|
30
|
+
// callers don't need to explicitly pass DEBUG_LOCATION anywhere.
|
28
31
|
class DebugLocation {
|
29
32
|
public:
|
30
33
|
DebugLocation(const char* file, int line) : file_(file), line_(line) {}
|
31
|
-
bool Log() const { return true; }
|
32
34
|
const char* file() const { return file_; }
|
33
35
|
int line() const { return line_; }
|
34
36
|
|
@@ -40,7 +42,6 @@ class DebugLocation {
|
|
40
42
|
#else
|
41
43
|
class DebugLocation {
|
42
44
|
public:
|
43
|
-
bool Log() const { return false; }
|
44
45
|
const char* file() const { return nullptr; }
|
45
46
|
int line() const { return -1; }
|
46
47
|
};
|
data/src/core/lib/gprpp/fork.cc
CHANGED
@@ -168,40 +168,33 @@ class ThreadState {
|
|
168
168
|
|
169
169
|
void Fork::GlobalInit() {
|
170
170
|
if (!override_enabled_) {
|
171
|
-
support_enabled_
|
171
|
+
support_enabled_.Store(GPR_GLOBAL_CONFIG_GET(grpc_enable_fork_support),
|
172
|
+
MemoryOrder::RELAXED);
|
172
173
|
}
|
173
|
-
if (support_enabled_) {
|
174
|
+
if (support_enabled_.Load(MemoryOrder::RELAXED)) {
|
174
175
|
exec_ctx_state_ = grpc_core::New<internal::ExecCtxState>();
|
175
176
|
thread_state_ = grpc_core::New<internal::ThreadState>();
|
176
177
|
}
|
177
178
|
}
|
178
179
|
|
179
180
|
void Fork::GlobalShutdown() {
|
180
|
-
if (support_enabled_) {
|
181
|
+
if (support_enabled_.Load(MemoryOrder::RELAXED)) {
|
181
182
|
grpc_core::Delete(exec_ctx_state_);
|
182
183
|
grpc_core::Delete(thread_state_);
|
183
184
|
}
|
184
185
|
}
|
185
186
|
|
186
|
-
bool Fork::Enabled() { return support_enabled_; }
|
187
|
+
bool Fork::Enabled() { return support_enabled_.Load(MemoryOrder::RELAXED); }
|
187
188
|
|
188
189
|
// Testing Only
|
189
190
|
void Fork::Enable(bool enable) {
|
190
191
|
override_enabled_ = true;
|
191
|
-
support_enabled_
|
192
|
+
support_enabled_.Store(enable, MemoryOrder::RELAXED);
|
192
193
|
}
|
193
194
|
|
194
|
-
void Fork::IncExecCtxCount()
|
195
|
-
if (support_enabled_) {
|
196
|
-
exec_ctx_state_->IncExecCtxCount();
|
197
|
-
}
|
198
|
-
}
|
195
|
+
void Fork::DoIncExecCtxCount() { exec_ctx_state_->IncExecCtxCount(); }
|
199
196
|
|
200
|
-
void Fork::DecExecCtxCount()
|
201
|
-
if (support_enabled_) {
|
202
|
-
exec_ctx_state_->DecExecCtxCount();
|
203
|
-
}
|
204
|
-
}
|
197
|
+
void Fork::DoDecExecCtxCount() { exec_ctx_state_->DecExecCtxCount(); }
|
205
198
|
|
206
199
|
void Fork::SetResetChildPollingEngineFunc(
|
207
200
|
Fork::child_postfork_func reset_child_polling_engine) {
|
@@ -212,38 +205,38 @@ Fork::child_postfork_func Fork::GetResetChildPollingEngineFunc() {
|
|
212
205
|
}
|
213
206
|
|
214
207
|
bool Fork::BlockExecCtx() {
|
215
|
-
if (support_enabled_) {
|
208
|
+
if (support_enabled_.Load(MemoryOrder::RELAXED)) {
|
216
209
|
return exec_ctx_state_->BlockExecCtx();
|
217
210
|
}
|
218
211
|
return false;
|
219
212
|
}
|
220
213
|
|
221
214
|
void Fork::AllowExecCtx() {
|
222
|
-
if (support_enabled_) {
|
215
|
+
if (support_enabled_.Load(MemoryOrder::RELAXED)) {
|
223
216
|
exec_ctx_state_->AllowExecCtx();
|
224
217
|
}
|
225
218
|
}
|
226
219
|
|
227
220
|
void Fork::IncThreadCount() {
|
228
|
-
if (support_enabled_) {
|
221
|
+
if (support_enabled_.Load(MemoryOrder::RELAXED)) {
|
229
222
|
thread_state_->IncThreadCount();
|
230
223
|
}
|
231
224
|
}
|
232
225
|
|
233
226
|
void Fork::DecThreadCount() {
|
234
|
-
if (support_enabled_) {
|
227
|
+
if (support_enabled_.Load(MemoryOrder::RELAXED)) {
|
235
228
|
thread_state_->DecThreadCount();
|
236
229
|
}
|
237
230
|
}
|
238
231
|
void Fork::AwaitThreads() {
|
239
|
-
if (support_enabled_) {
|
232
|
+
if (support_enabled_.Load(MemoryOrder::RELAXED)) {
|
240
233
|
thread_state_->AwaitThreads();
|
241
234
|
}
|
242
235
|
}
|
243
236
|
|
244
237
|
internal::ExecCtxState* Fork::exec_ctx_state_ = nullptr;
|
245
238
|
internal::ThreadState* Fork::thread_state_ = nullptr;
|
246
|
-
|
239
|
+
Atomic<bool> Fork::support_enabled_(false);
|
247
240
|
bool Fork::override_enabled_ = false;
|
248
241
|
Fork::child_postfork_func Fork::reset_child_polling_engine_ = nullptr;
|
249
242
|
} // namespace grpc_core
|
data/src/core/lib/gprpp/fork.h
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
|
22
22
|
#include <grpc/support/port_platform.h>
|
23
23
|
|
24
|
-
#include
|
24
|
+
#include "src/core/lib/gprpp/atomic.h"
|
25
25
|
|
26
26
|
/*
|
27
27
|
* NOTE: FORKING IS NOT GENERALLY SUPPORTED, THIS IS ONLY INTENDED TO WORK
|
@@ -47,10 +47,18 @@ class Fork {
|
|
47
47
|
|
48
48
|
// Increment the count of active ExecCtxs.
|
49
49
|
// Will block until a pending fork is complete if one is in progress.
|
50
|
-
static void IncExecCtxCount()
|
50
|
+
static void IncExecCtxCount() {
|
51
|
+
if (GPR_UNLIKELY(support_enabled_.Load(MemoryOrder::RELAXED))) {
|
52
|
+
DoIncExecCtxCount();
|
53
|
+
}
|
54
|
+
}
|
51
55
|
|
52
56
|
// Decrement the count of active ExecCtxs
|
53
|
-
static void DecExecCtxCount()
|
57
|
+
static void DecExecCtxCount() {
|
58
|
+
if (GPR_UNLIKELY(support_enabled_.Load(MemoryOrder::RELAXED))) {
|
59
|
+
DoDecExecCtxCount();
|
60
|
+
}
|
61
|
+
}
|
54
62
|
|
55
63
|
// Provide a function that will be invoked in the child's postfork handler to
|
56
64
|
// reset the polling engine's internal state.
|
@@ -80,9 +88,12 @@ class Fork {
|
|
80
88
|
static void Enable(bool enable);
|
81
89
|
|
82
90
|
private:
|
91
|
+
static void DoIncExecCtxCount();
|
92
|
+
static void DoDecExecCtxCount();
|
93
|
+
|
83
94
|
static internal::ExecCtxState* exec_ctx_state_;
|
84
95
|
static internal::ThreadState* thread_state_;
|
85
|
-
static
|
96
|
+
static grpc_core::Atomic<bool> support_enabled_;
|
86
97
|
static bool override_enabled_;
|
87
98
|
static child_postfork_func reset_child_polling_engine_;
|
88
99
|
};
|
@@ -0,0 +1,118 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 gRPC authors.
|
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
|
+
|
19
|
+
#include <grpc/support/port_platform.h>
|
20
|
+
|
21
|
+
#include "src/core/lib/gprpp/host_port.h"
|
22
|
+
|
23
|
+
#include <string.h>
|
24
|
+
|
25
|
+
#include <grpc/support/alloc.h>
|
26
|
+
#include <grpc/support/log.h>
|
27
|
+
#include <grpc/support/string_util.h>
|
28
|
+
|
29
|
+
#include "src/core/lib/gpr/string.h"
|
30
|
+
#include "src/core/lib/gprpp/string_view.h"
|
31
|
+
|
32
|
+
namespace grpc_core {
|
33
|
+
int JoinHostPort(UniquePtr<char>* out, const char* host, int port) {
|
34
|
+
char* tmp;
|
35
|
+
int ret;
|
36
|
+
if (host[0] != '[' && strchr(host, ':') != nullptr) {
|
37
|
+
/* IPv6 literals must be enclosed in brackets. */
|
38
|
+
ret = gpr_asprintf(&tmp, "[%s]:%d", host, port);
|
39
|
+
} else {
|
40
|
+
/* Ordinary non-bracketed host:port. */
|
41
|
+
ret = gpr_asprintf(&tmp, "%s:%d", host, port);
|
42
|
+
}
|
43
|
+
out->reset(tmp);
|
44
|
+
return ret;
|
45
|
+
}
|
46
|
+
|
47
|
+
namespace {
|
48
|
+
bool DoSplitHostPort(StringView name, StringView* host, StringView* port,
|
49
|
+
bool* has_port) {
|
50
|
+
*has_port = false;
|
51
|
+
if (name[0] == '[') {
|
52
|
+
/* Parse a bracketed host, typically an IPv6 literal. */
|
53
|
+
const size_t rbracket = name.find(']', 1);
|
54
|
+
if (rbracket == grpc_core::StringView::npos) {
|
55
|
+
/* Unmatched [ */
|
56
|
+
return false;
|
57
|
+
}
|
58
|
+
if (rbracket == name.size() - 1) {
|
59
|
+
/* ]<end> */
|
60
|
+
port->clear();
|
61
|
+
} else if (name[rbracket + 1] == ':') {
|
62
|
+
/* ]:<port?> */
|
63
|
+
*port = name.substr(rbracket + 2, name.size() - rbracket - 2);
|
64
|
+
*has_port = true;
|
65
|
+
} else {
|
66
|
+
/* ]<invalid> */
|
67
|
+
return false;
|
68
|
+
}
|
69
|
+
*host = name.substr(1, rbracket - 1);
|
70
|
+
if (host->find(':') == grpc_core::StringView::npos) {
|
71
|
+
/* Require all bracketed hosts to contain a colon, because a hostname or
|
72
|
+
IPv4 address should never use brackets. */
|
73
|
+
host->clear();
|
74
|
+
return false;
|
75
|
+
}
|
76
|
+
} else {
|
77
|
+
size_t colon = name.find(':');
|
78
|
+
if (colon != grpc_core::StringView::npos &&
|
79
|
+
name.find(':', colon + 1) == grpc_core::StringView::npos) {
|
80
|
+
/* Exactly 1 colon. Split into host:port. */
|
81
|
+
*host = name.substr(0, colon);
|
82
|
+
*port = name.substr(colon + 1, name.size() - colon - 1);
|
83
|
+
*has_port = true;
|
84
|
+
} else {
|
85
|
+
/* 0 or 2+ colons. Bare hostname or IPv6 litearal. */
|
86
|
+
*host = name;
|
87
|
+
port->clear();
|
88
|
+
}
|
89
|
+
}
|
90
|
+
return true;
|
91
|
+
}
|
92
|
+
} // namespace
|
93
|
+
|
94
|
+
bool SplitHostPort(StringView name, StringView* host, StringView* port) {
|
95
|
+
bool unused;
|
96
|
+
return DoSplitHostPort(name, host, port, &unused);
|
97
|
+
}
|
98
|
+
|
99
|
+
bool SplitHostPort(StringView name, UniquePtr<char>* host,
|
100
|
+
UniquePtr<char>* port) {
|
101
|
+
GPR_DEBUG_ASSERT(host != nullptr && *host == nullptr);
|
102
|
+
GPR_DEBUG_ASSERT(port != nullptr && *port == nullptr);
|
103
|
+
StringView host_view;
|
104
|
+
StringView port_view;
|
105
|
+
bool has_port;
|
106
|
+
const bool ret = DoSplitHostPort(name, &host_view, &port_view, &has_port);
|
107
|
+
if (ret) {
|
108
|
+
// We always set the host, but port is set only when DoSplitHostPort find a
|
109
|
+
// port in the string, to remain backward compatible with the old
|
110
|
+
// gpr_split_host_port API.
|
111
|
+
*host = host_view.dup();
|
112
|
+
if (has_port) {
|
113
|
+
*port = port_view.dup();
|
114
|
+
}
|
115
|
+
}
|
116
|
+
return ret;
|
117
|
+
}
|
118
|
+
} // namespace grpc_core
|
@@ -16,28 +16,44 @@
|
|
16
16
|
*
|
17
17
|
*/
|
18
18
|
|
19
|
-
#ifndef
|
20
|
-
#define
|
19
|
+
#ifndef GRPC_CORE_LIB_GPRPP_HOST_PORT_H
|
20
|
+
#define GRPC_CORE_LIB_GPRPP_HOST_PORT_H
|
21
21
|
|
22
22
|
#include <grpc/support/port_platform.h>
|
23
23
|
|
24
|
+
#include "src/core/lib/gprpp/memory.h"
|
25
|
+
#include "src/core/lib/gprpp/string_view.h"
|
26
|
+
|
27
|
+
namespace grpc_core {
|
28
|
+
|
24
29
|
/** Given a host and port, creates a newly-allocated string of the form
|
25
30
|
"host:port" or "[ho:st]:port", depending on whether the host contains colons
|
26
31
|
like an IPv6 literal. If the host is already bracketed, then additional
|
27
32
|
brackets will not be added.
|
28
33
|
|
29
34
|
Usage is similar to gpr_asprintf: returns the number of bytes written
|
30
|
-
(excluding the final '\0'), and *out points to a string
|
31
|
-
destroyed using gpr_free().
|
35
|
+
(excluding the final '\0'), and *out points to a string.
|
32
36
|
|
33
37
|
In the unlikely event of an error, returns -1 and sets *out to NULL. */
|
34
|
-
int
|
38
|
+
int JoinHostPort(UniquePtr<char>* out, const char* host, int port);
|
35
39
|
|
36
40
|
/** Given a name in the form "host:port" or "[ho:st]:port", split into hostname
|
37
|
-
and port number
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
and port number.
|
42
|
+
|
43
|
+
There are two variants of this method:
|
44
|
+
1) StringView output: port and host are returned as views on name.
|
45
|
+
2) char* output: port and host are copied into newly allocated strings.
|
46
|
+
|
47
|
+
Prefer variant (1) over (2), because no allocation or copy is performed in
|
48
|
+
variant (1). Use (2) only when interacting with C API that mandate
|
49
|
+
null-terminated strings.
|
50
|
+
|
51
|
+
Return true on success, false on failure. Guarantees *host and *port are
|
52
|
+
cleared on failure. */
|
53
|
+
bool SplitHostPort(StringView name, StringView* host, StringView* port);
|
54
|
+
bool SplitHostPort(StringView name, UniquePtr<char>* host,
|
55
|
+
UniquePtr<char>* port);
|
56
|
+
|
57
|
+
} // namespace grpc_core
|
42
58
|
|
43
|
-
#endif /*
|
59
|
+
#endif /* GRPC_CORE_LIB_GPRPP_HOST_PORT_H */
|
data/src/core/lib/gprpp/map.h
CHANGED
@@ -30,6 +30,7 @@
|
|
30
30
|
#include "src/core/lib/gpr/useful.h"
|
31
31
|
#include "src/core/lib/gprpp/memory.h"
|
32
32
|
#include "src/core/lib/gprpp/pair.h"
|
33
|
+
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
33
34
|
|
34
35
|
namespace grpc_core {
|
35
36
|
struct StringLess {
|
@@ -41,6 +42,13 @@ struct StringLess {
|
|
41
42
|
}
|
42
43
|
};
|
43
44
|
|
45
|
+
template <typename T>
|
46
|
+
struct RefCountedPtrLess {
|
47
|
+
bool operator()(const RefCountedPtr<T>& p1, const RefCountedPtr<T>& p2) {
|
48
|
+
return p1.get() < p2.get();
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
44
52
|
namespace testing {
|
45
53
|
class MapTest;
|
46
54
|
}
|
@@ -55,8 +63,25 @@ class Map {
|
|
55
63
|
typedef Compare key_compare;
|
56
64
|
class iterator;
|
57
65
|
|
66
|
+
Map() = default;
|
58
67
|
~Map() { clear(); }
|
59
68
|
|
69
|
+
// Movable.
|
70
|
+
Map(Map&& other) : root_(other.root_), size_(other.size_) {
|
71
|
+
other.root_ = nullptr;
|
72
|
+
other.size_ = 0;
|
73
|
+
}
|
74
|
+
Map& operator=(Map&& other) {
|
75
|
+
if (this != &other) {
|
76
|
+
clear();
|
77
|
+
root_ = other.root_;
|
78
|
+
size_ = other.size_;
|
79
|
+
other.root_ = nullptr;
|
80
|
+
other.size_ = 0;
|
81
|
+
}
|
82
|
+
return *this;
|
83
|
+
}
|
84
|
+
|
60
85
|
T& operator[](key_type&& key);
|
61
86
|
T& operator[](const key_type& key);
|
62
87
|
iterator find(const key_type& k);
|
data/src/core/lib/gprpp/memory.h
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
#include <grpc/support/port_platform.h>
|
23
23
|
|
24
24
|
#include <grpc/support/alloc.h>
|
25
|
+
#include <grpc/support/log.h>
|
25
26
|
|
26
27
|
#include <limits>
|
27
28
|
#include <memory>
|
@@ -29,14 +30,17 @@
|
|
29
30
|
|
30
31
|
// Add this to a class that want to use Delete(), but has a private or
|
31
32
|
// protected destructor.
|
32
|
-
#define GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
|
33
|
-
template <typename
|
34
|
-
friend void grpc_core::Delete(
|
33
|
+
#define GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE \
|
34
|
+
template <typename _Delete_T, bool _Delete_can_be_null> \
|
35
|
+
friend void ::grpc_core::Delete(_Delete_T*); \
|
36
|
+
template <typename _Delete_T> \
|
37
|
+
friend void ::grpc_core::Delete(_Delete_T*);
|
38
|
+
|
35
39
|
// Add this to a class that want to use New(), but has a private or
|
36
40
|
// protected constructor.
|
37
|
-
#define GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
|
38
|
-
template <typename
|
39
|
-
friend
|
41
|
+
#define GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW \
|
42
|
+
template <typename _New_T, typename... _New_Args> \
|
43
|
+
friend _New_T* grpc_core::New(_New_Args&&...);
|
40
44
|
|
41
45
|
namespace grpc_core {
|
42
46
|
|
@@ -48,17 +52,30 @@ inline T* New(Args&&... args) {
|
|
48
52
|
}
|
49
53
|
|
50
54
|
// Alternative to delete, since we cannot use it (for fear of libstdc++)
|
51
|
-
|
55
|
+
// We cannot add a default value for can_be_null, because they are used as
|
56
|
+
// as friend template methods where we cannot define a default value.
|
57
|
+
// Instead we simply define two variants, one with and one without the boolean
|
58
|
+
// argument.
|
59
|
+
template <typename T, bool can_be_null>
|
52
60
|
inline void Delete(T* p) {
|
53
|
-
|
61
|
+
GPR_DEBUG_ASSERT(can_be_null || p != nullptr);
|
62
|
+
if (can_be_null && p == nullptr) return;
|
54
63
|
p->~T();
|
55
64
|
gpr_free(p);
|
56
65
|
}
|
66
|
+
template <typename T>
|
67
|
+
inline void Delete(T* p) {
|
68
|
+
Delete<T, /*can_be_null=*/true>(p);
|
69
|
+
}
|
57
70
|
|
58
71
|
template <typename T>
|
59
72
|
class DefaultDelete {
|
60
73
|
public:
|
61
|
-
void operator()(T* p) {
|
74
|
+
void operator()(T* p) {
|
75
|
+
// std::unique_ptr is gauranteed not to call the deleter
|
76
|
+
// if the pointer is nullptr.
|
77
|
+
Delete<T, /*can_be_null=*/false>(p);
|
78
|
+
}
|
62
79
|
};
|
63
80
|
|
64
81
|
template <typename T, typename Deleter = DefaultDelete<T>>
|
@@ -89,72 +89,114 @@ class RefCount {
|
|
89
89
|
}
|
90
90
|
|
91
91
|
// Increases the ref-count by `n`.
|
92
|
-
void Ref(Value n = 1) {
|
92
|
+
void Ref(Value n = 1) {
|
93
|
+
#ifndef NDEBUG
|
94
|
+
const Value prior = value_.FetchAdd(n, MemoryOrder::RELAXED);
|
95
|
+
if (trace_flag_ != nullptr && trace_flag_->enabled()) {
|
96
|
+
gpr_log(GPR_INFO, "%s:%p ref %" PRIdPTR " -> %" PRIdPTR,
|
97
|
+
trace_flag_->name(), this, prior, prior + n);
|
98
|
+
}
|
99
|
+
#else
|
100
|
+
value_.FetchAdd(n, MemoryOrder::RELAXED);
|
101
|
+
#endif
|
102
|
+
}
|
93
103
|
void Ref(const DebugLocation& location, const char* reason, Value n = 1) {
|
94
104
|
#ifndef NDEBUG
|
95
|
-
|
96
|
-
|
105
|
+
const Value prior = value_.FetchAdd(n, MemoryOrder::RELAXED);
|
106
|
+
if (trace_flag_ != nullptr && trace_flag_->enabled()) {
|
97
107
|
gpr_log(GPR_INFO, "%s:%p %s:%d ref %" PRIdPTR " -> %" PRIdPTR " %s",
|
98
108
|
trace_flag_->name(), this, location.file(), location.line(),
|
99
|
-
|
109
|
+
prior, prior + n, reason);
|
100
110
|
}
|
111
|
+
#else
|
112
|
+
value_.FetchAdd(n, MemoryOrder::RELAXED);
|
101
113
|
#endif
|
102
|
-
Ref(n);
|
103
114
|
}
|
104
115
|
|
105
116
|
// Similar to Ref() with an assert on the ref-count being non-zero.
|
106
117
|
void RefNonZero() {
|
107
118
|
#ifndef NDEBUG
|
108
119
|
const Value prior = value_.FetchAdd(1, MemoryOrder::RELAXED);
|
120
|
+
if (trace_flag_ != nullptr && trace_flag_->enabled()) {
|
121
|
+
gpr_log(GPR_INFO, "%s:%p ref %" PRIdPTR " -> %" PRIdPTR,
|
122
|
+
trace_flag_->name(), this, prior, prior + 1);
|
123
|
+
}
|
109
124
|
assert(prior > 0);
|
110
125
|
#else
|
111
|
-
|
126
|
+
value_.FetchAdd(1, MemoryOrder::RELAXED);
|
112
127
|
#endif
|
113
128
|
}
|
114
129
|
void RefNonZero(const DebugLocation& location, const char* reason) {
|
115
130
|
#ifndef NDEBUG
|
116
|
-
|
117
|
-
|
131
|
+
const Value prior = value_.FetchAdd(1, MemoryOrder::RELAXED);
|
132
|
+
if (trace_flag_ != nullptr && trace_flag_->enabled()) {
|
118
133
|
gpr_log(GPR_INFO, "%s:%p %s:%d ref %" PRIdPTR " -> %" PRIdPTR " %s",
|
119
134
|
trace_flag_->name(), this, location.file(), location.line(),
|
120
|
-
|
135
|
+
prior, prior + 1, reason);
|
121
136
|
}
|
122
|
-
|
137
|
+
assert(prior > 0);
|
138
|
+
#else
|
123
139
|
RefNonZero();
|
140
|
+
#endif
|
124
141
|
}
|
125
142
|
|
126
|
-
bool RefIfNonZero() {
|
127
|
-
|
143
|
+
bool RefIfNonZero() {
|
144
|
+
#ifndef NDEBUG
|
145
|
+
if (trace_flag_ != nullptr && trace_flag_->enabled()) {
|
146
|
+
const Value prior = get();
|
147
|
+
gpr_log(GPR_INFO, "%s:%p ref_if_non_zero %" PRIdPTR " -> %" PRIdPTR,
|
148
|
+
trace_flag_->name(), this, prior, prior + 1);
|
149
|
+
}
|
150
|
+
#endif
|
151
|
+
return value_.IncrementIfNonzero();
|
152
|
+
}
|
128
153
|
bool RefIfNonZero(const DebugLocation& location, const char* reason) {
|
129
154
|
#ifndef NDEBUG
|
130
|
-
if (
|
131
|
-
const
|
155
|
+
if (trace_flag_ != nullptr && trace_flag_->enabled()) {
|
156
|
+
const Value prior = get();
|
132
157
|
gpr_log(GPR_INFO,
|
133
158
|
"%s:%p %s:%d ref_if_non_zero "
|
134
159
|
"%" PRIdPTR " -> %" PRIdPTR " %s",
|
135
160
|
trace_flag_->name(), this, location.file(), location.line(),
|
136
|
-
|
161
|
+
prior, prior + 1, reason);
|
137
162
|
}
|
138
163
|
#endif
|
139
|
-
return
|
164
|
+
return value_.IncrementIfNonzero();
|
140
165
|
}
|
141
166
|
|
142
167
|
// Decrements the ref-count and returns true if the ref-count reaches 0.
|
143
168
|
bool Unref() {
|
169
|
+
#ifndef NDEBUG
|
170
|
+
// Grab a copy of the trace flag before the atomic change, since we
|
171
|
+
// can't safely access it afterwards if we're going to be freed.
|
172
|
+
auto* trace_flag = trace_flag_;
|
173
|
+
#endif
|
144
174
|
const Value prior = value_.FetchSub(1, MemoryOrder::ACQ_REL);
|
175
|
+
#ifndef NDEBUG
|
176
|
+
if (trace_flag != nullptr && trace_flag->enabled()) {
|
177
|
+
gpr_log(GPR_INFO, "%s:%p unref %" PRIdPTR " -> %" PRIdPTR,
|
178
|
+
trace_flag->name(), this, prior, prior - 1);
|
179
|
+
}
|
145
180
|
GPR_DEBUG_ASSERT(prior > 0);
|
181
|
+
#endif
|
146
182
|
return prior == 1;
|
147
183
|
}
|
148
184
|
bool Unref(const DebugLocation& location, const char* reason) {
|
149
185
|
#ifndef NDEBUG
|
150
|
-
|
151
|
-
|
186
|
+
// Grab a copy of the trace flag before the atomic change, since we
|
187
|
+
// can't safely access it afterwards if we're going to be freed.
|
188
|
+
auto* trace_flag = trace_flag_;
|
189
|
+
#endif
|
190
|
+
const Value prior = value_.FetchSub(1, MemoryOrder::ACQ_REL);
|
191
|
+
#ifndef NDEBUG
|
192
|
+
if (trace_flag != nullptr && trace_flag->enabled()) {
|
152
193
|
gpr_log(GPR_INFO, "%s:%p %s:%d unref %" PRIdPTR " -> %" PRIdPTR " %s",
|
153
|
-
|
154
|
-
|
194
|
+
trace_flag->name(), this, location.file(), location.line(), prior,
|
195
|
+
prior - 1, reason);
|
155
196
|
}
|
197
|
+
GPR_DEBUG_ASSERT(prior > 0);
|
156
198
|
#endif
|
157
|
-
return
|
199
|
+
return prior == 1;
|
158
200
|
}
|
159
201
|
|
160
202
|
private:
|