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
@@ -31,7 +31,7 @@
|
|
31
31
|
// Provides serialized access to some resource.
|
32
32
|
// Each action queued on a combiner is executed serially in a borrowed thread.
|
33
33
|
// The actual thread executing actions may change over time (but there will only
|
34
|
-
//
|
34
|
+
// ever be one at a time).
|
35
35
|
|
36
36
|
// Initialize the lock, with an optional workqueue to shift load to when
|
37
37
|
// necessary
|
@@ -0,0 +1,375 @@
|
|
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_ENDPOINT
|
24
|
+
|
25
|
+
#import <CoreFoundation/CoreFoundation.h>
|
26
|
+
#import "src/core/lib/iomgr/endpoint_cfstream.h"
|
27
|
+
|
28
|
+
#include <grpc/slice_buffer.h>
|
29
|
+
#include <grpc/support/alloc.h>
|
30
|
+
#include <grpc/support/string_util.h>
|
31
|
+
|
32
|
+
#include "src/core/lib/gpr/string.h"
|
33
|
+
#include "src/core/lib/iomgr/cfstream_handle.h"
|
34
|
+
#include "src/core/lib/iomgr/closure.h"
|
35
|
+
#include "src/core/lib/iomgr/endpoint.h"
|
36
|
+
#include "src/core/lib/iomgr/error_cfstream.h"
|
37
|
+
#include "src/core/lib/slice/slice_internal.h"
|
38
|
+
#include "src/core/lib/slice/slice_string_helpers.h"
|
39
|
+
|
40
|
+
extern grpc_core::TraceFlag grpc_tcp_trace;
|
41
|
+
|
42
|
+
typedef struct {
|
43
|
+
grpc_endpoint base;
|
44
|
+
gpr_refcount refcount;
|
45
|
+
|
46
|
+
CFReadStreamRef read_stream;
|
47
|
+
CFWriteStreamRef write_stream;
|
48
|
+
CFStreamHandle* stream_sync;
|
49
|
+
|
50
|
+
grpc_closure* read_cb;
|
51
|
+
grpc_closure* write_cb;
|
52
|
+
grpc_slice_buffer* read_slices;
|
53
|
+
grpc_slice_buffer* write_slices;
|
54
|
+
|
55
|
+
grpc_closure read_action;
|
56
|
+
grpc_closure write_action;
|
57
|
+
|
58
|
+
char* peer_string;
|
59
|
+
grpc_resource_user* resource_user;
|
60
|
+
grpc_resource_user_slice_allocator slice_allocator;
|
61
|
+
} CFStreamEndpoint;
|
62
|
+
|
63
|
+
static void CFStreamFree(CFStreamEndpoint* ep) {
|
64
|
+
grpc_resource_user_unref(ep->resource_user);
|
65
|
+
CFRelease(ep->read_stream);
|
66
|
+
CFRelease(ep->write_stream);
|
67
|
+
CFSTREAM_HANDLE_UNREF(ep->stream_sync, "free");
|
68
|
+
gpr_free(ep->peer_string);
|
69
|
+
gpr_free(ep);
|
70
|
+
}
|
71
|
+
|
72
|
+
#ifndef NDEBUG
|
73
|
+
#define EP_REF(ep, reason) CFStreamRef((ep), (reason), __FILE__, __LINE__)
|
74
|
+
#define EP_UNREF(ep, reason) CFStreamUnref((ep), (reason), __FILE__, __LINE__)
|
75
|
+
static void CFStreamUnref(CFStreamEndpoint* ep, const char* reason,
|
76
|
+
const char* file, int line) {
|
77
|
+
if (grpc_tcp_trace.enabled()) {
|
78
|
+
gpr_atm val = gpr_atm_no_barrier_load(&ep->refcount.count);
|
79
|
+
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
|
80
|
+
"CFStream endpoint unref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep,
|
81
|
+
reason, val, val - 1);
|
82
|
+
}
|
83
|
+
if (gpr_unref(&ep->refcount)) {
|
84
|
+
CFStreamFree(ep);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
static void CFStreamRef(CFStreamEndpoint* ep, const char* reason,
|
88
|
+
const char* file, int line) {
|
89
|
+
if (grpc_tcp_trace.enabled()) {
|
90
|
+
gpr_atm val = gpr_atm_no_barrier_load(&ep->refcount.count);
|
91
|
+
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
|
92
|
+
"CFStream endpoint ref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep,
|
93
|
+
reason, val, val + 1);
|
94
|
+
}
|
95
|
+
gpr_ref(&ep->refcount);
|
96
|
+
}
|
97
|
+
#else
|
98
|
+
#define EP_REF(ep, reason) CFStreamRef((ep))
|
99
|
+
#define EP_UNREF(ep, reason) CFStreamUnref((ep))
|
100
|
+
static void CFStreamUnref(CFStreamEndpoint* ep) {
|
101
|
+
if (gpr_unref(&ep->refcount)) {
|
102
|
+
CFStreamFree(ep);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
static void CFStreamRef(CFStreamEndpoint* ep) { gpr_ref(&ep->refcount); }
|
106
|
+
#endif
|
107
|
+
|
108
|
+
static grpc_error* CFStreamAnnotateError(grpc_error* src_error,
|
109
|
+
CFStreamEndpoint* ep) {
|
110
|
+
return grpc_error_set_str(
|
111
|
+
grpc_error_set_int(src_error, GRPC_ERROR_INT_GRPC_STATUS,
|
112
|
+
GRPC_STATUS_UNAVAILABLE),
|
113
|
+
GRPC_ERROR_STR_TARGET_ADDRESS,
|
114
|
+
grpc_slice_from_copied_string(ep->peer_string));
|
115
|
+
}
|
116
|
+
|
117
|
+
static void CallReadCb(CFStreamEndpoint* ep, grpc_error* error) {
|
118
|
+
if (grpc_tcp_trace.enabled()) {
|
119
|
+
gpr_log(GPR_DEBUG, "CFStream endpoint:%p call_read_cb %p %p:%p", ep,
|
120
|
+
ep->read_cb, ep->read_cb->cb, ep->read_cb->cb_arg);
|
121
|
+
size_t i;
|
122
|
+
const char* str = grpc_error_string(error);
|
123
|
+
gpr_log(GPR_DEBUG, "read: error=%s", str);
|
124
|
+
|
125
|
+
for (i = 0; i < ep->read_slices->count; i++) {
|
126
|
+
char* dump = grpc_dump_slice(ep->read_slices->slices[i],
|
127
|
+
GPR_DUMP_HEX | GPR_DUMP_ASCII);
|
128
|
+
gpr_log(GPR_DEBUG, "READ %p (peer=%s): %s", ep, ep->peer_string, dump);
|
129
|
+
gpr_free(dump);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
grpc_closure* cb = ep->read_cb;
|
133
|
+
ep->read_cb = nullptr;
|
134
|
+
ep->read_slices = nullptr;
|
135
|
+
GRPC_CLOSURE_SCHED(cb, error);
|
136
|
+
}
|
137
|
+
|
138
|
+
static void CallWriteCb(CFStreamEndpoint* ep, grpc_error* error) {
|
139
|
+
if (grpc_tcp_trace.enabled()) {
|
140
|
+
gpr_log(GPR_DEBUG, "CFStream endpoint:%p call_write_cb %p %p:%p", ep,
|
141
|
+
ep->write_cb, ep->write_cb->cb, ep->write_cb->cb_arg);
|
142
|
+
const char* str = grpc_error_string(error);
|
143
|
+
gpr_log(GPR_DEBUG, "write: error=%s", str);
|
144
|
+
}
|
145
|
+
grpc_closure* cb = ep->write_cb;
|
146
|
+
ep->write_cb = nullptr;
|
147
|
+
ep->write_slices = nullptr;
|
148
|
+
GRPC_CLOSURE_SCHED(cb, error);
|
149
|
+
}
|
150
|
+
|
151
|
+
static void ReadAction(void* arg, grpc_error* error) {
|
152
|
+
CFStreamEndpoint* ep = static_cast<CFStreamEndpoint*>(arg);
|
153
|
+
GPR_ASSERT(ep->read_cb != nullptr);
|
154
|
+
if (error) {
|
155
|
+
grpc_slice_buffer_reset_and_unref_internal(ep->read_slices);
|
156
|
+
CallReadCb(ep, GRPC_ERROR_REF(error));
|
157
|
+
EP_UNREF(ep, "read");
|
158
|
+
return;
|
159
|
+
}
|
160
|
+
|
161
|
+
GPR_ASSERT(ep->read_slices->count == 1);
|
162
|
+
grpc_slice slice = ep->read_slices->slices[0];
|
163
|
+
size_t len = GRPC_SLICE_LENGTH(slice);
|
164
|
+
CFIndex read_size =
|
165
|
+
CFReadStreamRead(ep->read_stream, GRPC_SLICE_START_PTR(slice), len);
|
166
|
+
if (read_size == -1) {
|
167
|
+
grpc_slice_buffer_reset_and_unref_internal(ep->read_slices);
|
168
|
+
CFErrorRef stream_error = CFReadStreamCopyError(ep->read_stream);
|
169
|
+
if (stream_error != nullptr) {
|
170
|
+
error = CFStreamAnnotateError(
|
171
|
+
GRPC_ERROR_CREATE_FROM_CFERROR(stream_error, "Read error"), ep);
|
172
|
+
CFRelease(stream_error);
|
173
|
+
} else {
|
174
|
+
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Read error");
|
175
|
+
}
|
176
|
+
CallReadCb(ep, error);
|
177
|
+
EP_UNREF(ep, "read");
|
178
|
+
} else if (read_size == 0) {
|
179
|
+
grpc_slice_buffer_reset_and_unref_internal(ep->read_slices);
|
180
|
+
CallReadCb(ep,
|
181
|
+
CFStreamAnnotateError(
|
182
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Socket closed"), ep));
|
183
|
+
EP_UNREF(ep, "read");
|
184
|
+
} else {
|
185
|
+
if (read_size < static_cast<CFIndex>(len)) {
|
186
|
+
grpc_slice_buffer_trim_end(ep->read_slices, len - read_size, nullptr);
|
187
|
+
}
|
188
|
+
CallReadCb(ep, GRPC_ERROR_NONE);
|
189
|
+
EP_UNREF(ep, "read");
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
static void WriteAction(void* arg, grpc_error* error) {
|
194
|
+
CFStreamEndpoint* ep = static_cast<CFStreamEndpoint*>(arg);
|
195
|
+
GPR_ASSERT(ep->write_cb != nullptr);
|
196
|
+
if (error) {
|
197
|
+
grpc_slice_buffer_reset_and_unref_internal(ep->write_slices);
|
198
|
+
CallWriteCb(ep, GRPC_ERROR_REF(error));
|
199
|
+
EP_UNREF(ep, "write");
|
200
|
+
return;
|
201
|
+
}
|
202
|
+
|
203
|
+
grpc_slice slice = grpc_slice_buffer_take_first(ep->write_slices);
|
204
|
+
size_t slice_len = GRPC_SLICE_LENGTH(slice);
|
205
|
+
CFIndex write_size = CFWriteStreamWrite(
|
206
|
+
ep->write_stream, GRPC_SLICE_START_PTR(slice), slice_len);
|
207
|
+
if (write_size == -1) {
|
208
|
+
grpc_slice_buffer_reset_and_unref_internal(ep->write_slices);
|
209
|
+
CFErrorRef stream_error = CFWriteStreamCopyError(ep->write_stream);
|
210
|
+
if (stream_error != nullptr) {
|
211
|
+
error = CFStreamAnnotateError(
|
212
|
+
GRPC_ERROR_CREATE_FROM_CFERROR(stream_error, "write failed."), ep);
|
213
|
+
CFRelease(stream_error);
|
214
|
+
} else {
|
215
|
+
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("write failed.");
|
216
|
+
}
|
217
|
+
CallWriteCb(ep, error);
|
218
|
+
EP_UNREF(ep, "write");
|
219
|
+
} else {
|
220
|
+
if (write_size < static_cast<CFIndex>(GRPC_SLICE_LENGTH(slice))) {
|
221
|
+
grpc_slice_buffer_undo_take_first(
|
222
|
+
ep->write_slices, grpc_slice_sub(slice, write_size, slice_len));
|
223
|
+
}
|
224
|
+
if (ep->write_slices->length > 0) {
|
225
|
+
ep->stream_sync->NotifyOnWrite(&ep->write_action);
|
226
|
+
} else {
|
227
|
+
CallWriteCb(ep, GRPC_ERROR_NONE);
|
228
|
+
EP_UNREF(ep, "write");
|
229
|
+
}
|
230
|
+
|
231
|
+
if (grpc_tcp_trace.enabled()) {
|
232
|
+
grpc_slice trace_slice = grpc_slice_sub(slice, 0, write_size);
|
233
|
+
char* dump = grpc_dump_slice(trace_slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
|
234
|
+
gpr_log(GPR_DEBUG, "WRITE %p (peer=%s): %s", ep, ep->peer_string, dump);
|
235
|
+
gpr_free(dump);
|
236
|
+
grpc_slice_unref_internal(trace_slice);
|
237
|
+
}
|
238
|
+
}
|
239
|
+
grpc_slice_unref_internal(slice);
|
240
|
+
}
|
241
|
+
|
242
|
+
static void CFStreamReadAllocationDone(void* arg, grpc_error* error) {
|
243
|
+
CFStreamEndpoint* ep = static_cast<CFStreamEndpoint*>(arg);
|
244
|
+
if (error == GRPC_ERROR_NONE) {
|
245
|
+
ep->stream_sync->NotifyOnRead(&ep->read_action);
|
246
|
+
} else {
|
247
|
+
grpc_slice_buffer_reset_and_unref_internal(ep->read_slices);
|
248
|
+
CallReadCb(ep, error);
|
249
|
+
EP_UNREF(ep, "read");
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
static void CFStreamRead(grpc_endpoint* ep, grpc_slice_buffer* slices,
|
254
|
+
grpc_closure* cb, bool urgent) {
|
255
|
+
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
|
256
|
+
if (grpc_tcp_trace.enabled()) {
|
257
|
+
gpr_log(GPR_DEBUG, "CFStream endpoint:%p read (%p, %p) length:%zu", ep_impl,
|
258
|
+
slices, cb, slices->length);
|
259
|
+
}
|
260
|
+
GPR_ASSERT(ep_impl->read_cb == nullptr);
|
261
|
+
ep_impl->read_cb = cb;
|
262
|
+
ep_impl->read_slices = slices;
|
263
|
+
grpc_slice_buffer_reset_and_unref_internal(slices);
|
264
|
+
grpc_resource_user_alloc_slices(&ep_impl->slice_allocator,
|
265
|
+
GRPC_TCP_DEFAULT_READ_SLICE_SIZE, 1,
|
266
|
+
ep_impl->read_slices);
|
267
|
+
EP_REF(ep_impl, "read");
|
268
|
+
}
|
269
|
+
|
270
|
+
static void CFStreamWrite(grpc_endpoint* ep, grpc_slice_buffer* slices,
|
271
|
+
grpc_closure* cb, void* arg) {
|
272
|
+
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
|
273
|
+
if (grpc_tcp_trace.enabled()) {
|
274
|
+
gpr_log(GPR_DEBUG, "CFStream endpoint:%p write (%p, %p) length:%zu",
|
275
|
+
ep_impl, slices, cb, slices->length);
|
276
|
+
}
|
277
|
+
GPR_ASSERT(ep_impl->write_cb == nullptr);
|
278
|
+
ep_impl->write_cb = cb;
|
279
|
+
ep_impl->write_slices = slices;
|
280
|
+
EP_REF(ep_impl, "write");
|
281
|
+
ep_impl->stream_sync->NotifyOnWrite(&ep_impl->write_action);
|
282
|
+
}
|
283
|
+
|
284
|
+
void CFStreamShutdown(grpc_endpoint* ep, grpc_error* why) {
|
285
|
+
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
|
286
|
+
if (grpc_tcp_trace.enabled()) {
|
287
|
+
gpr_log(GPR_DEBUG, "CFStream endpoint:%p shutdown (%p)", ep_impl, why);
|
288
|
+
}
|
289
|
+
CFReadStreamClose(ep_impl->read_stream);
|
290
|
+
CFWriteStreamClose(ep_impl->write_stream);
|
291
|
+
ep_impl->stream_sync->Shutdown(why);
|
292
|
+
grpc_resource_user_shutdown(ep_impl->resource_user);
|
293
|
+
if (grpc_tcp_trace.enabled()) {
|
294
|
+
gpr_log(GPR_DEBUG, "CFStream endpoint:%p shutdown DONE (%p)", ep_impl, why);
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
void CFStreamDestroy(grpc_endpoint* ep) {
|
299
|
+
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
|
300
|
+
if (grpc_tcp_trace.enabled()) {
|
301
|
+
gpr_log(GPR_DEBUG, "CFStream endpoint:%p destroy", ep_impl);
|
302
|
+
}
|
303
|
+
EP_UNREF(ep_impl, "destroy");
|
304
|
+
}
|
305
|
+
|
306
|
+
grpc_resource_user* CFStreamGetResourceUser(grpc_endpoint* ep) {
|
307
|
+
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
|
308
|
+
return ep_impl->resource_user;
|
309
|
+
}
|
310
|
+
|
311
|
+
char* CFStreamGetPeer(grpc_endpoint* ep) {
|
312
|
+
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
|
313
|
+
return gpr_strdup(ep_impl->peer_string);
|
314
|
+
}
|
315
|
+
|
316
|
+
int CFStreamGetFD(grpc_endpoint* ep) { return 0; }
|
317
|
+
|
318
|
+
bool CFStreamCanTrackErr(grpc_endpoint* ep) { return false; }
|
319
|
+
|
320
|
+
void CFStreamAddToPollset(grpc_endpoint* ep, grpc_pollset* pollset) {}
|
321
|
+
void CFStreamAddToPollsetSet(grpc_endpoint* ep, grpc_pollset_set* pollset) {}
|
322
|
+
void CFStreamDeleteFromPollsetSet(grpc_endpoint* ep,
|
323
|
+
grpc_pollset_set* pollset) {}
|
324
|
+
|
325
|
+
static const grpc_endpoint_vtable vtable = {CFStreamRead,
|
326
|
+
CFStreamWrite,
|
327
|
+
CFStreamAddToPollset,
|
328
|
+
CFStreamAddToPollsetSet,
|
329
|
+
CFStreamDeleteFromPollsetSet,
|
330
|
+
CFStreamShutdown,
|
331
|
+
CFStreamDestroy,
|
332
|
+
CFStreamGetResourceUser,
|
333
|
+
CFStreamGetPeer,
|
334
|
+
CFStreamGetFD,
|
335
|
+
CFStreamCanTrackErr};
|
336
|
+
|
337
|
+
grpc_endpoint* grpc_cfstream_endpoint_create(
|
338
|
+
CFReadStreamRef read_stream, CFWriteStreamRef write_stream,
|
339
|
+
const char* peer_string, grpc_resource_quota* resource_quota,
|
340
|
+
CFStreamHandle* stream_sync) {
|
341
|
+
CFStreamEndpoint* ep_impl =
|
342
|
+
static_cast<CFStreamEndpoint*>(gpr_malloc(sizeof(CFStreamEndpoint)));
|
343
|
+
if (grpc_tcp_trace.enabled()) {
|
344
|
+
gpr_log(GPR_DEBUG,
|
345
|
+
"CFStream endpoint:%p create readStream:%p writeStream: %p",
|
346
|
+
ep_impl, read_stream, write_stream);
|
347
|
+
}
|
348
|
+
ep_impl->base.vtable = &vtable;
|
349
|
+
gpr_ref_init(&ep_impl->refcount, 1);
|
350
|
+
ep_impl->read_stream = read_stream;
|
351
|
+
ep_impl->write_stream = write_stream;
|
352
|
+
CFRetain(read_stream);
|
353
|
+
CFRetain(write_stream);
|
354
|
+
ep_impl->stream_sync = stream_sync;
|
355
|
+
CFSTREAM_HANDLE_REF(ep_impl->stream_sync, "endpoint create");
|
356
|
+
|
357
|
+
ep_impl->peer_string = gpr_strdup(peer_string);
|
358
|
+
ep_impl->read_cb = nil;
|
359
|
+
ep_impl->write_cb = nil;
|
360
|
+
ep_impl->read_slices = nil;
|
361
|
+
ep_impl->write_slices = nil;
|
362
|
+
GRPC_CLOSURE_INIT(&ep_impl->read_action, ReadAction,
|
363
|
+
static_cast<void*>(ep_impl), grpc_schedule_on_exec_ctx);
|
364
|
+
GRPC_CLOSURE_INIT(&ep_impl->write_action, WriteAction,
|
365
|
+
static_cast<void*>(ep_impl), grpc_schedule_on_exec_ctx);
|
366
|
+
ep_impl->resource_user =
|
367
|
+
grpc_resource_user_create(resource_quota, peer_string);
|
368
|
+
grpc_resource_user_slice_allocator_init(&ep_impl->slice_allocator,
|
369
|
+
ep_impl->resource_user,
|
370
|
+
CFStreamReadAllocationDone, ep_impl);
|
371
|
+
|
372
|
+
return &ep_impl->base;
|
373
|
+
}
|
374
|
+
|
375
|
+
#endif /* GRPC_CFSTREAM_ENDPOINT */
|
@@ -0,0 +1,49 @@
|
|
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
|
+
#ifndef GRPC_CORE_LIB_IOMGR_ENDPOINT_CFSTREAM_H
|
20
|
+
#define GRPC_CORE_LIB_IOMGR_ENDPOINT_CFSTREAM_H
|
21
|
+
/*
|
22
|
+
Low level TCP "bottom half" implementation, for use by transports built on
|
23
|
+
top of a TCP connection.
|
24
|
+
|
25
|
+
Note that this file does not (yet) include APIs for creating the socket in
|
26
|
+
the first place.
|
27
|
+
|
28
|
+
All calls passing slice transfer ownership of a slice refcount unless
|
29
|
+
otherwise specified.
|
30
|
+
*/
|
31
|
+
|
32
|
+
#include <grpc/support/port_platform.h>
|
33
|
+
|
34
|
+
#ifdef GRPC_CFSTREAM
|
35
|
+
|
36
|
+
#import <CoreFoundation/CoreFoundation.h>
|
37
|
+
|
38
|
+
#include "src/core/lib/debug/trace.h"
|
39
|
+
#include "src/core/lib/iomgr/cfstream_handle.h"
|
40
|
+
#include "src/core/lib/iomgr/endpoint.h"
|
41
|
+
|
42
|
+
grpc_endpoint* grpc_cfstream_endpoint_create(
|
43
|
+
CFReadStreamRef read_stream, CFWriteStreamRef write_stream,
|
44
|
+
const char* peer_string, grpc_resource_quota* resource_quota,
|
45
|
+
CFStreamHandle* stream_sync);
|
46
|
+
|
47
|
+
#endif /* GRPC_CFSTREAM */
|
48
|
+
|
49
|
+
#endif /* GRPC_CORE_LIB_IOMGR_ENDPOINT_CFSTREAM_H */
|
@@ -41,7 +41,7 @@ static void create_sockets(SOCKET sv[2]) {
|
|
41
41
|
int addr_len = sizeof(addr);
|
42
42
|
|
43
43
|
lst_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0,
|
44
|
-
|
44
|
+
grpc_get_default_wsa_socket_flags());
|
45
45
|
GPR_ASSERT(lst_sock != INVALID_SOCKET);
|
46
46
|
|
47
47
|
memset(&addr, 0, sizeof(addr));
|
@@ -54,7 +54,7 @@ static void create_sockets(SOCKET sv[2]) {
|
|
54
54
|
SOCKET_ERROR);
|
55
55
|
|
56
56
|
cli_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0,
|
57
|
-
|
57
|
+
grpc_get_default_wsa_socket_flags());
|
58
58
|
GPR_ASSERT(cli_sock != INVALID_SOCKET);
|
59
59
|
|
60
60
|
GPR_ASSERT(WSAConnect(cli_sock, (grpc_sockaddr*)&addr, addr_len, NULL, NULL,
|