grpc 0.13.0 → 0.13.1.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.

Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/Makefile +1114 -937
  4. data/include/grpc/census.h +71 -89
  5. data/include/grpc/compression.h +7 -7
  6. data/include/grpc/grpc.h +65 -68
  7. data/include/grpc/grpc_security.h +38 -38
  8. data/include/grpc/impl/codegen/alloc.h +7 -7
  9. data/include/grpc/impl/codegen/byte_buffer.h +13 -13
  10. data/include/grpc/impl/codegen/grpc_types.h +7 -2
  11. data/include/grpc/impl/codegen/log.h +5 -5
  12. data/include/grpc/impl/codegen/port_platform.h +14 -6
  13. data/include/grpc/impl/codegen/slice.h +15 -15
  14. data/include/grpc/impl/codegen/slice_buffer.h +17 -17
  15. data/include/grpc/impl/codegen/sync.h +26 -22
  16. data/include/grpc/impl/codegen/time.h +22 -24
  17. data/include/grpc/support/avl.h +9 -8
  18. data/include/grpc/support/cmdline.h +12 -12
  19. data/include/grpc/support/cpu.h +2 -2
  20. data/include/grpc/support/histogram.h +22 -22
  21. data/include/grpc/support/host_port.h +2 -2
  22. data/include/grpc/support/log_win32.h +1 -1
  23. data/include/grpc/support/string_util.h +2 -2
  24. data/include/grpc/support/subprocess.h +5 -5
  25. data/include/grpc/support/thd.h +9 -9
  26. data/include/grpc/support/useful.h +3 -1
  27. data/src/core/census/context.c +64 -85
  28. data/src/core/census/grpc_filter.c +2 -2
  29. data/src/core/census/mlog.c +600 -0
  30. data/src/core/census/mlog.h +95 -0
  31. data/src/core/channel/channel_args.c +67 -6
  32. data/src/core/channel/channel_args.h +7 -1
  33. data/src/core/channel/client_channel.c +26 -36
  34. data/src/core/channel/client_uchannel.c +1 -1
  35. data/src/core/channel/http_client_filter.c +2 -2
  36. data/src/core/channel/http_server_filter.c +2 -2
  37. data/src/core/channel/subchannel_call_holder.c +5 -7
  38. data/src/core/client_config/connector.c +3 -2
  39. data/src/core/client_config/connector.h +2 -2
  40. data/src/core/client_config/lb_policies/load_balancer_api.c +163 -0
  41. data/src/core/client_config/lb_policies/load_balancer_api.h +85 -0
  42. data/src/core/client_config/lb_policies/pick_first.c +10 -11
  43. data/src/core/client_config/lb_policies/round_robin.c +7 -8
  44. data/src/core/client_config/lb_policy.c +3 -3
  45. data/src/core/client_config/lb_policy.h +3 -2
  46. data/src/core/client_config/subchannel.c +51 -21
  47. data/src/core/client_config/subchannel.h +15 -6
  48. data/src/core/client_config/subchannel_index.c +261 -0
  49. data/src/core/client_config/subchannel_index.h +77 -0
  50. data/src/core/compression/{algorithm.c → compression_algorithm.c} +0 -0
  51. data/src/core/httpcli/httpcli.c +13 -11
  52. data/src/core/httpcli/httpcli.h +3 -2
  53. data/src/core/httpcli/httpcli_security_connector.c +7 -7
  54. data/src/core/iomgr/fd_posix.c +4 -2
  55. data/src/core/iomgr/iocp_windows.c +10 -6
  56. data/src/core/iomgr/iocp_windows.h +9 -2
  57. data/src/core/iomgr/iomgr.c +18 -2
  58. data/src/core/iomgr/iomgr_internal.h +5 -1
  59. data/src/core/iomgr/pollset.h +9 -10
  60. data/src/core/iomgr/pollset_multipoller_with_epoll.c +1 -0
  61. data/src/core/iomgr/pollset_multipoller_with_poll_posix.c +10 -5
  62. data/src/core/iomgr/pollset_posix.c +30 -35
  63. data/src/core/iomgr/pollset_posix.h +10 -6
  64. data/src/core/iomgr/pollset_set.h +3 -9
  65. data/src/core/iomgr/pollset_set_posix.c +23 -3
  66. data/src/core/iomgr/pollset_set_posix.h +2 -18
  67. data/src/core/iomgr/pollset_set_windows.c +3 -3
  68. data/src/core/iomgr/pollset_set_windows.h +2 -2
  69. data/src/core/iomgr/pollset_windows.c +24 -21
  70. data/src/core/iomgr/pollset_windows.h +1 -5
  71. data/src/core/iomgr/tcp_client_posix.c +7 -5
  72. data/src/core/iomgr/tcp_posix.c +4 -2
  73. data/src/core/iomgr/tcp_server_windows.c +1 -2
  74. data/src/core/iomgr/timer.c +2 -3
  75. data/src/core/iomgr/timer.h +21 -1
  76. data/src/core/iomgr/timer_heap.c +10 -12
  77. data/src/core/iomgr/udp_server.c +5 -4
  78. data/src/core/iomgr/udp_server.h +1 -0
  79. data/src/core/iomgr/workqueue_posix.c +1 -0
  80. data/src/core/iomgr/workqueue_posix.h +3 -1
  81. data/src/core/proto/grpc/lb/v0/load_balancer.pb.c +119 -0
  82. data/src/core/proto/grpc/lb/v0/load_balancer.pb.h +182 -0
  83. data/src/core/security/{base64.c → b64.c} +1 -1
  84. data/src/core/security/{base64.h → b64.h} +1 -1
  85. data/src/core/security/client_auth_filter.c +0 -1
  86. data/src/core/security/credentials.c +12 -5
  87. data/src/core/security/credentials.h +3 -3
  88. data/src/core/security/google_default_credentials.c +24 -19
  89. data/src/core/security/handshake.c +15 -7
  90. data/src/core/security/handshake.h +2 -1
  91. data/src/core/security/json_token.c +1 -1
  92. data/src/core/security/jwt_verifier.c +1 -1
  93. data/src/core/security/security_connector.c +84 -64
  94. data/src/core/security/security_connector.h +42 -22
  95. data/src/core/security/security_context.c +8 -3
  96. data/src/core/security/server_auth_filter.c +2 -2
  97. data/src/core/security/server_secure_chttp2.c +7 -7
  98. data/src/core/support/avl.c +2 -2
  99. data/src/core/support/env_linux.c +17 -0
  100. data/src/core/support/{file.c → load_file.c} +2 -2
  101. data/src/core/support/{file.h → load_file.h} +4 -12
  102. data/src/core/support/sync.c +6 -1
  103. data/src/core/support/time_posix.c +1 -1
  104. data/src/core/{iomgr/timer_internal.h → support/tmpfile.h} +17 -23
  105. data/src/core/support/{file_posix.c → tmpfile_posix.c} +2 -2
  106. data/src/core/support/{file_win32.c → tmpfile_win32.c} +2 -2
  107. data/src/core/surface/alarm.c +3 -2
  108. data/src/core/surface/call.c +102 -52
  109. data/src/core/surface/channel_create.c +1 -1
  110. data/src/core/surface/completion_queue.c +73 -41
  111. data/src/core/surface/init.c +4 -0
  112. data/src/core/surface/lame_client.c +1 -2
  113. data/src/core/surface/secure_channel_create.c +6 -7
  114. data/src/core/surface/server.c +13 -5
  115. data/src/core/surface/validate_metadata.c +1 -1
  116. data/src/core/surface/version.c +1 -1
  117. data/src/core/transport/chttp2/internal.h +22 -10
  118. data/src/core/transport/chttp2/parsing.c +3 -3
  119. data/src/core/transport/chttp2/stream_lists.c +39 -21
  120. data/src/core/transport/chttp2/writing.c +19 -28
  121. data/src/core/transport/chttp2_transport.c +80 -37
  122. data/src/core/transport/metadata.c +8 -0
  123. data/src/core/transport/static_metadata.c +17 -17
  124. data/src/core/transport/static_metadata.h +3 -3
  125. data/src/core/transport/transport.c +2 -1
  126. data/src/core/transport/transport.h +12 -5
  127. data/src/ruby/ext/grpc/extconf.rb +1 -0
  128. data/src/ruby/ext/grpc/rb_call.c +6 -0
  129. data/src/ruby/ext/grpc/rb_call_credentials.c +12 -14
  130. data/src/ruby/ext/grpc/rb_channel.c +8 -14
  131. data/src/ruby/ext/grpc/rb_channel_credentials.c +11 -12
  132. data/src/ruby/ext/grpc/rb_grpc.c +19 -18
  133. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
  134. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +8 -2
  135. data/src/ruby/lib/grpc/core/time_consts.rb +2 -2
  136. data/src/ruby/lib/grpc/errors.rb +2 -2
  137. data/src/ruby/lib/grpc/generic/rpc_server.rb +58 -39
  138. data/src/ruby/lib/grpc/version.rb +1 -1
  139. data/src/ruby/pb/README.md +2 -2
  140. data/src/ruby/pb/generate_proto_ruby.sh +2 -2
  141. data/src/ruby/pb/grpc/health/checker.rb +11 -11
  142. data/src/ruby/pb/grpc/health/v1/health.rb +28 -0
  143. data/src/ruby/pb/grpc/health/{v1alpha → v1}/health_services.rb +4 -4
  144. data/src/ruby/spec/client_server_spec.rb +2 -1
  145. data/src/ruby/spec/generic/rpc_server_spec.rb +3 -22
  146. data/src/ruby/spec/pb/health/checker_spec.rb +22 -36
  147. data/third_party/nanopb/pb.h +547 -0
  148. data/third_party/nanopb/pb_common.c +97 -0
  149. data/third_party/nanopb/pb_common.h +42 -0
  150. data/third_party/nanopb/pb_decode.c +1319 -0
  151. data/third_party/nanopb/pb_decode.h +149 -0
  152. data/third_party/nanopb/pb_encode.c +690 -0
  153. data/third_party/nanopb/pb_encode.h +154 -0
  154. metadata +32 -16
  155. data/src/ruby/pb/grpc/health/v1alpha/health.rb +0 -29
