grpc 1.20.0 → 1.21.0
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 +500 -29
- data/etc/roots.pem +146 -0
- data/include/grpc/grpc_security.h +1 -1
- data/include/grpc/impl/codegen/grpc_types.h +10 -7
- data/include/grpc/impl/codegen/port_platform.h +11 -1
- data/include/grpc/impl/codegen/slice.h +1 -21
- data/include/grpc/impl/codegen/status.h +2 -1
- data/include/grpc/slice.h +1 -1
- data/src/core/ext/filters/client_channel/backup_poller.cc +19 -13
- data/src/core/ext/filters/client_channel/backup_poller.h +3 -0
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +1 -1
- data/src/core/ext/filters/client_channel/client_channel.cc +2084 -1673
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +2 -3
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +4 -0
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +54 -49
- data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -2
- data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.cc +3 -30
- data/src/core/ext/filters/client_channel/lb_policy.h +16 -25
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +106 -81
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +8 -12
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +2 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +57 -49
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +47 -41
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +24 -20
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +989 -284
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -1
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +105 -2
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +9 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +79 -36
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +15 -3
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
- data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
- data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h +29 -0
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +4 -4
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +367 -232
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +55 -76
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +50 -39
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +18 -12
- data/src/core/ext/filters/client_channel/service_config.cc +247 -27
- data/src/core/ext/filters/client_channel/service_config.h +119 -166
- data/src/core/ext/filters/client_channel/subchannel.cc +46 -84
- data/src/core/ext/filters/client_channel/subchannel.h +7 -7
- data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
- data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
- data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
- data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
- data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
- data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
- data/src/core/ext/filters/message_size/message_size_filter.cc +118 -76
- data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +93 -60
- data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +4 -3
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +8 -2
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +3 -2
- data/src/core/ext/transport/chttp2/transport/internal.h +35 -23
- data/src/core/ext/transport/chttp2/transport/parsing.cc +4 -4
- data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/writing.cc +61 -27
- data/src/core/ext/transport/inproc/inproc_transport.cc +18 -18
- data/src/core/lib/channel/channel_args.cc +0 -101
- data/src/core/lib/channel/channel_args.h +0 -37
- data/src/core/lib/channel/channel_stack.h +9 -5
- data/src/core/lib/channel/channelz_registry.cc +1 -1
- data/src/core/lib/channel/connected_channel.cc +2 -2
- data/src/core/lib/channel/context.h +3 -0
- data/src/core/lib/channel/handshaker.cc +4 -4
- data/src/core/lib/channel/handshaker.h +1 -1
- data/src/core/lib/compression/compression_args.cc +127 -0
- data/src/core/lib/compression/compression_args.h +55 -0
- data/src/core/lib/debug/trace.cc +13 -7
- data/src/core/lib/debug/trace.h +12 -0
- data/src/core/lib/gpr/arena.h +13 -9
- data/src/core/lib/gpr/env.h +2 -5
- data/src/core/lib/gpr/env_linux.cc +6 -1
- data/src/core/lib/gpr/env_posix.cc +5 -0
- data/src/core/lib/gpr/env_windows.cc +7 -5
- data/src/core/lib/gpr/log.cc +9 -13
- data/src/core/lib/gpr/string.cc +12 -6
- data/src/core/lib/gpr/string.h +4 -2
- data/src/core/lib/gpr/time_posix.cc +13 -0
- data/src/core/lib/gprpp/arena.cc +103 -0
- data/src/core/lib/gprpp/arena.h +121 -0
- data/src/core/lib/gprpp/fork.cc +12 -29
- data/src/core/lib/gprpp/global_config.h +87 -0
- data/src/core/lib/gprpp/global_config_custom.h +29 -0
- data/src/core/lib/gprpp/global_config_env.cc +135 -0
- data/src/core/lib/gprpp/global_config_env.h +131 -0
- data/src/core/lib/gprpp/global_config_generic.h +44 -0
- data/src/core/lib/gprpp/map.h +419 -0
- data/src/core/lib/gprpp/optional.h +1 -0
- data/src/core/lib/gprpp/orphanable.h +2 -2
- data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
- data/src/core/lib/gprpp/ref_counted.h +18 -2
- data/src/core/lib/gprpp/sync.h +126 -0
- data/src/core/lib/http/parser.cc +1 -1
- data/src/core/lib/iomgr/call_combiner.cc +84 -90
- data/src/core/lib/iomgr/call_combiner.h +75 -82
- data/src/core/lib/iomgr/cfstream_handle.cc +202 -0
- data/src/core/lib/iomgr/cfstream_handle.h +82 -0
- data/src/core/lib/iomgr/combiner.h +1 -1
- data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
- data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
- data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
- data/src/core/lib/iomgr/error.h +23 -0
- data/src/core/lib/iomgr/error_cfstream.cc +52 -0
- data/src/core/lib/iomgr/error_cfstream.h +31 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +34 -27
- data/src/core/lib/iomgr/ev_epollex_linux.cc +33 -33
- data/src/core/lib/iomgr/ev_poll_posix.cc +7 -7
- data/src/core/lib/iomgr/ev_posix.cc +15 -13
- data/src/core/lib/iomgr/ev_posix.h +4 -1
- data/src/core/lib/iomgr/executor.cc +13 -9
- data/src/core/lib/iomgr/fork_posix.cc +0 -1
- data/src/core/lib/iomgr/internal_errqueue.cc +1 -1
- data/src/core/lib/iomgr/iomgr.cc +6 -5
- data/src/core/lib/iomgr/iomgr_custom.cc +3 -0
- data/src/core/lib/iomgr/iomgr_custom.h +2 -0
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
- data/src/core/lib/iomgr/iomgr_windows.cc +1 -0
- data/src/core/lib/iomgr/lockfree_event.cc +3 -3
- data/src/core/lib/iomgr/port.h +11 -0
- data/src/core/lib/iomgr/resource_quota.cc +40 -37
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
- data/src/core/lib/iomgr/socket_windows.cc +19 -0
- data/src/core/lib/iomgr/socket_windows.h +8 -0
- data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
- data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
- data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
- data/src/core/lib/iomgr/tcp_client_windows.cc +1 -1
- data/src/core/lib/iomgr/tcp_custom.cc +9 -9
- data/src/core/lib/iomgr/tcp_posix.cc +41 -41
- data/src/core/lib/iomgr/tcp_server_custom.cc +3 -3
- data/src/core/lib/iomgr/tcp_server_posix.cc +14 -1
- data/src/core/lib/iomgr/tcp_server_windows.cc +2 -2
- data/src/core/lib/iomgr/tcp_windows.cc +7 -9
- data/src/core/lib/iomgr/timer_generic.cc +16 -16
- data/src/core/lib/iomgr/timer_manager.cc +12 -11
- data/src/core/lib/profiling/basic_timers.cc +10 -4
- data/src/core/lib/security/context/security_context.cc +6 -7
- data/src/core/lib/security/context/security_context.h +3 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -3
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +7 -7
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
- data/src/core/lib/security/security_connector/security_connector.cc +0 -1
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +3 -2
- data/src/core/lib/security/security_connector/ssl_utils.cc +30 -26
- data/src/core/lib/security/security_connector/ssl_utils.h +5 -1
- data/src/core/lib/security/transport/client_auth_filter.cc +7 -11
- data/src/core/lib/security/transport/secure_endpoint.cc +4 -4
- data/src/core/lib/security/transport/server_auth_filter.cc +2 -3
- data/src/core/lib/slice/slice.cc +99 -116
- data/src/core/lib/slice/slice_buffer.cc +5 -0
- data/src/core/lib/slice/slice_intern.cc +38 -95
- data/src/core/lib/slice/slice_internal.h +200 -2
- data/src/core/lib/surface/api_trace.h +1 -1
- data/src/core/lib/surface/call.cc +41 -35
- data/src/core/lib/surface/call.h +7 -2
- data/src/core/lib/surface/call_details.cc +0 -1
- data/src/core/lib/surface/completion_queue.cc +36 -27
- data/src/core/lib/surface/init.cc +3 -4
- data/src/core/lib/surface/lame_client.cc +1 -1
- data/src/core/lib/surface/server.cc +18 -25
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/lib/transport/bdp_estimator.cc +3 -3
- data/src/core/lib/transport/bdp_estimator.h +2 -2
- data/src/core/lib/transport/connectivity_state.cc +10 -40
- data/src/core/lib/transport/connectivity_state.h +0 -8
- data/src/core/lib/transport/error_utils.cc +12 -0
- data/src/core/lib/transport/metadata.cc +206 -278
- data/src/core/lib/transport/metadata.h +205 -10
- data/src/core/lib/transport/static_metadata.cc +108 -116
- data/src/core/lib/transport/static_metadata.h +1 -2
- data/src/core/lib/transport/status_metadata.cc +3 -3
- data/src/core/lib/transport/transport.cc +29 -66
- data/src/core/lib/transport/transport.h +36 -8
- data/src/core/lib/transport/transport_impl.h +1 -1
- data/src/core/tsi/fake_transport_security.cc +4 -4
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
- data/src/core/tsi/ssl_transport_security.cc +1 -1
- data/src/ruby/ext/grpc/rb_grpc.c +1 -1
- data/src/ruby/lib/grpc/errors.rb +22 -3
- data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/errors_spec.rb +141 -0
- metadata +57 -33
- data/src/core/lib/gpr/arena.cc +0 -192
@@ -41,15 +41,78 @@
|
|
41
41
|
// when it is done with the action that was kicked off by the original
|
42
42
|
// callback.
|
43
43
|
|
44
|
-
|
44
|
+
namespace grpc_core {
|
45
|
+
|
46
|
+
extern TraceFlag grpc_call_combiner_trace;
|
47
|
+
|
48
|
+
class CallCombiner {
|
49
|
+
public:
|
50
|
+
CallCombiner();
|
51
|
+
~CallCombiner();
|
52
|
+
|
53
|
+
#ifndef NDEBUG
|
54
|
+
#define GRPC_CALL_COMBINER_START(call_combiner, closure, error, reason) \
|
55
|
+
(call_combiner)->Start((closure), (error), __FILE__, __LINE__, (reason))
|
56
|
+
#define GRPC_CALL_COMBINER_STOP(call_combiner, reason) \
|
57
|
+
(call_combiner)->Stop(__FILE__, __LINE__, (reason))
|
58
|
+
/// Starts processing \a closure.
|
59
|
+
void Start(grpc_closure* closure, grpc_error* error, const char* file,
|
60
|
+
int line, const char* reason);
|
61
|
+
/// Yields the call combiner to the next closure in the queue, if any.
|
62
|
+
void Stop(const char* file, int line, const char* reason);
|
63
|
+
#else
|
64
|
+
#define GRPC_CALL_COMBINER_START(call_combiner, closure, error, reason) \
|
65
|
+
(call_combiner)->Start((closure), (error), (reason))
|
66
|
+
#define GRPC_CALL_COMBINER_STOP(call_combiner, reason) \
|
67
|
+
(call_combiner)->Stop((reason))
|
68
|
+
/// Starts processing \a closure.
|
69
|
+
void Start(grpc_closure* closure, grpc_error* error, const char* reason);
|
70
|
+
/// Yields the call combiner to the next closure in the queue, if any.
|
71
|
+
void Stop(const char* reason);
|
72
|
+
#endif
|
73
|
+
|
74
|
+
/// Registers \a closure to be invoked when Cancel() is called.
|
75
|
+
///
|
76
|
+
/// Once a closure is registered, it will always be scheduled exactly
|
77
|
+
/// once; this allows the closure to hold references that will be freed
|
78
|
+
/// regardless of whether or not the call was cancelled. If a cancellation
|
79
|
+
/// does occur, the closure will be scheduled with the cancellation error;
|
80
|
+
/// otherwise, it will be scheduled with GRPC_ERROR_NONE.
|
81
|
+
///
|
82
|
+
/// The closure will be scheduled in the following cases:
|
83
|
+
/// - If Cancel() was called prior to registering the closure, it will be
|
84
|
+
/// scheduled immediately with the cancelation error.
|
85
|
+
/// - If Cancel() is called after registering the closure, the closure will
|
86
|
+
/// be scheduled with the cancellation error.
|
87
|
+
/// - If SetNotifyOnCancel() is called again to register a new cancellation
|
88
|
+
/// closure, the previous cancellation closure will be scheduled with
|
89
|
+
/// GRPC_ERROR_NONE.
|
90
|
+
///
|
91
|
+
/// If \a closure is NULL, then no closure will be invoked on
|
92
|
+
/// cancellation; this effectively unregisters the previously set closure.
|
93
|
+
/// However, most filters will not need to explicitly unregister their
|
94
|
+
/// callbacks, as this is done automatically when the call is destroyed.
|
95
|
+
/// Filters that schedule the cancellation closure on ExecCtx do not need
|
96
|
+
/// to take a ref on the call stack to guarantee closure liveness. This is
|
97
|
+
/// done by explicitly flushing ExecCtx after the unregistration during
|
98
|
+
/// call destruction.
|
99
|
+
void SetNotifyOnCancel(grpc_closure* closure);
|
100
|
+
|
101
|
+
/// Indicates that the call has been cancelled.
|
102
|
+
void Cancel(grpc_error* error);
|
103
|
+
|
104
|
+
private:
|
105
|
+
void ScheduleClosure(grpc_closure* closure, grpc_error* error);
|
106
|
+
#ifdef GRPC_TSAN_ENABLED
|
107
|
+
static void TsanClosure(void* arg, grpc_error* error);
|
108
|
+
#endif
|
45
109
|
|
46
|
-
|
47
|
-
|
48
|
-
gpr_mpscq queue;
|
110
|
+
gpr_atm size_ = 0; // size_t, num closures in queue or currently executing
|
111
|
+
gpr_mpscq queue_;
|
49
112
|
// Either 0 (if not cancelled and no cancellation closure set),
|
50
113
|
// a grpc_closure* (if the lowest bit is 0),
|
51
114
|
// or a grpc_error* (if the lowest bit is 1).
|
52
|
-
gpr_atm
|
115
|
+
gpr_atm cancel_state_ = 0;
|
53
116
|
#ifdef GRPC_TSAN_ENABLED
|
54
117
|
// A fake ref-counted lock that is kept alive after the destruction of
|
55
118
|
// grpc_call_combiner, when we are running the original closure.
|
@@ -58,90 +121,20 @@ struct grpc_call_combiner {
|
|
58
121
|
// callback is called. However, original_closure is free to trigger
|
59
122
|
// anything on the call combiner (including destruction of grpc_call).
|
60
123
|
// Thus, we need a ref-counted structure that can outlive the call combiner.
|
61
|
-
struct TsanLock
|
62
|
-
: public grpc_core::RefCounted<TsanLock,
|
63
|
-
grpc_core::NonPolymorphicRefCount> {
|
124
|
+
struct TsanLock : public RefCounted<TsanLock, NonPolymorphicRefCount> {
|
64
125
|
TsanLock() { TSAN_ANNOTATE_RWLOCK_CREATE(&taken); }
|
65
126
|
~TsanLock() { TSAN_ANNOTATE_RWLOCK_DESTROY(&taken); }
|
66
|
-
|
67
127
|
// To avoid double-locking by the same thread, we should acquire/release
|
68
128
|
// the lock only when taken is false. On each acquire taken must be set to
|
69
129
|
// true.
|
70
130
|
std::atomic<bool> taken{false};
|
71
131
|
};
|
72
|
-
|
73
|
-
|
74
|
-
grpc_closure
|
75
|
-
grpc_closure* original_closure;
|
132
|
+
RefCountedPtr<TsanLock> tsan_lock_ = MakeRefCounted<TsanLock>();
|
133
|
+
grpc_closure tsan_closure_;
|
134
|
+
grpc_closure* original_closure_;
|
76
135
|
#endif
|
77
136
|
};
|
78
137
|
|
79
|
-
// Assumes memory was initialized to zero.
|
80
|
-
void grpc_call_combiner_init(grpc_call_combiner* call_combiner);
|
81
|
-
|
82
|
-
void grpc_call_combiner_destroy(grpc_call_combiner* call_combiner);
|
83
|
-
|
84
|
-
#ifndef NDEBUG
|
85
|
-
#define GRPC_CALL_COMBINER_START(call_combiner, closure, error, reason) \
|
86
|
-
grpc_call_combiner_start((call_combiner), (closure), (error), __FILE__, \
|
87
|
-
__LINE__, (reason))
|
88
|
-
#define GRPC_CALL_COMBINER_STOP(call_combiner, reason) \
|
89
|
-
grpc_call_combiner_stop((call_combiner), __FILE__, __LINE__, (reason))
|
90
|
-
/// Starts processing \a closure on \a call_combiner.
|
91
|
-
void grpc_call_combiner_start(grpc_call_combiner* call_combiner,
|
92
|
-
grpc_closure* closure, grpc_error* error,
|
93
|
-
const char* file, int line, const char* reason);
|
94
|
-
/// Yields the call combiner to the next closure in the queue, if any.
|
95
|
-
void grpc_call_combiner_stop(grpc_call_combiner* call_combiner,
|
96
|
-
const char* file, int line, const char* reason);
|
97
|
-
#else
|
98
|
-
#define GRPC_CALL_COMBINER_START(call_combiner, closure, error, reason) \
|
99
|
-
grpc_call_combiner_start((call_combiner), (closure), (error), (reason))
|
100
|
-
#define GRPC_CALL_COMBINER_STOP(call_combiner, reason) \
|
101
|
-
grpc_call_combiner_stop((call_combiner), (reason))
|
102
|
-
/// Starts processing \a closure on \a call_combiner.
|
103
|
-
void grpc_call_combiner_start(grpc_call_combiner* call_combiner,
|
104
|
-
grpc_closure* closure, grpc_error* error,
|
105
|
-
const char* reason);
|
106
|
-
/// Yields the call combiner to the next closure in the queue, if any.
|
107
|
-
void grpc_call_combiner_stop(grpc_call_combiner* call_combiner,
|
108
|
-
const char* reason);
|
109
|
-
#endif
|
110
|
-
|
111
|
-
/// Registers \a closure to be invoked by \a call_combiner when
|
112
|
-
/// grpc_call_combiner_cancel() is called.
|
113
|
-
///
|
114
|
-
/// Once a closure is registered, it will always be scheduled exactly
|
115
|
-
/// once; this allows the closure to hold references that will be freed
|
116
|
-
/// regardless of whether or not the call was cancelled. If a cancellation
|
117
|
-
/// does occur, the closure will be scheduled with the cancellation error;
|
118
|
-
/// otherwise, it will be scheduled with GRPC_ERROR_NONE.
|
119
|
-
///
|
120
|
-
/// The closure will be scheduled in the following cases:
|
121
|
-
/// - If grpc_call_combiner_cancel() was called prior to registering the
|
122
|
-
/// closure, it will be scheduled immediately with the cancelation error.
|
123
|
-
/// - If grpc_call_combiner_cancel() is called after registering the
|
124
|
-
/// closure, the closure will be scheduled with the cancellation error.
|
125
|
-
/// - If grpc_call_combiner_set_notify_on_cancel() is called again to
|
126
|
-
/// register a new cancellation closure, the previous cancellation
|
127
|
-
/// closure will be scheduled with GRPC_ERROR_NONE.
|
128
|
-
///
|
129
|
-
/// If \a closure is NULL, then no closure will be invoked on
|
130
|
-
/// cancellation; this effectively unregisters the previously set closure.
|
131
|
-
/// However, most filters will not need to explicitly unregister their
|
132
|
-
/// callbacks, as this is done automatically when the call is destroyed. Filters
|
133
|
-
/// that schedule the cancellation closure on ExecCtx do not need to take a ref
|
134
|
-
/// on the call stack to guarantee closure liveness. This is done by explicitly
|
135
|
-
/// flushing ExecCtx after the unregistration during call destruction.
|
136
|
-
void grpc_call_combiner_set_notify_on_cancel(grpc_call_combiner* call_combiner,
|
137
|
-
grpc_closure* closure);
|
138
|
-
|
139
|
-
/// Indicates that the call has been cancelled.
|
140
|
-
void grpc_call_combiner_cancel(grpc_call_combiner* call_combiner,
|
141
|
-
grpc_error* error);
|
142
|
-
|
143
|
-
namespace grpc_core {
|
144
|
-
|
145
138
|
// Helper for running a list of closures in a call combiner.
|
146
139
|
//
|
147
140
|
// Each callback running in the call combiner will eventually be
|
@@ -166,7 +159,7 @@ class CallCombinerClosureList {
|
|
166
159
|
// scheduled via GRPC_CLOSURE_SCHED(), which will eventually result in
|
167
160
|
// yielding the call combiner. If the list is empty, then the call
|
168
161
|
// combiner will be yielded immediately.
|
169
|
-
void RunClosures(
|
162
|
+
void RunClosures(CallCombiner* call_combiner) {
|
170
163
|
if (closures_.empty()) {
|
171
164
|
GRPC_CALL_COMBINER_STOP(call_combiner, "no closures to schedule");
|
172
165
|
return;
|
@@ -176,7 +169,7 @@ class CallCombinerClosureList {
|
|
176
169
|
GRPC_CALL_COMBINER_START(call_combiner, closure.closure, closure.error,
|
177
170
|
closure.reason);
|
178
171
|
}
|
179
|
-
if (grpc_call_combiner_trace
|
172
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
|
180
173
|
gpr_log(GPR_INFO,
|
181
174
|
"CallCombinerClosureList executing closure while already "
|
182
175
|
"holding call_combiner %p: closure=%p error=%s reason=%s",
|
@@ -190,7 +183,7 @@ class CallCombinerClosureList {
|
|
190
183
|
|
191
184
|
// Runs all closures in the call combiner, but does NOT yield the call
|
192
185
|
// combiner. All closures will be scheduled via GRPC_CALL_COMBINER_START().
|
193
|
-
void RunClosuresWithoutYielding(
|
186
|
+
void RunClosuresWithoutYielding(CallCombiner* call_combiner) {
|
194
187
|
for (size_t i = 0; i < closures_.size(); ++i) {
|
195
188
|
auto& closure = closures_[i];
|
196
189
|
GRPC_CALL_COMBINER_START(call_combiner, closure.closure, closure.error,
|
@@ -0,0 +1,202 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2018 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/iomgr/port.h"
|
22
|
+
|
23
|
+
#ifdef GRPC_CFSTREAM
|
24
|
+
#import <CoreFoundation/CoreFoundation.h>
|
25
|
+
#import "src/core/lib/iomgr/cfstream_handle.h"
|
26
|
+
|
27
|
+
#include <grpc/support/atm.h>
|
28
|
+
#include <grpc/support/sync.h>
|
29
|
+
|
30
|
+
#include "src/core/lib/debug/trace.h"
|
31
|
+
#include "src/core/lib/iomgr/closure.h"
|
32
|
+
#include "src/core/lib/iomgr/error_cfstream.h"
|
33
|
+
#include "src/core/lib/iomgr/exec_ctx.h"
|
34
|
+
|
35
|
+
extern grpc_core::TraceFlag grpc_tcp_trace;
|
36
|
+
|
37
|
+
void* CFStreamHandle::Retain(void* info) {
|
38
|
+
CFStreamHandle* handle = static_cast<CFStreamHandle*>(info);
|
39
|
+
CFSTREAM_HANDLE_REF(handle, "retain");
|
40
|
+
return info;
|
41
|
+
}
|
42
|
+
|
43
|
+
void CFStreamHandle::Release(void* info) {
|
44
|
+
CFStreamHandle* handle = static_cast<CFStreamHandle*>(info);
|
45
|
+
CFSTREAM_HANDLE_UNREF(handle, "release");
|
46
|
+
}
|
47
|
+
|
48
|
+
CFStreamHandle* CFStreamHandle::CreateStreamHandle(
|
49
|
+
CFReadStreamRef read_stream, CFWriteStreamRef write_stream) {
|
50
|
+
return new CFStreamHandle(read_stream, write_stream);
|
51
|
+
}
|
52
|
+
|
53
|
+
void CFStreamHandle::ReadCallback(CFReadStreamRef stream,
|
54
|
+
CFStreamEventType type,
|
55
|
+
void* client_callback_info) {
|
56
|
+
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
|
57
|
+
grpc_core::ExecCtx exec_ctx;
|
58
|
+
grpc_error* error;
|
59
|
+
CFErrorRef stream_error;
|
60
|
+
CFStreamHandle* handle = static_cast<CFStreamHandle*>(client_callback_info);
|
61
|
+
if (grpc_tcp_trace.enabled()) {
|
62
|
+
gpr_log(GPR_DEBUG, "CFStream ReadCallback (%p, %p, %lu, %p)", handle,
|
63
|
+
stream, type, client_callback_info);
|
64
|
+
}
|
65
|
+
switch (type) {
|
66
|
+
case kCFStreamEventOpenCompleted:
|
67
|
+
handle->open_event_.SetReady();
|
68
|
+
break;
|
69
|
+
case kCFStreamEventHasBytesAvailable:
|
70
|
+
case kCFStreamEventEndEncountered:
|
71
|
+
handle->read_event_.SetReady();
|
72
|
+
break;
|
73
|
+
case kCFStreamEventErrorOccurred:
|
74
|
+
stream_error = CFReadStreamCopyError(stream);
|
75
|
+
error = grpc_error_set_int(
|
76
|
+
GRPC_ERROR_CREATE_FROM_CFERROR(stream_error, "read error"),
|
77
|
+
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
|
78
|
+
CFRelease(stream_error);
|
79
|
+
handle->open_event_.SetShutdown(GRPC_ERROR_REF(error));
|
80
|
+
handle->write_event_.SetShutdown(GRPC_ERROR_REF(error));
|
81
|
+
handle->read_event_.SetShutdown(GRPC_ERROR_REF(error));
|
82
|
+
GRPC_ERROR_UNREF(error);
|
83
|
+
break;
|
84
|
+
default:
|
85
|
+
GPR_UNREACHABLE_CODE(return );
|
86
|
+
}
|
87
|
+
}
|
88
|
+
void CFStreamHandle::WriteCallback(CFWriteStreamRef stream,
|
89
|
+
CFStreamEventType type,
|
90
|
+
void* clientCallBackInfo) {
|
91
|
+
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
|
92
|
+
grpc_core::ExecCtx exec_ctx;
|
93
|
+
grpc_error* error;
|
94
|
+
CFErrorRef stream_error;
|
95
|
+
CFStreamHandle* handle = static_cast<CFStreamHandle*>(clientCallBackInfo);
|
96
|
+
if (grpc_tcp_trace.enabled()) {
|
97
|
+
gpr_log(GPR_DEBUG, "CFStream WriteCallback (%p, %p, %lu, %p)", handle,
|
98
|
+
stream, type, clientCallBackInfo);
|
99
|
+
}
|
100
|
+
switch (type) {
|
101
|
+
case kCFStreamEventOpenCompleted:
|
102
|
+
handle->open_event_.SetReady();
|
103
|
+
break;
|
104
|
+
case kCFStreamEventCanAcceptBytes:
|
105
|
+
case kCFStreamEventEndEncountered:
|
106
|
+
handle->write_event_.SetReady();
|
107
|
+
break;
|
108
|
+
case kCFStreamEventErrorOccurred:
|
109
|
+
stream_error = CFWriteStreamCopyError(stream);
|
110
|
+
error = grpc_error_set_int(
|
111
|
+
GRPC_ERROR_CREATE_FROM_CFERROR(stream_error, "write error"),
|
112
|
+
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
|
113
|
+
CFRelease(stream_error);
|
114
|
+
handle->open_event_.SetShutdown(GRPC_ERROR_REF(error));
|
115
|
+
handle->write_event_.SetShutdown(GRPC_ERROR_REF(error));
|
116
|
+
handle->read_event_.SetShutdown(GRPC_ERROR_REF(error));
|
117
|
+
GRPC_ERROR_UNREF(error);
|
118
|
+
break;
|
119
|
+
default:
|
120
|
+
GPR_UNREACHABLE_CODE(return );
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
CFStreamHandle::CFStreamHandle(CFReadStreamRef read_stream,
|
125
|
+
CFWriteStreamRef write_stream) {
|
126
|
+
gpr_ref_init(&refcount_, 1);
|
127
|
+
open_event_.InitEvent();
|
128
|
+
read_event_.InitEvent();
|
129
|
+
write_event_.InitEvent();
|
130
|
+
dispatch_queue_ = dispatch_queue_create(nullptr, DISPATCH_QUEUE_SERIAL);
|
131
|
+
CFStreamClientContext ctx = {0, static_cast<void*>(this),
|
132
|
+
CFStreamHandle::Retain, CFStreamHandle::Release,
|
133
|
+
nil};
|
134
|
+
CFReadStreamSetClient(
|
135
|
+
read_stream,
|
136
|
+
kCFStreamEventOpenCompleted | kCFStreamEventHasBytesAvailable |
|
137
|
+
kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered,
|
138
|
+
CFStreamHandle::ReadCallback, &ctx);
|
139
|
+
CFWriteStreamSetClient(
|
140
|
+
write_stream,
|
141
|
+
kCFStreamEventOpenCompleted | kCFStreamEventCanAcceptBytes |
|
142
|
+
kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered,
|
143
|
+
CFStreamHandle::WriteCallback, &ctx);
|
144
|
+
CFReadStreamSetDispatchQueue(read_stream, dispatch_queue_);
|
145
|
+
CFWriteStreamSetDispatchQueue(write_stream, dispatch_queue_);
|
146
|
+
}
|
147
|
+
|
148
|
+
CFStreamHandle::~CFStreamHandle() {
|
149
|
+
open_event_.DestroyEvent();
|
150
|
+
read_event_.DestroyEvent();
|
151
|
+
write_event_.DestroyEvent();
|
152
|
+
}
|
153
|
+
|
154
|
+
void CFStreamHandle::NotifyOnOpen(grpc_closure* closure) {
|
155
|
+
open_event_.NotifyOn(closure);
|
156
|
+
}
|
157
|
+
|
158
|
+
void CFStreamHandle::NotifyOnRead(grpc_closure* closure) {
|
159
|
+
read_event_.NotifyOn(closure);
|
160
|
+
}
|
161
|
+
|
162
|
+
void CFStreamHandle::NotifyOnWrite(grpc_closure* closure) {
|
163
|
+
write_event_.NotifyOn(closure);
|
164
|
+
}
|
165
|
+
|
166
|
+
void CFStreamHandle::Shutdown(grpc_error* error) {
|
167
|
+
open_event_.SetShutdown(GRPC_ERROR_REF(error));
|
168
|
+
read_event_.SetShutdown(GRPC_ERROR_REF(error));
|
169
|
+
write_event_.SetShutdown(GRPC_ERROR_REF(error));
|
170
|
+
GRPC_ERROR_UNREF(error);
|
171
|
+
}
|
172
|
+
|
173
|
+
void CFStreamHandle::Ref(const char* file, int line, const char* reason) {
|
174
|
+
if (grpc_tcp_trace.enabled()) {
|
175
|
+
gpr_atm val = gpr_atm_no_barrier_load(&refcount_.count);
|
176
|
+
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
|
177
|
+
"CFStream Handle ref %p : %s %" PRIdPTR " -> %" PRIdPTR, this,
|
178
|
+
reason, val, val + 1);
|
179
|
+
}
|
180
|
+
gpr_ref(&refcount_);
|
181
|
+
}
|
182
|
+
|
183
|
+
void CFStreamHandle::Unref(const char* file, int line, const char* reason) {
|
184
|
+
if (grpc_tcp_trace.enabled()) {
|
185
|
+
gpr_atm val = gpr_atm_no_barrier_load(&refcount_.count);
|
186
|
+
gpr_log(GPR_ERROR,
|
187
|
+
"CFStream Handle unref %p : %s %" PRIdPTR " -> %" PRIdPTR, this,
|
188
|
+
reason, val, val - 1);
|
189
|
+
}
|
190
|
+
if (gpr_unref(&refcount_)) {
|
191
|
+
delete this;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
#else
|
196
|
+
|
197
|
+
/* Creating a dummy function so that the grpc_cfstream library will be
|
198
|
+
* non-empty.
|
199
|
+
*/
|
200
|
+
void CFStreamDummy() {}
|
201
|
+
|
202
|
+
#endif
|
@@ -0,0 +1,82 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2018 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
|
+
/* The CFStream handle acts as an event synchronization entity for
|
20
|
+
* read/write/open/error/eos events happening on CFStream streams. */
|
21
|
+
|
22
|
+
#ifndef GRPC_CORE_LIB_IOMGR_CFSTREAM_HANDLE_H
|
23
|
+
#define GRPC_CORE_LIB_IOMGR_CFSTREAM_HANDLE_H
|
24
|
+
|
25
|
+
#include <grpc/support/port_platform.h>
|
26
|
+
|
27
|
+
#include "src/core/lib/iomgr/port.h"
|
28
|
+
|
29
|
+
#ifdef GRPC_CFSTREAM
|
30
|
+
#import <CoreFoundation/CoreFoundation.h>
|
31
|
+
|
32
|
+
#include "src/core/lib/iomgr/closure.h"
|
33
|
+
#include "src/core/lib/iomgr/lockfree_event.h"
|
34
|
+
|
35
|
+
class CFStreamHandle final {
|
36
|
+
public:
|
37
|
+
static CFStreamHandle* CreateStreamHandle(CFReadStreamRef read_stream,
|
38
|
+
CFWriteStreamRef write_stream);
|
39
|
+
~CFStreamHandle();
|
40
|
+
CFStreamHandle(const CFStreamHandle& ref) = delete;
|
41
|
+
CFStreamHandle(CFStreamHandle&& ref) = delete;
|
42
|
+
CFStreamHandle& operator=(const CFStreamHandle& rhs) = delete;
|
43
|
+
|
44
|
+
void NotifyOnOpen(grpc_closure* closure);
|
45
|
+
void NotifyOnRead(grpc_closure* closure);
|
46
|
+
void NotifyOnWrite(grpc_closure* closure);
|
47
|
+
void Shutdown(grpc_error* error);
|
48
|
+
|
49
|
+
void Ref(const char* file = "", int line = 0, const char* reason = nullptr);
|
50
|
+
void Unref(const char* file = "", int line = 0, const char* reason = nullptr);
|
51
|
+
|
52
|
+
private:
|
53
|
+
CFStreamHandle(CFReadStreamRef read_stream, CFWriteStreamRef write_stream);
|
54
|
+
static void ReadCallback(CFReadStreamRef stream, CFStreamEventType type,
|
55
|
+
void* client_callback_info);
|
56
|
+
static void WriteCallback(CFWriteStreamRef stream, CFStreamEventType type,
|
57
|
+
void* client_callback_info);
|
58
|
+
static void* Retain(void* info);
|
59
|
+
static void Release(void* info);
|
60
|
+
|
61
|
+
grpc_core::LockfreeEvent open_event_;
|
62
|
+
grpc_core::LockfreeEvent read_event_;
|
63
|
+
grpc_core::LockfreeEvent write_event_;
|
64
|
+
|
65
|
+
dispatch_queue_t dispatch_queue_;
|
66
|
+
|
67
|
+
gpr_refcount refcount_;
|
68
|
+
};
|
69
|
+
|
70
|
+
#ifdef DEBUG
|
71
|
+
#define CFSTREAM_HANDLE_REF(handle, reason) \
|
72
|
+
(handle)->Ref(__FILE__, __LINE__, (reason))
|
73
|
+
#define CFSTREAM_HANDLE_UNREF(handle, reason) \
|
74
|
+
(handle)->Unref(__FILE__, __LINE__, (reason))
|
75
|
+
#else
|
76
|
+
#define CFSTREAM_HANDLE_REF(handle, reason) (handle)->Ref()
|
77
|
+
#define CFSTREAM_HANDLE_UNREF(handle, reason) (handle)->Unref()
|
78
|
+
#endif
|
79
|
+
|
80
|
+
#endif
|
81
|
+
|
82
|
+
#endif /* GRPC_CORE_LIB_IOMGR_CFSTREAM_HANDLE_H */
|