Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 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 | #include "src/core/channel/client_channel.h" |
| 35 | |
| 36 | #include <stdio.h> |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 37 | #include <string.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 38 | |
| 39 | #include "src/core/channel/channel_args.h" |
| 40 | #include "src/core/channel/connected_channel.h" |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 41 | #include "src/core/surface/channel.h" |
ctiller | c6d61c4 | 2014-12-15 14:52:08 -0800 | [diff] [blame] | 42 | #include "src/core/iomgr/iomgr.h" |
Craig Tiller | 485d776 | 2015-01-23 12:54:05 -0800 | [diff] [blame] | 43 | #include "src/core/support/string.h" |
Craig Tiller | 08a1cf8 | 2015-06-29 09:37:52 -0700 | [diff] [blame] | 44 | #include "src/core/transport/connectivity_state.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 45 | #include <grpc/support/alloc.h> |
| 46 | #include <grpc/support/log.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 47 | #include <grpc/support/sync.h> |
| 48 | #include <grpc/support/useful.h> |
| 49 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 50 | /* Client channel implementation */ |
| 51 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 52 | typedef struct call_data call_data; |
| 53 | |
| 54 | typedef struct { |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 55 | /** metadata context for this channel */ |
Craig Tiller | e70413c | 2015-04-24 10:12:34 -0700 | [diff] [blame] | 56 | grpc_mdctx *mdctx; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 57 | /** resolver for this channel */ |
| 58 | grpc_resolver *resolver; |
Craig Tiller | 20a3c35 | 2015-08-05 08:39:50 -0700 | [diff] [blame] | 59 | /** have we started resolving this channel */ |
| 60 | int started_resolving; |
Craig Tiller | 50bc609 | 2015-07-01 14:25:19 -0700 | [diff] [blame] | 61 | /** master channel - the grpc_channel instance that ultimately owns |
| 62 | this channel_data via its channel stack. |
| 63 | We occasionally use this to bump the refcount on the master channel |
| 64 | to keep ourselves alive through an asynchronous operation. */ |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 65 | grpc_channel *master; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 66 | |
Craig Tiller | 9d94b60 | 2015-07-01 14:23:18 -0700 | [diff] [blame] | 67 | /** mutex protecting client configuration, including all |
| 68 | variables below in this data structure */ |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 69 | gpr_mu mu_config; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 70 | /** currently active load balancer - guarded by mu_config */ |
| 71 | grpc_lb_policy *lb_policy; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 72 | /** incoming configuration - set by resolver.next |
| 73 | guarded by mu_config */ |
| 74 | grpc_client_config *incoming_configuration; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 75 | /** a list of closures that are all waiting for config to come in */ |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 76 | grpc_iomgr_call_list waiting_for_config_closures; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 77 | /** resolver callback */ |
| 78 | grpc_iomgr_closure on_config_changed; |
| 79 | /** connectivity state being tracked */ |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 80 | grpc_connectivity_state_tracker state_tracker; |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 81 | /** when an lb_policy arrives, should we try to exit idle */ |
| 82 | int exit_idle_when_lb_policy_arrives; |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 83 | /** pollset_set of interested parties in a new connection */ |
| 84 | grpc_pollset_set pollset_set; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 85 | } channel_data; |
| 86 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 87 | /** We create one watcher for each new lb_policy that is returned from a |
| 88 | resolver, |
| 89 | to watch for state changes from the lb_policy. When a state change is seen, |
| 90 | we |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 91 | update the channel, and create a new watcher */ |
| 92 | typedef struct { |
| 93 | channel_data *chand; |
| 94 | grpc_iomgr_closure on_changed; |
| 95 | grpc_connectivity_state state; |
| 96 | grpc_lb_policy *lb_policy; |
| 97 | } lb_policy_connectivity_watcher; |
| 98 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 99 | typedef enum { |
| 100 | CALL_CREATED, |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 101 | CALL_WAITING_FOR_SEND, |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 102 | CALL_WAITING_FOR_CONFIG, |
| 103 | CALL_WAITING_FOR_PICK, |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 104 | CALL_WAITING_FOR_CALL, |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 105 | CALL_ACTIVE, |
| 106 | CALL_CANCELLED |
| 107 | } call_state; |
| 108 | |
| 109 | struct call_data { |
| 110 | /* owning element */ |
| 111 | grpc_call_element *elem; |
| 112 | |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 113 | gpr_mu mu_state; |
| 114 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 115 | call_state state; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 116 | gpr_timespec deadline; |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 117 | grpc_subchannel *picked_channel; |
| 118 | grpc_iomgr_closure async_setup_task; |
| 119 | grpc_transport_stream_op waiting_op; |
| 120 | /* our child call stack */ |
| 121 | grpc_subchannel_call *subchannel_call; |
| 122 | grpc_linked_mdelem status; |
| 123 | grpc_linked_mdelem details; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 124 | }; |
| 125 | |
Craig Tiller | b367153 | 2015-07-01 10:37:40 -0700 | [diff] [blame] | 126 | static grpc_iomgr_closure *merge_into_waiting_op( |
| 127 | grpc_call_element *elem, |
| 128 | grpc_transport_stream_op *new_op) GRPC_MUST_USE_RESULT; |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 129 | |
Craig Tiller | 1a727fd | 2015-04-24 13:21:22 -0700 | [diff] [blame] | 130 | static void handle_op_after_cancellation(grpc_call_element *elem, |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 131 | grpc_transport_stream_op *op) { |
Craig Tiller | e70413c | 2015-04-24 10:12:34 -0700 | [diff] [blame] | 132 | call_data *calld = elem->call_data; |
| 133 | channel_data *chand = elem->channel_data; |
| 134 | if (op->send_ops) { |
Yang Gao | dbf8fdc | 2015-05-28 00:52:31 -0700 | [diff] [blame] | 135 | grpc_stream_ops_unref_owned_objects(op->send_ops->ops, op->send_ops->nops); |
Craig Tiller | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 136 | op->on_done_send->cb(op->on_done_send->cb_arg, 0); |
Craig Tiller | e70413c | 2015-04-24 10:12:34 -0700 | [diff] [blame] | 137 | } |
| 138 | if (op->recv_ops) { |
| 139 | char status[GPR_LTOA_MIN_BUFSIZE]; |
| 140 | grpc_metadata_batch mdb; |
| 141 | gpr_ltoa(GRPC_STATUS_CANCELLED, status); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 142 | calld->status.md = |
Craig Tiller | 1a727fd | 2015-04-24 13:21:22 -0700 | [diff] [blame] | 143 | grpc_mdelem_from_strings(chand->mdctx, "grpc-status", status); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 144 | calld->details.md = |
Craig Tiller | 1a727fd | 2015-04-24 13:21:22 -0700 | [diff] [blame] | 145 | grpc_mdelem_from_strings(chand->mdctx, "grpc-message", "Cancelled"); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 146 | calld->status.prev = calld->details.next = NULL; |
| 147 | calld->status.next = &calld->details; |
| 148 | calld->details.prev = &calld->status; |
| 149 | mdb.list.head = &calld->status; |
| 150 | mdb.list.tail = &calld->details; |
Craig Tiller | e70413c | 2015-04-24 10:12:34 -0700 | [diff] [blame] | 151 | mdb.garbage.head = mdb.garbage.tail = NULL; |
Craig Tiller | 143e7bf | 2015-07-13 08:41:49 -0700 | [diff] [blame] | 152 | mdb.deadline = gpr_inf_future(GPR_CLOCK_REALTIME); |
Craig Tiller | e70413c | 2015-04-24 10:12:34 -0700 | [diff] [blame] | 153 | grpc_sopb_add_metadata(op->recv_ops, mdb); |
| 154 | *op->recv_state = GRPC_STREAM_CLOSED; |
Craig Tiller | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 155 | op->on_done_recv->cb(op->on_done_recv->cb_arg, 1); |
Craig Tiller | e70413c | 2015-04-24 10:12:34 -0700 | [diff] [blame] | 156 | } |
Craig Tiller | 5dde66e | 2015-06-02 09:05:23 -0700 | [diff] [blame] | 157 | if (op->on_consumed) { |
Craig Tiller | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 158 | op->on_consumed->cb(op->on_consumed->cb_arg, 0); |
Craig Tiller | 5dde66e | 2015-06-02 09:05:23 -0700 | [diff] [blame] | 159 | } |
Craig Tiller | e70413c | 2015-04-24 10:12:34 -0700 | [diff] [blame] | 160 | } |
Craig Tiller | 8b976d0 | 2015-02-05 21:41:23 -0800 | [diff] [blame] | 161 | |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 162 | typedef struct { |
| 163 | grpc_iomgr_closure closure; |
| 164 | grpc_call_element *elem; |
| 165 | } waiting_call; |
| 166 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 167 | static void perform_transport_stream_op(grpc_call_element *elem, |
| 168 | grpc_transport_stream_op *op, |
| 169 | int continuation); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 170 | |
| 171 | static void continue_with_pick(void *arg, int iomgr_success) { |
| 172 | waiting_call *wc = arg; |
| 173 | call_data *calld = wc->elem->call_data; |
| 174 | perform_transport_stream_op(wc->elem, &calld->waiting_op, 1); |
| 175 | gpr_free(wc); |
| 176 | } |
| 177 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 178 | static void add_to_lb_policy_wait_queue_locked_state_config( |
| 179 | grpc_call_element *elem) { |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 180 | channel_data *chand = elem->channel_data; |
| 181 | waiting_call *wc = gpr_malloc(sizeof(*wc)); |
| 182 | grpc_iomgr_closure_init(&wc->closure, continue_with_pick, wc); |
| 183 | wc->elem = elem; |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 184 | grpc_iomgr_call_list_add(&chand->waiting_for_config_closures, &wc->closure, |
| 185 | 1); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static int is_empty(void *p, int len) { |
| 189 | char *ptr = p; |
| 190 | int i; |
| 191 | for (i = 0; i < len; i++) { |
| 192 | if (ptr[i] != 0) return 0; |
| 193 | } |
| 194 | return 1; |
| 195 | } |
| 196 | |
| 197 | static void started_call(void *arg, int iomgr_success) { |
| 198 | call_data *calld = arg; |
| 199 | grpc_transport_stream_op op; |
| 200 | int have_waiting; |
| 201 | |
| 202 | gpr_mu_lock(&calld->mu_state); |
| 203 | if (calld->state == CALL_CANCELLED && calld->subchannel_call != NULL) { |
| 204 | memset(&op, 0, sizeof(op)); |
| 205 | op.cancel_with_status = GRPC_STATUS_CANCELLED; |
| 206 | gpr_mu_unlock(&calld->mu_state); |
| 207 | grpc_subchannel_call_process_op(calld->subchannel_call, &op); |
| 208 | } else if (calld->state == CALL_WAITING_FOR_CALL) { |
| 209 | have_waiting = !is_empty(&calld->waiting_op, sizeof(calld->waiting_op)); |
| 210 | if (calld->subchannel_call != NULL) { |
| 211 | calld->state = CALL_ACTIVE; |
| 212 | gpr_mu_unlock(&calld->mu_state); |
| 213 | if (have_waiting) { |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 214 | grpc_subchannel_call_process_op(calld->subchannel_call, |
| 215 | &calld->waiting_op); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 216 | } |
| 217 | } else { |
| 218 | calld->state = CALL_CANCELLED; |
| 219 | gpr_mu_unlock(&calld->mu_state); |
| 220 | if (have_waiting) { |
| 221 | handle_op_after_cancellation(calld->elem, &calld->waiting_op); |
| 222 | } |
| 223 | } |
| 224 | } else { |
| 225 | GPR_ASSERT(calld->state == CALL_CANCELLED); |
Craig Tiller | 62b1473 | 2015-07-01 11:28:41 -0700 | [diff] [blame] | 226 | gpr_mu_unlock(&calld->mu_state); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | static void picked_target(void *arg, int iomgr_success) { |
| 231 | call_data *calld = arg; |
Craig Tiller | abf3638 | 2015-06-29 16:13:27 -0700 | [diff] [blame] | 232 | grpc_pollset *pollset; |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 233 | grpc_iomgr_call_list call_list = GRPC_IOMGR_CALL_LIST_INIT; |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 234 | |
| 235 | if (calld->picked_channel == NULL) { |
| 236 | /* treat this like a cancellation */ |
| 237 | calld->waiting_op.cancel_with_status = GRPC_STATUS_UNAVAILABLE; |
| 238 | perform_transport_stream_op(calld->elem, &calld->waiting_op, 1); |
| 239 | } else { |
| 240 | gpr_mu_lock(&calld->mu_state); |
| 241 | if (calld->state == CALL_CANCELLED) { |
| 242 | gpr_mu_unlock(&calld->mu_state); |
| 243 | handle_op_after_cancellation(calld->elem, &calld->waiting_op); |
| 244 | } else { |
| 245 | GPR_ASSERT(calld->state == CALL_WAITING_FOR_PICK); |
| 246 | calld->state = CALL_WAITING_FOR_CALL; |
Craig Tiller | abf3638 | 2015-06-29 16:13:27 -0700 | [diff] [blame] | 247 | pollset = calld->waiting_op.bind_pollset; |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 248 | gpr_mu_unlock(&calld->mu_state); |
| 249 | grpc_iomgr_closure_init(&calld->async_setup_task, started_call, calld); |
Craig Tiller | abf3638 | 2015-06-29 16:13:27 -0700 | [diff] [blame] | 250 | grpc_subchannel_create_call(calld->picked_channel, pollset, |
Craig Tiller | 5f84c84 | 2015-06-26 16:08:21 -0700 | [diff] [blame] | 251 | &calld->subchannel_call, |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 252 | &calld->async_setup_task, &call_list); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 253 | } |
| 254 | } |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 255 | grpc_iomgr_call_list_run(call_list); |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Craig Tiller | b367153 | 2015-07-01 10:37:40 -0700 | [diff] [blame] | 258 | static grpc_iomgr_closure *merge_into_waiting_op( |
| 259 | grpc_call_element *elem, grpc_transport_stream_op *new_op) { |
Craig Tiller | bb32ba3 | 2015-06-30 09:31:48 -0700 | [diff] [blame] | 260 | call_data *calld = elem->call_data; |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 261 | grpc_iomgr_closure *consumed_op = NULL; |
Craig Tiller | bb32ba3 | 2015-06-30 09:31:48 -0700 | [diff] [blame] | 262 | grpc_transport_stream_op *waiting_op = &calld->waiting_op; |
Craig Tiller | 2e9dc50 | 2015-07-01 11:31:07 -0700 | [diff] [blame] | 263 | GPR_ASSERT((waiting_op->send_ops != NULL) + (new_op->send_ops != NULL) <= 1); |
| 264 | GPR_ASSERT((waiting_op->recv_ops != NULL) + (new_op->recv_ops != NULL) <= 1); |
Craig Tiller | bb32ba3 | 2015-06-30 09:31:48 -0700 | [diff] [blame] | 265 | if (new_op->send_ops != NULL) { |
| 266 | waiting_op->send_ops = new_op->send_ops; |
| 267 | waiting_op->is_last_send = new_op->is_last_send; |
| 268 | waiting_op->on_done_send = new_op->on_done_send; |
| 269 | } |
| 270 | if (new_op->recv_ops != NULL) { |
| 271 | waiting_op->recv_ops = new_op->recv_ops; |
| 272 | waiting_op->recv_state = new_op->recv_state; |
| 273 | waiting_op->on_done_recv = new_op->on_done_recv; |
| 274 | } |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 275 | if (new_op->on_consumed != NULL) { |
| 276 | if (waiting_op->on_consumed != NULL) { |
| 277 | consumed_op = waiting_op->on_consumed; |
| 278 | } |
Craig Tiller | bb32ba3 | 2015-06-30 09:31:48 -0700 | [diff] [blame] | 279 | waiting_op->on_consumed = new_op->on_consumed; |
Craig Tiller | bb32ba3 | 2015-06-30 09:31:48 -0700 | [diff] [blame] | 280 | } |
| 281 | if (new_op->cancel_with_status != GRPC_STATUS_OK) { |
| 282 | waiting_op->cancel_with_status = new_op->cancel_with_status; |
| 283 | } |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 284 | return consumed_op; |
Craig Tiller | bb32ba3 | 2015-06-30 09:31:48 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 287 | static char *cc_get_peer(grpc_call_element *elem) { |
| 288 | call_data *calld = elem->call_data; |
| 289 | channel_data *chand = elem->channel_data; |
| 290 | grpc_subchannel_call *subchannel_call; |
| 291 | char *result; |
| 292 | |
| 293 | gpr_mu_lock(&calld->mu_state); |
| 294 | if (calld->state == CALL_ACTIVE) { |
| 295 | subchannel_call = calld->subchannel_call; |
| 296 | GRPC_SUBCHANNEL_CALL_REF(subchannel_call, "get_peer"); |
| 297 | gpr_mu_unlock(&calld->mu_state); |
| 298 | result = grpc_subchannel_call_get_peer(subchannel_call); |
| 299 | GRPC_SUBCHANNEL_CALL_UNREF(subchannel_call, "get_peer"); |
| 300 | return result; |
| 301 | } else { |
| 302 | gpr_mu_unlock(&calld->mu_state); |
| 303 | return grpc_channel_get_target(chand->master); |
| 304 | } |
| 305 | } |
| 306 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 307 | static void perform_transport_stream_op(grpc_call_element *elem, |
| 308 | grpc_transport_stream_op *op, |
| 309 | int continuation) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 310 | call_data *calld = elem->call_data; |
| 311 | channel_data *chand = elem->channel_data; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 312 | grpc_subchannel_call *subchannel_call; |
| 313 | grpc_lb_policy *lb_policy; |
Craig Tiller | 49924e0 | 2015-06-29 22:42:33 -0700 | [diff] [blame] | 314 | grpc_transport_stream_op op2; |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 315 | grpc_iomgr_call_list call_list = GRPC_IOMGR_CALL_LIST_INIT; |
Craig Tiller | a940752 | 2015-04-24 10:37:57 -0700 | [diff] [blame] | 316 | GPR_ASSERT(elem->filter == &grpc_client_channel_filter); |
| 317 | GRPC_CALL_LOG_OP(GPR_INFO, elem, op); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 318 | |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 319 | gpr_mu_lock(&calld->mu_state); |
| 320 | switch (calld->state) { |
| 321 | case CALL_ACTIVE: |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 322 | GPR_ASSERT(!continuation); |
| 323 | subchannel_call = calld->subchannel_call; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 324 | gpr_mu_unlock(&calld->mu_state); |
| 325 | grpc_subchannel_call_process_op(subchannel_call, op); |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 326 | break; |
| 327 | case CALL_CANCELLED: |
| 328 | gpr_mu_unlock(&calld->mu_state); |
| 329 | handle_op_after_cancellation(elem, op); |
| 330 | break; |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 331 | case CALL_WAITING_FOR_SEND: |
| 332 | GPR_ASSERT(!continuation); |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 333 | grpc_iomgr_call_list_add(&call_list, merge_into_waiting_op(elem, op), 1); |
Craig Tiller | b367153 | 2015-07-01 10:37:40 -0700 | [diff] [blame] | 334 | if (!calld->waiting_op.send_ops && |
| 335 | calld->waiting_op.cancel_with_status == GRPC_STATUS_OK) { |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 336 | gpr_mu_unlock(&calld->mu_state); |
| 337 | break; |
| 338 | } |
| 339 | *op = calld->waiting_op; |
| 340 | memset(&calld->waiting_op, 0, sizeof(calld->waiting_op)); |
| 341 | continuation = 1; |
Craig Tiller | b367153 | 2015-07-01 10:37:40 -0700 | [diff] [blame] | 342 | /* fall through */ |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 343 | case CALL_WAITING_FOR_CONFIG: |
| 344 | case CALL_WAITING_FOR_PICK: |
| 345 | case CALL_WAITING_FOR_CALL: |
| 346 | if (!continuation) { |
| 347 | if (op->cancel_with_status != GRPC_STATUS_OK) { |
| 348 | calld->state = CALL_CANCELLED; |
Craig Tiller | 49924e0 | 2015-06-29 22:42:33 -0700 | [diff] [blame] | 349 | op2 = calld->waiting_op; |
| 350 | memset(&calld->waiting_op, 0, sizeof(calld->waiting_op)); |
Craig Tiller | bb32ba3 | 2015-06-30 09:31:48 -0700 | [diff] [blame] | 351 | if (op->on_consumed) { |
| 352 | calld->waiting_op.on_consumed = op->on_consumed; |
| 353 | op->on_consumed = NULL; |
| 354 | } else if (op2.on_consumed) { |
| 355 | calld->waiting_op.on_consumed = op2.on_consumed; |
| 356 | op2.on_consumed = NULL; |
| 357 | } |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 358 | gpr_mu_unlock(&calld->mu_state); |
| 359 | handle_op_after_cancellation(elem, op); |
Craig Tiller | 49924e0 | 2015-06-29 22:42:33 -0700 | [diff] [blame] | 360 | handle_op_after_cancellation(elem, &op2); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 361 | } else { |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 362 | grpc_iomgr_call_list_add(&call_list, merge_into_waiting_op(elem, op), |
| 363 | 1); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 364 | gpr_mu_unlock(&calld->mu_state); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 365 | } |
| 366 | break; |
| 367 | } |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 368 | /* fall through */ |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 369 | case CALL_CREATED: |
| 370 | if (op->cancel_with_status != GRPC_STATUS_OK) { |
| 371 | calld->state = CALL_CANCELLED; |
| 372 | gpr_mu_unlock(&calld->mu_state); |
| 373 | handle_op_after_cancellation(elem, op); |
| 374 | } else { |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 375 | calld->waiting_op = *op; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 376 | |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 377 | if (op->send_ops == NULL) { |
| 378 | /* need to have some send ops before we can select the |
| 379 | lb target */ |
| 380 | calld->state = CALL_WAITING_FOR_SEND; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 381 | gpr_mu_unlock(&calld->mu_state); |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 382 | } else { |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 383 | gpr_mu_lock(&chand->mu_config); |
| 384 | lb_policy = chand->lb_policy; |
| 385 | if (lb_policy) { |
Craig Tiller | 990f642 | 2015-07-20 22:07:13 -0700 | [diff] [blame] | 386 | grpc_transport_stream_op *op = &calld->waiting_op; |
| 387 | grpc_pollset *bind_pollset = op->bind_pollset; |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 388 | grpc_metadata_batch *initial_metadata = |
| 389 | &op->send_ops->ops[0].data.metadata; |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 390 | GRPC_LB_POLICY_REF(lb_policy, "pick"); |
| 391 | gpr_mu_unlock(&chand->mu_config); |
| 392 | calld->state = CALL_WAITING_FOR_PICK; |
Craig Tiller | 3d57871 | 2015-07-20 22:00:24 -0700 | [diff] [blame] | 393 | |
Craig Tiller | 990f642 | 2015-07-20 22:07:13 -0700 | [diff] [blame] | 394 | GPR_ASSERT(op->bind_pollset); |
| 395 | GPR_ASSERT(op->send_ops); |
| 396 | GPR_ASSERT(op->send_ops->nops >= 1); |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 397 | GPR_ASSERT(op->send_ops->ops[0].type == GRPC_OP_METADATA); |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 398 | gpr_mu_unlock(&calld->mu_state); |
| 399 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 400 | grpc_iomgr_closure_init(&calld->async_setup_task, picked_target, |
| 401 | calld); |
Craig Tiller | 990f642 | 2015-07-20 22:07:13 -0700 | [diff] [blame] | 402 | grpc_lb_policy_pick(lb_policy, bind_pollset, initial_metadata, |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 403 | &calld->picked_channel, |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 404 | &calld->async_setup_task, &call_list); |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 405 | |
| 406 | GRPC_LB_POLICY_UNREF(lb_policy, "pick"); |
Craig Tiller | b9a46ae | 2015-07-01 09:45:21 -0700 | [diff] [blame] | 407 | } else if (chand->resolver != NULL) { |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 408 | calld->state = CALL_WAITING_FOR_CONFIG; |
| 409 | add_to_lb_policy_wait_queue_locked_state_config(elem); |
Craig Tiller | 20a3c35 | 2015-08-05 08:39:50 -0700 | [diff] [blame] | 410 | if (!chand->started_resolving && chand->resolver != NULL) { |
Craig Tiller | 6659d8b | 2015-08-06 18:02:22 -0700 | [diff] [blame] | 411 | GRPC_CHANNEL_INTERNAL_REF(chand->master, "resolver"); |
Craig Tiller | 20a3c35 | 2015-08-05 08:39:50 -0700 | [diff] [blame] | 412 | chand->started_resolving = 1; |
| 413 | grpc_resolver_next(chand->resolver, |
| 414 | &chand->incoming_configuration, |
| 415 | &chand->on_config_changed); |
| 416 | } |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 417 | gpr_mu_unlock(&chand->mu_config); |
| 418 | gpr_mu_unlock(&calld->mu_state); |
Craig Tiller | b9a46ae | 2015-07-01 09:45:21 -0700 | [diff] [blame] | 419 | } else { |
| 420 | calld->state = CALL_CANCELLED; |
| 421 | gpr_mu_unlock(&chand->mu_config); |
| 422 | gpr_mu_unlock(&calld->mu_state); |
| 423 | handle_op_after_cancellation(elem, op); |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 424 | } |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | break; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 428 | } |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 429 | |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 430 | grpc_iomgr_call_list_run(call_list); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 431 | } |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 432 | |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 433 | static void cc_start_transport_stream_op(grpc_call_element *elem, |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 434 | grpc_transport_stream_op *op) { |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 435 | perform_transport_stream_op(elem, op, 0); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 438 | static void watch_lb_policy(channel_data *chand, grpc_lb_policy *lb_policy, |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 439 | grpc_connectivity_state current_state, |
| 440 | grpc_iomgr_call_list *cl); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 441 | |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 442 | static void on_lb_policy_state_changed_locked(lb_policy_connectivity_watcher *w, |
| 443 | grpc_iomgr_call_list *cl) { |
Craig Tiller | 5795da7 | 2015-09-17 15:27:13 -0700 | [diff] [blame] | 444 | /* check if the notification is for a stale policy */ |
| 445 | if (w->lb_policy != w->chand->lb_policy) return; |
| 446 | |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 447 | grpc_connectivity_state_set(&w->chand->state_tracker, w->state, "lb_changed", |
| 448 | cl); |
Craig Tiller | 5795da7 | 2015-09-17 15:27:13 -0700 | [diff] [blame] | 449 | if (w->state != GRPC_CHANNEL_FATAL_FAILURE) { |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 450 | watch_lb_policy(w->chand, w->lb_policy, w->state, cl); |
Craig Tiller | 5795da7 | 2015-09-17 15:27:13 -0700 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 454 | static void on_lb_policy_state_changed(void *arg, int iomgr_success) { |
| 455 | lb_policy_connectivity_watcher *w = arg; |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 456 | grpc_iomgr_call_list cl = GRPC_IOMGR_CALL_LIST_INIT; |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 457 | |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 458 | gpr_mu_lock(&w->chand->mu_config); |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 459 | on_lb_policy_state_changed_locked(w, &cl); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 460 | gpr_mu_unlock(&w->chand->mu_config); |
| 461 | |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 462 | grpc_iomgr_call_list_run(cl); |
Craig Tiller | 5795da7 | 2015-09-17 15:27:13 -0700 | [diff] [blame] | 463 | |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 464 | GRPC_CHANNEL_INTERNAL_UNREF(w->chand->master, "watch_lb_policy"); |
| 465 | gpr_free(w); |
| 466 | } |
| 467 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 468 | static void watch_lb_policy(channel_data *chand, grpc_lb_policy *lb_policy, |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 469 | grpc_connectivity_state current_state, |
| 470 | grpc_iomgr_call_list *call_list) { |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 471 | lb_policy_connectivity_watcher *w = gpr_malloc(sizeof(*w)); |
| 472 | GRPC_CHANNEL_INTERNAL_REF(chand->master, "watch_lb_policy"); |
| 473 | |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 474 | w->chand = chand; |
| 475 | grpc_iomgr_closure_init(&w->on_changed, on_lb_policy_state_changed, w); |
| 476 | w->state = current_state; |
| 477 | w->lb_policy = lb_policy; |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 478 | grpc_lb_policy_notify_on_state_change(lb_policy, &w->state, &w->on_changed, |
| 479 | call_list); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 482 | static void cc_on_config_changed(void *arg, int iomgr_success) { |
| 483 | channel_data *chand = arg; |
| 484 | grpc_lb_policy *lb_policy = NULL; |
| 485 | grpc_lb_policy *old_lb_policy; |
| 486 | grpc_resolver *old_resolver; |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 487 | grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 488 | grpc_iomgr_call_list cl = GRPC_IOMGR_CALL_LIST_INIT; |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 489 | int exit_idle = 0; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 490 | |
Craig Tiller | d7b68e7 | 2015-06-28 11:41:09 -0700 | [diff] [blame] | 491 | if (chand->incoming_configuration != NULL) { |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 492 | lb_policy = grpc_client_config_get_lb_policy(chand->incoming_configuration); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 493 | if (lb_policy != NULL) { |
| 494 | GRPC_LB_POLICY_REF(lb_policy, "channel"); |
| 495 | GRPC_LB_POLICY_REF(lb_policy, "config_change"); |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 496 | state = grpc_lb_policy_check_connectivity(lb_policy, &cl); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 497 | } |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 498 | |
| 499 | grpc_client_config_unref(chand->incoming_configuration); |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 502 | chand->incoming_configuration = NULL; |
| 503 | |
| 504 | gpr_mu_lock(&chand->mu_config); |
| 505 | old_lb_policy = chand->lb_policy; |
| 506 | chand->lb_policy = lb_policy; |
Craig Tiller | b9a46ae | 2015-07-01 09:45:21 -0700 | [diff] [blame] | 507 | if (lb_policy != NULL || chand->resolver == NULL /* disconnected */) { |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 508 | grpc_iomgr_call_list_move(&chand->waiting_for_config_closures, &cl); |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 509 | } |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 510 | if (lb_policy != NULL && chand->exit_idle_when_lb_policy_arrives) { |
| 511 | GRPC_LB_POLICY_REF(lb_policy, "exit_idle"); |
| 512 | exit_idle = 1; |
| 513 | chand->exit_idle_when_lb_policy_arrives = 0; |
| 514 | } |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 515 | |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 516 | if (iomgr_success && chand->resolver) { |
| 517 | grpc_resolver *resolver = chand->resolver; |
| 518 | GRPC_RESOLVER_REF(resolver, "channel-next"); |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 519 | grpc_connectivity_state_set(&chand->state_tracker, state, "new_lb+resolver", |
| 520 | &cl); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 521 | if (lb_policy != NULL) { |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 522 | watch_lb_policy(chand, lb_policy, state, &cl); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 523 | } |
Craig Tiller | 5795da7 | 2015-09-17 15:27:13 -0700 | [diff] [blame] | 524 | gpr_mu_unlock(&chand->mu_config); |
| 525 | GRPC_CHANNEL_INTERNAL_REF(chand->master, "resolver"); |
Craig Tiller | 5795da7 | 2015-09-17 15:27:13 -0700 | [diff] [blame] | 526 | grpc_resolver_next(resolver, &chand->incoming_configuration, |
| 527 | &chand->on_config_changed); |
| 528 | GRPC_RESOLVER_UNREF(resolver, "channel-next"); |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 529 | } else { |
| 530 | old_resolver = chand->resolver; |
| 531 | chand->resolver = NULL; |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 532 | grpc_connectivity_state_set(&chand->state_tracker, |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 533 | GRPC_CHANNEL_FATAL_FAILURE, "resolver_gone", |
| 534 | &cl); |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 535 | gpr_mu_unlock(&chand->mu_config); |
| 536 | if (old_resolver != NULL) { |
| 537 | grpc_resolver_shutdown(old_resolver); |
| 538 | GRPC_RESOLVER_UNREF(old_resolver, "channel"); |
| 539 | } |
| 540 | } |
| 541 | |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 542 | if (exit_idle) { |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 543 | grpc_lb_policy_exit_idle(lb_policy, &cl); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 544 | GRPC_LB_POLICY_UNREF(lb_policy, "exit_idle"); |
| 545 | } |
| 546 | |
| 547 | if (old_lb_policy != NULL) { |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 548 | grpc_lb_policy_shutdown(old_lb_policy, &cl); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 549 | GRPC_LB_POLICY_UNREF(old_lb_policy, "channel"); |
| 550 | } |
| 551 | |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 552 | if (lb_policy != NULL) { |
| 553 | GRPC_LB_POLICY_UNREF(lb_policy, "config_change"); |
| 554 | } |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 555 | |
| 556 | grpc_iomgr_call_list_run(cl); |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 557 | GRPC_CHANNEL_INTERNAL_UNREF(chand->master, "resolver"); |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 560 | static void cc_start_transport_op(grpc_channel_element *elem, |
| 561 | grpc_transport_op *op) { |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 562 | grpc_lb_policy *lb_policy = NULL; |
| 563 | channel_data *chand = elem->channel_data; |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 564 | grpc_resolver *destroy_resolver = NULL; |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 565 | grpc_iomgr_call_list call_list = GRPC_IOMGR_CALL_LIST_INIT; |
| 566 | |
| 567 | if (op->on_consumed) { |
| 568 | grpc_iomgr_call_list_add(&call_list, op->on_consumed, 1); |
| 569 | op->on_consumed = NULL; |
| 570 | } |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 571 | |
| 572 | GPR_ASSERT(op->set_accept_stream == NULL); |
| 573 | GPR_ASSERT(op->bind_pollset == NULL); |
| 574 | |
| 575 | gpr_mu_lock(&chand->mu_config); |
| 576 | if (op->on_connectivity_state_change != NULL) { |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 577 | grpc_connectivity_state_notify_on_state_change( |
| 578 | &chand->state_tracker, op->connectivity_state, |
| 579 | op->on_connectivity_state_change, &call_list); |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 580 | op->on_connectivity_state_change = NULL; |
| 581 | op->connectivity_state = NULL; |
| 582 | } |
| 583 | |
Craig Tiller | 03dc655 | 2015-07-17 23:12:34 -0700 | [diff] [blame] | 584 | if (!is_empty(op, sizeof(*op))) { |
| 585 | lb_policy = chand->lb_policy; |
| 586 | if (lb_policy) { |
| 587 | GRPC_LB_POLICY_REF(lb_policy, "broadcast"); |
| 588 | } |
| 589 | } |
| 590 | |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 591 | if (op->disconnect && chand->resolver != NULL) { |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 592 | grpc_connectivity_state_set(&chand->state_tracker, |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 593 | GRPC_CHANNEL_FATAL_FAILURE, "disconnect", |
| 594 | &call_list); |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 595 | destroy_resolver = chand->resolver; |
| 596 | chand->resolver = NULL; |
Craig Tiller | d2cc459 | 2015-07-01 07:50:47 -0700 | [diff] [blame] | 597 | if (chand->lb_policy != NULL) { |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 598 | grpc_lb_policy_shutdown(chand->lb_policy, &call_list); |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 599 | GRPC_LB_POLICY_UNREF(chand->lb_policy, "channel"); |
| 600 | chand->lb_policy = NULL; |
Craig Tiller | d2cc459 | 2015-07-01 07:50:47 -0700 | [diff] [blame] | 601 | } |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 602 | } |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 603 | gpr_mu_unlock(&chand->mu_config); |
| 604 | |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 605 | if (destroy_resolver) { |
| 606 | grpc_resolver_shutdown(destroy_resolver); |
| 607 | GRPC_RESOLVER_UNREF(destroy_resolver, "channel"); |
| 608 | } |
| 609 | |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 610 | if (lb_policy) { |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 611 | grpc_lb_policy_broadcast(lb_policy, op, &call_list); |
Craig Tiller | d7b68e7 | 2015-06-28 11:41:09 -0700 | [diff] [blame] | 612 | GRPC_LB_POLICY_UNREF(lb_policy, "broadcast"); |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 615 | grpc_iomgr_call_list_run(call_list); |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 616 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 617 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 618 | /* Constructor for call_data */ |
| 619 | static void init_call_elem(grpc_call_element *elem, |
Craig Tiller | 06aeea7 | 2015-04-23 10:54:45 -0700 | [diff] [blame] | 620 | const void *server_transport_data, |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 621 | grpc_transport_stream_op *initial_op) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 622 | call_data *calld = elem->call_data; |
| 623 | |
Craig Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 624 | /* TODO(ctiller): is there something useful we can do here? */ |
| 625 | GPR_ASSERT(initial_op == NULL); |
| 626 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 627 | GPR_ASSERT(elem->filter == &grpc_client_channel_filter); |
| 628 | GPR_ASSERT(server_transport_data == NULL); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 629 | gpr_mu_init(&calld->mu_state); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 630 | calld->elem = elem; |
| 631 | calld->state = CALL_CREATED; |
Craig Tiller | 143e7bf | 2015-07-13 08:41:49 -0700 | [diff] [blame] | 632 | calld->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /* Destructor for call_data */ |
| 636 | static void destroy_call_elem(grpc_call_element *elem) { |
| 637 | call_data *calld = elem->call_data; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 638 | grpc_subchannel_call *subchannel_call; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 639 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 640 | /* if the call got activated, we need to destroy the child stack also, and |
| 641 | remove it from the in-flight requests tracked by the child_entry we |
| 642 | picked */ |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 643 | gpr_mu_lock(&calld->mu_state); |
Craig Tiller | f93fd05 | 2015-06-02 08:15:33 -0700 | [diff] [blame] | 644 | switch (calld->state) { |
| 645 | case CALL_ACTIVE: |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 646 | subchannel_call = calld->subchannel_call; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 647 | gpr_mu_unlock(&calld->mu_state); |
Craig Tiller | c396753 | 2015-06-29 14:59:38 -0700 | [diff] [blame] | 648 | GRPC_SUBCHANNEL_CALL_UNREF(subchannel_call, "client_channel"); |
Craig Tiller | f93fd05 | 2015-06-02 08:15:33 -0700 | [diff] [blame] | 649 | break; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 650 | case CALL_CREATED: |
| 651 | case CALL_CANCELLED: |
| 652 | gpr_mu_unlock(&calld->mu_state); |
Craig Tiller | f93fd05 | 2015-06-02 08:15:33 -0700 | [diff] [blame] | 653 | break; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 654 | case CALL_WAITING_FOR_PICK: |
| 655 | case CALL_WAITING_FOR_CONFIG: |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 656 | case CALL_WAITING_FOR_CALL: |
Craig Tiller | 5d44c06 | 2015-07-01 08:55:28 -0700 | [diff] [blame] | 657 | case CALL_WAITING_FOR_SEND: |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 658 | gpr_log(GPR_ERROR, "should never reach here"); |
| 659 | abort(); |
Craig Tiller | f93fd05 | 2015-06-02 08:15:33 -0700 | [diff] [blame] | 660 | break; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | |
| 664 | /* Constructor for channel_data */ |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 665 | static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master, |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 666 | const grpc_channel_args *args, |
| 667 | grpc_mdctx *metadata_context, int is_first, |
| 668 | int is_last) { |
| 669 | channel_data *chand = elem->channel_data; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 670 | |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 671 | memset(chand, 0, sizeof(*chand)); |
| 672 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 673 | GPR_ASSERT(is_last); |
| 674 | GPR_ASSERT(elem->filter == &grpc_client_channel_filter); |
| 675 | |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 676 | gpr_mu_init(&chand->mu_config); |
Craig Tiller | e70413c | 2015-04-24 10:12:34 -0700 | [diff] [blame] | 677 | chand->mdctx = metadata_context; |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 678 | chand->master = master; |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 679 | grpc_pollset_set_init(&chand->pollset_set); |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 680 | grpc_iomgr_closure_init(&chand->on_config_changed, cc_on_config_changed, |
| 681 | chand); |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 682 | |
Craig Tiller | 47a708e | 2015-09-15 16:16:06 -0700 | [diff] [blame] | 683 | grpc_connectivity_state_init(&chand->state_tracker, |
Craig Tiller | 47a708e | 2015-09-15 16:16:06 -0700 | [diff] [blame] | 684 | GRPC_CHANNEL_IDLE, "client_channel"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | /* Destructor for channel_data */ |
| 688 | static void destroy_channel_elem(grpc_channel_element *elem) { |
| 689 | channel_data *chand = elem->channel_data; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 690 | |
Craig Tiller | d7b68e7 | 2015-06-28 11:41:09 -0700 | [diff] [blame] | 691 | if (chand->resolver != NULL) { |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 692 | grpc_resolver_shutdown(chand->resolver); |
| 693 | GRPC_RESOLVER_UNREF(chand->resolver, "channel"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 694 | } |
Craig Tiller | d7b68e7 | 2015-06-28 11:41:09 -0700 | [diff] [blame] | 695 | if (chand->lb_policy != NULL) { |
| 696 | GRPC_LB_POLICY_UNREF(chand->lb_policy, "channel"); |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 697 | } |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 698 | grpc_connectivity_state_destroy(&chand->state_tracker); |
| 699 | grpc_pollset_set_destroy(&chand->pollset_set); |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 700 | gpr_mu_destroy(&chand->mu_config); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | const grpc_channel_filter grpc_client_channel_filter = { |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 704 | cc_start_transport_stream_op, |
| 705 | cc_start_transport_op, |
| 706 | sizeof(call_data), |
| 707 | init_call_elem, |
| 708 | destroy_call_elem, |
| 709 | sizeof(channel_data), |
| 710 | init_channel_elem, |
| 711 | destroy_channel_elem, |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 712 | cc_get_peer, |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 713 | "client-channel", |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 714 | }; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 715 | |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 716 | void grpc_client_channel_set_resolver(grpc_channel_stack *channel_stack, |
| 717 | grpc_resolver *resolver) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 718 | /* post construction initialization: set the transport setup pointer */ |
| 719 | grpc_channel_element *elem = grpc_channel_stack_last_element(channel_stack); |
| 720 | channel_data *chand = elem->channel_data; |
Craig Tiller | 20a3c35 | 2015-08-05 08:39:50 -0700 | [diff] [blame] | 721 | gpr_mu_lock(&chand->mu_config); |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 722 | GPR_ASSERT(!chand->resolver); |
| 723 | chand->resolver = resolver; |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 724 | GRPC_RESOLVER_REF(resolver, "channel"); |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 725 | if (!grpc_iomgr_call_list_empty(chand->waiting_for_config_closures) || |
Craig Tiller | 20a3c35 | 2015-08-05 08:39:50 -0700 | [diff] [blame] | 726 | chand->exit_idle_when_lb_policy_arrives) { |
| 727 | chand->started_resolving = 1; |
Craig Tiller | 6659d8b | 2015-08-06 18:02:22 -0700 | [diff] [blame] | 728 | GRPC_CHANNEL_INTERNAL_REF(chand->master, "resolver"); |
Craig Tiller | 20a3c35 | 2015-08-05 08:39:50 -0700 | [diff] [blame] | 729 | grpc_resolver_next(resolver, &chand->incoming_configuration, |
| 730 | &chand->on_config_changed); |
| 731 | } |
| 732 | gpr_mu_unlock(&chand->mu_config); |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 733 | } |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 734 | |
| 735 | grpc_connectivity_state grpc_client_channel_check_connectivity_state( |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 736 | grpc_channel_element *elem, int try_to_connect, |
| 737 | grpc_iomgr_call_list *call_list) { |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 738 | channel_data *chand = elem->channel_data; |
| 739 | grpc_connectivity_state out; |
| 740 | gpr_mu_lock(&chand->mu_config); |
| 741 | out = grpc_connectivity_state_check(&chand->state_tracker); |
| 742 | if (out == GRPC_CHANNEL_IDLE && try_to_connect) { |
| 743 | if (chand->lb_policy != NULL) { |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 744 | grpc_lb_policy_exit_idle(chand->lb_policy, call_list); |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 745 | } else { |
| 746 | chand->exit_idle_when_lb_policy_arrives = 1; |
Craig Tiller | 20a3c35 | 2015-08-05 08:39:50 -0700 | [diff] [blame] | 747 | if (!chand->started_resolving && chand->resolver != NULL) { |
Craig Tiller | 6659d8b | 2015-08-06 18:02:22 -0700 | [diff] [blame] | 748 | GRPC_CHANNEL_INTERNAL_REF(chand->master, "resolver"); |
Craig Tiller | 20a3c35 | 2015-08-05 08:39:50 -0700 | [diff] [blame] | 749 | chand->started_resolving = 1; |
| 750 | grpc_resolver_next(chand->resolver, &chand->incoming_configuration, |
| 751 | &chand->on_config_changed); |
| 752 | } |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | gpr_mu_unlock(&chand->mu_config); |
| 756 | return out; |
| 757 | } |
| 758 | |
| 759 | void grpc_client_channel_watch_connectivity_state( |
| 760 | grpc_channel_element *elem, grpc_connectivity_state *state, |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 761 | grpc_iomgr_closure *on_complete, grpc_iomgr_call_list *call_list) { |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 762 | channel_data *chand = elem->channel_data; |
| 763 | gpr_mu_lock(&chand->mu_config); |
Craig Tiller | 000cd8f | 2015-09-18 07:20:29 -0700 | [diff] [blame^] | 764 | grpc_connectivity_state_notify_on_state_change(&chand->state_tracker, state, |
| 765 | on_complete, call_list); |
Craig Tiller | 48cb07c | 2015-07-15 16:16:15 -0700 | [diff] [blame] | 766 | gpr_mu_unlock(&chand->mu_config); |
| 767 | } |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 768 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 769 | grpc_pollset_set *grpc_client_channel_get_connecting_pollset_set( |
| 770 | grpc_channel_element *elem) { |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 771 | channel_data *chand = elem->channel_data; |
| 772 | return &chand->pollset_set; |
| 773 | } |
| 774 | |
| 775 | void grpc_client_channel_add_interested_party(grpc_channel_element *elem, |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 776 | grpc_pollset *pollset) { |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 777 | channel_data *chand = elem->channel_data; |
| 778 | grpc_pollset_set_add_pollset(&chand->pollset_set, pollset); |
| 779 | } |
| 780 | |
| 781 | void grpc_client_channel_del_interested_party(grpc_channel_element *elem, |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 782 | grpc_pollset *pollset) { |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 783 | channel_data *chand = elem->channel_data; |
| 784 | grpc_pollset_set_del_pollset(&chand->pollset_set, pollset); |
| 785 | } |