@@ -0,0 +1,95 @@
1
+ /*
2
+ *
3
+ * Copyright 2015-2016, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ /* A very fast in-memory log, optimized for multiple writers. */
35
+
36
+ #ifndef GRPC_INTERNAL_CORE_CENSUS_MLOG_H
37
+ #define GRPC_INTERNAL_CORE_CENSUS_MLOG_H
38
+
39
+ #include <grpc/support/port_platform.h>
40
+ #include <stddef.h>
41
+
42
+ /* Maximum record size, in bytes. */
43
+ #define CENSUS_LOG_2_MAX_RECORD_SIZE 14 /* 2^14 = 16KB */
44
+ #define CENSUS_LOG_MAX_RECORD_SIZE (1 << CENSUS_LOG_2_MAX_RECORD_SIZE)
45
+
46
+ /* Initialize the statistics logging subsystem with the given log size. A log
47
+ size of 0 will result in the smallest possible log for the platform
48
+ (approximately CENSUS_LOG_MAX_RECORD_SIZE * gpr_cpu_num_cores()). If
49
+ discard_old_records is non-zero, then new records will displace older ones
50
+ when the log is full. This function must be called before any other
51
+ census_log functions.
52
+ */
53
+ void census_log_initialize(size_t size_in_mb, int discard_old_records);
54
+
55
+ /* Shutdown the logging subsystem. Caller must ensure that:
56
+ - no in progress or future call to any census_log functions
57
+ - no incomplete records
58
+ */
59
+ void census_log_shutdown(void);
60
+
61
+ /* Allocates and returns a 'size' bytes record and marks it in use. A
62
+ subsequent census_log_end_write() marks the record complete. The
63
+ 'bytes_written' census_log_end_write() argument must be <=
64
+ 'size'. Returns NULL if out-of-space AND:
65
+ - log is configured to keep old records OR
66
+ - all blocks are pinned by incomplete records.
67
+ */
68
+ void* census_log_start_write(size_t size);
69
+
70
+ void census_log_end_write(void* record, size_t bytes_written);
71
+
72
+ void census_log_init_reader(void);
73
+
74
+ /* census_log_read_next() iterates over blocks with data and for each block
75
+ returns a pointer to the first unread byte. The number of bytes that can be
76
+ read are returned in 'bytes_available'. Reader is expected to read all
77
+ available data. Reading the data consumes it i.e. it cannot be read again.
78
+ census_log_read_next() returns NULL if the end is reached i.e last block
79
+ is read. census_log_init_reader() starts the iteration or aborts the
80
+ current iteration.
81
+ */
82
+ const void* census_log_read_next(size_t* bytes_available);
83
+
84
+ /* Returns estimated remaining space across all blocks, in bytes. If log is
85
+ configured to discard old records, returns total log space. Otherwise,
86
+ returns space available in empty blocks (partially filled blocks are
87
+ treated as full).
88
+ */
89
+ size_t census_log_remaining_space(void);
90
+
91
+ /* Returns the number of times gprc_stats_log_start_write() failed due to
92
+ out-of-space. */
93
+ int64_t census_log_out_of_space_count(void);
94
+
95
+ #endif /* GRPC_INTERNAL_CORE_CENSUS_LOG_H */
@@ -37,6 +37,7 @@
37
37
 
38
38
  #include <grpc/census.h>
39
39
  #include <grpc/support/alloc.h>
40
+ #include <grpc/support/log.h>
40
41
  #include <grpc/support/string_util.h>
41
42
  #include <grpc/support/useful.h>
42
43
 
@@ -55,9 +56,8 @@ static grpc_arg copy_arg(const grpc_arg *src) {
55
56
  break;
56
57
  case GRPC_ARG_POINTER:
57
58
  dst.value.pointer = src->value.pointer;
58
- dst.value.pointer.p = src->value.pointer.copy
59
- ? src->value.pointer.copy(src->value.pointer.p)
60
- : src->value.pointer.p;
59
+ dst.value.pointer.p =
60
+ src->value.pointer.vtable->copy(src->value.pointer.p);
61
61
  break;
62
62
  }
63
63
  return dst;
@@ -94,6 +94,58 @@ grpc_channel_args *grpc_channel_args_merge(const grpc_channel_args *a,
94
94
  return grpc_channel_args_copy_and_add(a, b->args, b->num_args);
95
95
  }
96
96
 
97
+ static int cmp_arg(const grpc_arg *a, const grpc_arg *b) {
98
+ int c = GPR_ICMP(a->type, b->type);
99
+ if (c != 0) return c;
100
+ c = strcmp(a->key, b->key);
101
+ if (c != 0) return c;
102
+ switch (a->type) {
103
+ case GRPC_ARG_STRING:
104
+ return strcmp(a->value.string, b->value.string);
105
+ case GRPC_ARG_INTEGER:
106
+ return GPR_ICMP(a->value.integer, b->value.integer);
107
+ case GRPC_ARG_POINTER:
108
+ c = GPR_ICMP(a->value.pointer.p, b->value.pointer.p);
109
+ if (c != 0) {
110
+ c = GPR_ICMP(a->value.pointer.vtable, b->value.pointer.vtable);
111
+ if (c == 0) {
112
+ c = a->value.pointer.vtable->cmp(a->value.pointer.p,
113
+ b->value.pointer.p);
114
+ }
115
+ }
116
+ return c;
117
+ }
118
+ GPR_UNREACHABLE_CODE(return 0);
119
+ }
120
+
121
+ /* stabilizing comparison function: since channel_args ordering matters for
122
+ * keys with the same name, we need to preserve that ordering */
123
+ static int cmp_key_stable(const void *ap, const void *bp) {
124
+ const grpc_arg *const *a = ap;
125
+ const grpc_arg *const *b = bp;
126
+ int c = strcmp((*a)->key, (*b)->key);
127
+ if (c == 0) c = GPR_ICMP(*a, *b);
128
+ return c;
129
+ }
130
+
131
+ grpc_channel_args *grpc_channel_args_normalize(const grpc_channel_args *a) {
132
+ grpc_arg **args = gpr_malloc(sizeof(grpc_arg *) * a->num_args);
133
+ for (size_t i = 0; i < a->num_args; i++) {
134
+ args[i] = &a->args[i];
135
+ }
136
+ qsort(args, a->num_args, sizeof(grpc_arg *), cmp_key_stable);
137
+
138
+ grpc_channel_args *b = gpr_malloc(sizeof(grpc_channel_args));
139
+ b->num_args = a->num_args;
140
+ b->args = gpr_malloc(sizeof(grpc_arg) * b->num_args);
141
+ for (size_t i = 0; i < a->num_args; i++) {
142
+ b->args[i] = copy_arg(args[i]);
143
+ }
144
+
145
+ gpr_free(args);
146
+ return b;
147
+ }
148
+
97
149
  void grpc_channel_args_destroy(grpc_channel_args *a) {
98
150
  size_t i;
99
151
  for (i = 0; i < a->num_args; i++) {
@@ -104,9 +156,7 @@ void grpc_channel_args_destroy(grpc_channel_args *a) {
104
156
  case GRPC_ARG_INTEGER:
105
157
  break;
106
158
  case GRPC_ARG_POINTER:
107
- if (a->args[i].value.pointer.destroy) {
108
- a->args[i].value.pointer.destroy(a->args[i].value.pointer.p);
109
- }
159
+ a->args[i].value.pointer.vtable->destroy(a->args[i].value.pointer.p);
110
160
  break;
111
161
  }
112
162
  gpr_free(a->args[i].key);
@@ -208,3 +258,14 @@ int grpc_channel_args_compression_algorithm_get_states(
208
258
  return (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; /* All algs. enabled */
209
259
  }
210
260
  }
261
+
262
+ int grpc_channel_args_compare(const grpc_channel_args *a,
263
+ const grpc_channel_args *b) {
264
+ int c = GPR_ICMP(a->num_args, b->num_args);
265
+ if (c != 0) return c;
266
+ for (size_t i = 0; i < a->num_args; i++) {
267
+ c = cmp_arg(&a->args[i], &b->args[i]);
268
+ if (c != 0) return c;
269
+ }
270
+ return 0;
271
+ }
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  *
3
- * Copyright 2015, Google Inc.
3
+ * Copyright 2015-2016, Google Inc.
4
4
  * All rights reserved.
5
5
  *
6
6
  * Redistribution and use in source and binary forms, with or without
@@ -40,6 +40,9 @@
40
40
  /* Copy some arguments */
41
41
  grpc_channel_args *grpc_channel_args_copy(const grpc_channel_args *src);
42
42
 
43
+ /* Copy some arguments, stably sorting keys */
44
+ grpc_channel_args *grpc_channel_args_normalize(const grpc_channel_args *a);
45
+
43
46
  /** Copy some arguments and add the to_add parameter in the end.
44
47
  If to_add is NULL, it is equivalent to call grpc_channel_args_copy. */
45
48
  grpc_channel_args *grpc_channel_args_copy_and_add(const grpc_channel_args *src,
@@ -85,4 +88,7 @@ grpc_channel_args *grpc_channel_args_compression_algorithm_set_state(
85
88
  int grpc_channel_args_compression_algorithm_get_states(
86
89
  const grpc_channel_args *a);
87
90
 
91
+ int grpc_channel_args_compare(const grpc_channel_args *a,
92
+ const grpc_channel_args *b);
93
+
88
94
  #endif /* GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_ARGS_H */
@@ -78,8 +78,8 @@ typedef struct client_channel_channel_data {
78
78
  int exit_idle_when_lb_policy_arrives;
79
79
  /** owning stack */
80
80
  grpc_channel_stack *owning_stack;
81
- /** interested parties */
82
- grpc_pollset_set interested_parties;
81
+ /** interested parties (owned) */
82
+ grpc_pollset_set *interested_parties;
83
83
  } channel_data;
84
84
 
85
85
  /** We create one watcher for each new lb_policy that is returned from a
@@ -165,7 +165,6 @@ static void cc_on_config_changed(grpc_exec_ctx *exec_ctx, void *arg,
165
165
  channel_data *chand = arg;
166
166
  grpc_lb_policy *lb_policy = NULL;
167
167
  grpc_lb_policy *old_lb_policy;
168
- grpc_resolver *old_resolver;
169
168
  grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE;
170
169
  int exit_idle = 0;
171
170
 
@@ -183,8 +182,8 @@ static void cc_on_config_changed(grpc_exec_ctx *exec_ctx, void *arg,
183
182
  chand->incoming_configuration = NULL;
184
183
 
185
184
  if (lb_policy != NULL) {
186
- grpc_pollset_set_add_pollset_set(exec_ctx, &lb_policy->interested_parties,
187
- &chand->interested_parties);
185
+ grpc_pollset_set_add_pollset_set(exec_ctx, lb_policy->interested_parties,
186
+ chand->interested_parties);
188
187
  }
189
188
 
190
189
  gpr_mu_lock(&chand->mu_config);
@@ -201,28 +200,25 @@ static void cc_on_config_changed(grpc_exec_ctx *exec_ctx, void *arg,
201
200
  }
202
201
 
203
202
  if (iomgr_success && chand->resolver) {
204
- grpc_resolver *resolver = chand->resolver;
205
- GRPC_RESOLVER_REF(resolver, "channel-next");
206
203
  grpc_connectivity_state_set(exec_ctx, &chand->state_tracker, state,
207
204
  "new_lb+resolver");
208
205
  if (lb_policy != NULL) {
209
206
  watch_lb_policy(exec_ctx, chand, lb_policy, state);
210
207
  }
211
- gpr_mu_unlock(&chand->mu_config);
212
208
  GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver");
213
- grpc_resolver_next(exec_ctx, resolver, &chand->incoming_configuration,
209
+ grpc_resolver_next(exec_ctx, chand->resolver,
210
+ &chand->incoming_configuration,
214
211
  &chand->on_config_changed);
215
- GRPC_RESOLVER_UNREF(exec_ctx, resolver, "channel-next");
212
+ gpr_mu_unlock(&chand->mu_config);
216
213
  } else {
217
- old_resolver = chand->resolver;
218
- chand->resolver = NULL;
214
+ if (chand->resolver != NULL) {
215
+ grpc_resolver_shutdown(exec_ctx, chand->resolver);
216
+ GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel");
217
+ chand->resolver = NULL;
218
+ }
219
219
  grpc_connectivity_state_set(exec_ctx, &chand->state_tracker,
220
220
  GRPC_CHANNEL_FATAL_FAILURE, "resolver_gone");
221
221
  gpr_mu_unlock(&chand->mu_config);
222
- if (old_resolver != NULL) {
223
- grpc_resolver_shutdown(exec_ctx, old_resolver);
224
- GRPC_RESOLVER_UNREF(exec_ctx, old_resolver, "channel");
225
- }
226
222
  }
227
223
 
228
224
  if (exit_idle) {
@@ -231,9 +227,8 @@ static void cc_on_config_changed(grpc_exec_ctx *exec_ctx, void *arg,
231
227
  }
232
228
 
233
229
  if (old_lb_policy != NULL) {
234
- grpc_pollset_set_del_pollset_set(exec_ctx,
235
- &old_lb_policy->interested_parties,
236
- &chand->interested_parties);
230
+ grpc_pollset_set_del_pollset_set(
231
+ exec_ctx, old_lb_policy->interested_parties, chand->interested_parties);
237
232
  GRPC_LB_POLICY_UNREF(exec_ctx, old_lb_policy, "channel");
238
233
  }
239
234
 
@@ -248,13 +243,12 @@ static void cc_start_transport_op(grpc_exec_ctx *exec_ctx,
248
243
  grpc_channel_element *elem,
249
244
  grpc_transport_op *op) {
250
245
  channel_data *chand = elem->channel_data;
251
- grpc_resolver *destroy_resolver = NULL;
252
246
 
253
247
  grpc_exec_ctx_enqueue(exec_ctx, op->on_consumed, true, NULL);
254
248
 
255
- GPR_ASSERT(op->set_accept_stream == NULL);
249
+ GPR_ASSERT(op->set_accept_stream == false);
256
250
  if (op->bind_pollset != NULL) {
257
- grpc_pollset_set_add_pollset(exec_ctx, &chand->interested_parties,
251
+ grpc_pollset_set_add_pollset(exec_ctx, chand->interested_parties,
258
252
  op->bind_pollset);
259
253
  }
260
254
 
@@ -280,22 +274,18 @@ static void cc_start_transport_op(grpc_exec_ctx *exec_ctx,
280
274
  if (op->disconnect && chand->resolver != NULL) {
281
275
  grpc_connectivity_state_set(exec_ctx, &chand->state_tracker,
282
276
  GRPC_CHANNEL_FATAL_FAILURE, "disconnect");
283
- destroy_resolver = chand->resolver;
277
+ grpc_resolver_shutdown(exec_ctx, chand->resolver);
278
+ GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel");
284
279
  chand->resolver = NULL;
285
280
  if (chand->lb_policy != NULL) {
286
281
  grpc_pollset_set_del_pollset_set(exec_ctx,
287
- &chand->lb_policy->interested_parties,
288
- &chand->interested_parties);
282
+ chand->lb_policy->interested_parties,
283
+ chand->interested_parties);
289
284
  GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel");
290
285
  chand->lb_policy = NULL;
291
286
  }
292
287
  }
293
288
  gpr_mu_unlock(&chand->mu_config);
294
-
295
- if (destroy_resolver) {
296
- grpc_resolver_shutdown(exec_ctx, destroy_resolver);
297
- GRPC_RESOLVER_UNREF(exec_ctx, destroy_resolver, "channel");
298
- }
299
289
  }
300
290
 
301
291
  typedef struct {
@@ -411,7 +401,7 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
411
401
 
412
402
  grpc_connectivity_state_init(&chand->state_tracker, GRPC_CHANNEL_IDLE,
413
403
  "client_channel");
414
- grpc_pollset_set_init(&chand->interested_parties);
404
+ chand->interested_parties = grpc_pollset_set_create();
415
405
  }
416
406
 
417
407
  /* Destructor for channel_data */
@@ -425,12 +415,12 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
425
415
  }
426
416
  if (chand->lb_policy != NULL) {
427
417
  grpc_pollset_set_del_pollset_set(exec_ctx,
428
- &chand->lb_policy->interested_parties,
429
- &chand->interested_parties);
418
+ chand->lb_policy->interested_parties,
419
+ chand->interested_parties);
430
420
  GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel");
431
421
  }
432
422
  grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker);
433
- grpc_pollset_set_destroy(&chand->interested_parties);
423
+ grpc_pollset_set_destroy(chand->interested_parties);
434
424
  gpr_mu_destroy(&chand->mu_config);
435
425
  }
436
426
 
@@ -501,7 +491,7 @@ static void on_external_watch_complete(grpc_exec_ctx *exec_ctx, void *arg,
501
491
  bool iomgr_success) {
502
492
  external_connectivity_watcher *w = arg;
503
493
  grpc_closure *follow_up = w->on_complete;
504
- grpc_pollset_set_del_pollset(exec_ctx, &w->chand->interested_parties,
494
+ grpc_pollset_set_del_pollset(exec_ctx, w->chand->interested_parties,
505
495
  w->pollset);
506
496
  GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack,
507
497
  "external_connectivity_watcher");
@@ -517,7 +507,7 @@ void grpc_client_channel_watch_connectivity_state(
517
507
  w->chand = chand;
518
508
  w->pollset = pollset;
519
509
  w->on_complete = on_complete;
520
- grpc_pollset_set_add_pollset(exec_ctx, &chand->interested_parties, pollset);
510
+ grpc_pollset_set_add_pollset(exec_ctx, chand->interested_parties, pollset);
521
511
  grpc_closure_init(&w->my_closure, on_external_watch_complete, w);
522
512
  GRPC_CHANNEL_STACK_REF(w->chand->owning_stack,
523
513
  "external_connectivity_watcher");
@@ -107,7 +107,7 @@ static void cuc_start_transport_op(grpc_exec_ctx *exec_ctx,
107
107
 
108
108
  grpc_exec_ctx_enqueue(exec_ctx, op->on_consumed, true, NULL);
109
109
 
110
- GPR_ASSERT(op->set_accept_stream == NULL);
110
+ GPR_ASSERT(op->set_accept_stream == false);
111
111
  GPR_ASSERT(op->bind_pollset == NULL);
112
112
 
113
113
  if (op->on_connectivity_state_change != NULL) {
@@ -127,8 +127,8 @@ static void hc_mutate_op(grpc_call_element *elem,
127
127
  if (op->recv_initial_metadata != NULL) {
128
128
  /* substitute our callback for the higher callback */
129
129
  calld->recv_initial_metadata = op->recv_initial_metadata;
130
- calld->on_done_recv = op->on_complete;
131
- op->on_complete = &calld->hc_on_recv;
130
+ calld->on_done_recv = op->recv_initial_metadata_ready;
131
+ op->recv_initial_metadata_ready = &calld->hc_on_recv;
132
132
  }
133
133
  }
134
134
 
@@ -186,8 +186,8 @@ static void hs_mutate_op(grpc_call_element *elem,
186
186
  if (op->recv_initial_metadata) {
187
187
  /* substitute our callback for the higher callback */
188
188
  calld->recv_initial_metadata = op->recv_initial_metadata;
189
- calld->on_done_recv = op->on_complete;
190
- op->on_complete = &calld->hs_on_recv;
189
+ calld->on_done_recv = op->recv_initial_metadata_ready;
190
+ op->recv_initial_metadata_ready = &calld->hs_on_recv;
191
191
  }
192
192
  }
193
193
 
@@ -168,15 +168,15 @@ retry:
168
168
 
169
169
  static void subchannel_ready(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
170
170
  grpc_subchannel_call_holder *holder = arg;
171
- grpc_subchannel_call *call;
172
171
  gpr_mu_lock(&holder->mu);
173
172
  GPR_ASSERT(holder->creation_phase ==
174
173
  GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL);
175
- call = GET_CALL(holder);
176
- GPR_ASSERT(call == NULL || call == CANCELLED_CALL);
177
174
  holder->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING;
178
175
  if (holder->connected_subchannel == NULL) {
179
176
  fail_locked(exec_ctx, holder);
177
+ } else if (1 == gpr_atm_acq_load(&holder->subchannel_call)) {
178
+ /* already cancelled before subchannel became ready */
179
+ fail_locked(exec_ctx, holder);
180
180
  } else {
181
181
  gpr_atm_rel_store(
182
182
  &holder->subchannel_call,
@@ -241,10 +241,8 @@ static void fail_locked(grpc_exec_ctx *exec_ctx,
241
241
  grpc_subchannel_call_holder *holder) {
242
242
  size_t i;
243
243
  for (i = 0; i < holder->waiting_ops_count; i++) {
244
- grpc_exec_ctx_enqueue(exec_ctx, holder->waiting_ops[i].on_complete, false,
245
- NULL);
246
- grpc_exec_ctx_enqueue(exec_ctx, holder->waiting_ops[i].recv_message_ready,
247
- false, NULL);
244
+ grpc_transport_stream_op_finish_with_failure(exec_ctx,
245
+ &holder->waiting_ops[i]);
248
246
  }
249
247
  holder->waiting_ops_count = 0;
250
248
  }