Craig Tiller | af69180 | 2015-06-23 14:57:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
Craig Tiller | af69180 | 2015-06-23 14:57:07 -0700 | [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, |
Craig Tiller | 892f2d3 | 2015-11-08 13:53:04 +0000 | [diff] [blame] | 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
Craig Tiller | af69180 | 2015-06-23 14:57:07 -0700 | [diff] [blame] | 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/client_config/subchannel.h" |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 35 | |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 36 | #include <string.h> |
| 37 | |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 38 | #include <grpc/support/alloc.h> |
Craig Tiller | 694cf8b | 2016-01-15 21:13:25 -0800 | [diff] [blame] | 39 | #include <grpc/support/avl.h> |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 40 | |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 41 | #include "src/core/channel/channel_args.h" |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 42 | #include "src/core/channel/client_channel.h" |
Craig Tiller | ff54c92 | 2015-06-26 16:57:20 -0700 | [diff] [blame] | 43 | #include "src/core/channel/connected_channel.h" |
yang-g | a612412 | 2015-11-05 22:36:20 -0800 | [diff] [blame] | 44 | #include "src/core/client_config/initial_connect_string.h" |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 45 | #include "src/core/client_config/subchannel_index.h" |
David Garcia Quintas | f747bbc | 2015-10-04 23:09:47 -0700 | [diff] [blame] | 46 | #include "src/core/iomgr/timer.h" |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 47 | #include "src/core/profiling/timers.h" |
Craig Tiller | 536fc53 | 2016-03-11 12:36:56 -0800 | [diff] [blame] | 48 | #include "src/core/support/backoff.h" |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 49 | #include "src/core/surface/channel.h" |
Craig Tiller | 121e7a9 | 2016-03-16 07:50:18 -0700 | [diff] [blame] | 50 | #include "src/core/surface/channel_init.h" |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 51 | #include "src/core/transport/connectivity_state.h" |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 52 | |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 53 | #define INTERNAL_REF_BITS 16 |
| 54 | #define STRONG_REF_MASK (~(gpr_atm)((1 << INTERNAL_REF_BITS) - 1)) |
| 55 | |
yang-g | b4e262c | 2015-07-21 16:11:55 -0700 | [diff] [blame] | 56 | #define GRPC_SUBCHANNEL_MIN_CONNECT_TIMEOUT_SECONDS 20 |
| 57 | #define GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS 1 |
| 58 | #define GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER 1.6 |
| 59 | #define GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS 120 |
| 60 | #define GRPC_SUBCHANNEL_RECONNECT_JITTER 0.2 |
| 61 | |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 62 | #define GET_CONNECTED_SUBCHANNEL(subchannel, barrier) \ |
| 63 | ((grpc_connected_subchannel *)(gpr_atm_##barrier##_load( \ |
| 64 | &(subchannel)->connected_subchannel))) |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 65 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 66 | typedef struct { |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 67 | grpc_closure closure; |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 68 | grpc_subchannel *subchannel; |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 69 | grpc_connectivity_state connectivity_state; |
| 70 | } state_watcher; |
| 71 | |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 72 | typedef struct external_state_watcher { |
| 73 | grpc_subchannel *subchannel; |
| 74 | grpc_pollset_set *pollset_set; |
| 75 | grpc_closure *notify; |
| 76 | grpc_closure closure; |
| 77 | struct external_state_watcher *next; |
| 78 | struct external_state_watcher *prev; |
| 79 | } external_state_watcher; |
| 80 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 81 | struct grpc_subchannel { |
Craig Tiller | 9162466 | 2015-06-25 16:31:02 -0700 | [diff] [blame] | 82 | grpc_connector *connector; |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 83 | |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 84 | /** refcount |
| 85 | - lower INTERNAL_REF_BITS bits are for internal references: |
| 86 | these do not keep the subchannel open. |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 87 | - upper remaining bits are for public references: these do |
| 88 | keep the subchannel open */ |
| 89 | gpr_atm ref_pair; |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 90 | |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 91 | /** non-transport related channel filters */ |
| 92 | const grpc_channel_filter **filters; |
Craig Tiller | 5945ee1 | 2015-06-27 10:36:09 -0700 | [diff] [blame] | 93 | size_t num_filters; |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 94 | /** channel arguments */ |
| 95 | grpc_channel_args *args; |
| 96 | /** address to connect to */ |
| 97 | struct sockaddr *addr; |
| 98 | size_t addr_len; |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 99 | |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 100 | grpc_subchannel_key *key; |
| 101 | |
yang-g | a612412 | 2015-11-05 22:36:20 -0800 | [diff] [blame] | 102 | /** initial string to send to peer */ |
| 103 | gpr_slice initial_connect_string; |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 104 | |
| 105 | /** set during connection */ |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 106 | grpc_connect_out_args connecting_result; |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 107 | |
| 108 | /** callback for connection finishing */ |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 109 | grpc_closure connected; |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 110 | |
Craig Tiller | 5f84c84 | 2015-06-26 16:08:21 -0700 | [diff] [blame] | 111 | /** pollset_set tracking who's interested in a connection |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 112 | being setup */ |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 113 | grpc_pollset_set *pollset_set; |
Craig Tiller | 5f84c84 | 2015-06-26 16:08:21 -0700 | [diff] [blame] | 114 | |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 115 | /** active connection, or null; of type grpc_connected_subchannel */ |
| 116 | gpr_atm connected_subchannel; |
| 117 | |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 118 | /** mutex protecting remaining elements */ |
| 119 | gpr_mu mu; |
| 120 | |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 121 | /** have we seen a disconnection? */ |
| 122 | int disconnected; |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 123 | /** are we connecting */ |
| 124 | int connecting; |
Craig Tiller | c7b5f76 | 2015-06-27 11:48:42 -0700 | [diff] [blame] | 125 | /** connectivity state tracking */ |
| 126 | grpc_connectivity_state_tracker state_tracker; |
Craig Tiller | ff3ae68 | 2015-06-29 17:44:04 -0700 | [diff] [blame] | 127 | |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 128 | external_state_watcher root_external_state_watcher; |
| 129 | |
Craig Tiller | ff3ae68 | 2015-06-29 17:44:04 -0700 | [diff] [blame] | 130 | /** next connect attempt time */ |
| 131 | gpr_timespec next_attempt; |
Craig Tiller | 536fc53 | 2016-03-11 12:36:56 -0800 | [diff] [blame] | 132 | /** backoff state */ |
| 133 | gpr_backoff backoff_state; |
Craig Tiller | ff3ae68 | 2015-06-29 17:44:04 -0700 | [diff] [blame] | 134 | /** do we have an active alarm? */ |
| 135 | int have_alarm; |
| 136 | /** our alarm */ |
David Garcia Quintas | f747bbc | 2015-10-04 23:09:47 -0700 | [diff] [blame] | 137 | grpc_timer alarm; |
yang-g | b4e262c | 2015-07-21 16:11:55 -0700 | [diff] [blame] | 138 | /** current random value */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 139 | uint32_t random; |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 142 | struct grpc_subchannel_call { |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 143 | grpc_connected_subchannel *connection; |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 146 | #define SUBCHANNEL_CALL_TO_CALL_STACK(call) ((grpc_call_stack *)((call) + 1)) |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 147 | #define CHANNEL_STACK_FROM_CONNECTION(con) ((grpc_channel_stack *)(con)) |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 148 | #define CALLSTACK_TO_SUBCHANNEL_CALL(callstack) \ |
| 149 | (((grpc_subchannel_call *)(callstack)) - 1) |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 150 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 151 | static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *subchannel, |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 152 | bool iomgr_success); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 153 | |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 154 | #ifdef GRPC_STREAM_REFCOUNT_DEBUG |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 155 | #define REF_REASON reason |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 156 | #define REF_LOG(name, p) \ |
| 157 | gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "%s: %p ref %d -> %d %s", \ |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 158 | (name), (p), (p)->refs.count, (p)->refs.count + 1, reason) |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 159 | #define UNREF_LOG(name, p) \ |
| 160 | gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "%s: %p unref %d -> %d %s", \ |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 161 | (name), (p), (p)->refs.count, (p)->refs.count - 1, reason) |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 162 | #define REF_MUTATE_EXTRA_ARGS \ |
| 163 | GRPC_SUBCHANNEL_REF_EXTRA_ARGS, const char *purpose |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 164 | #define REF_MUTATE_PURPOSE(x) , file, line, reason, x |
Craig Tiller | c396753 | 2015-06-29 14:59:38 -0700 | [diff] [blame] | 165 | #else |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 166 | #define REF_REASON "" |
Craig Tiller | 11bf14e | 2015-06-29 16:35:41 -0700 | [diff] [blame] | 167 | #define REF_LOG(name, p) \ |
| 168 | do { \ |
| 169 | } while (0) |
| 170 | #define UNREF_LOG(name, p) \ |
| 171 | do { \ |
| 172 | } while (0) |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 173 | #define REF_MUTATE_EXTRA_ARGS |
| 174 | #define REF_MUTATE_PURPOSE(x) |
Craig Tiller | c396753 | 2015-06-29 14:59:38 -0700 | [diff] [blame] | 175 | #endif |
| 176 | |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 177 | /* |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 178 | * connection implementation |
| 179 | */ |
| 180 | |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 181 | static void connection_destroy(grpc_exec_ctx *exec_ctx, void *arg, |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 182 | bool success) { |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 183 | grpc_connected_subchannel *c = arg; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 184 | grpc_channel_stack_destroy(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c)); |
| 185 | gpr_free(c); |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 188 | void grpc_connected_subchannel_ref( |
| 189 | grpc_connected_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 190 | GRPC_CHANNEL_STACK_REF(CHANNEL_STACK_FROM_CONNECTION(c), REF_REASON); |
Craig Tiller | d7b68e7 | 2015-06-28 11:41:09 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 193 | void grpc_connected_subchannel_unref(grpc_exec_ctx *exec_ctx, |
| 194 | grpc_connected_subchannel *c |
| 195 | GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { |
Craig Tiller | 7b43561 | 2015-11-24 08:15:05 -0800 | [diff] [blame] | 196 | GRPC_CHANNEL_STACK_UNREF(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c), |
| 197 | REF_REASON); |
Craig Tiller | ca3e9d3 | 2015-06-27 18:37:27 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 201 | * grpc_subchannel implementation |
| 202 | */ |
| 203 | |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 204 | static void subchannel_destroy(grpc_exec_ctx *exec_ctx, void *arg, |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 205 | bool success) { |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 206 | grpc_subchannel *c = arg; |
Craig Tiller | 565b18b | 2015-09-23 10:09:42 -0700 | [diff] [blame] | 207 | gpr_free((void *)c->filters); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 208 | grpc_channel_args_destroy(c->args); |
| 209 | gpr_free(c->addr); |
yang-g | a612412 | 2015-11-05 22:36:20 -0800 | [diff] [blame] | 210 | gpr_slice_unref(c->initial_connect_string); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 211 | grpc_connectivity_state_destroy(exec_ctx, &c->state_tracker); |
| 212 | grpc_connector_unref(exec_ctx, c->connector); |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 213 | grpc_pollset_set_destroy(c->pollset_set); |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 214 | grpc_subchannel_key_destroy(exec_ctx, c->key); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 215 | gpr_free(c); |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 218 | static gpr_atm ref_mutate(grpc_subchannel *c, gpr_atm delta, |
| 219 | int barrier REF_MUTATE_EXTRA_ARGS) { |
| 220 | gpr_atm old_val = barrier ? gpr_atm_full_fetch_add(&c->ref_pair, delta) |
| 221 | : gpr_atm_no_barrier_fetch_add(&c->ref_pair, delta); |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 222 | #ifdef GRPC_STREAM_REFCOUNT_DEBUG |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 223 | gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, |
| 224 | "SUBCHANNEL: %p % 12s 0x%08x -> 0x%08x [%s]", c, purpose, old_val, |
| 225 | old_val + delta, reason); |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 226 | #endif |
| 227 | return old_val; |
| 228 | } |
| 229 | |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 230 | grpc_subchannel *grpc_subchannel_ref( |
| 231 | grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 232 | gpr_atm old_refs; |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 233 | old_refs = ref_mutate(c, (1 << INTERNAL_REF_BITS), |
| 234 | 0 REF_MUTATE_PURPOSE("STRONG_REF")); |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 235 | GPR_ASSERT((old_refs & STRONG_REF_MASK) != 0); |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 236 | return c; |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 239 | grpc_subchannel *grpc_subchannel_weak_ref( |
| 240 | grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 241 | gpr_atm old_refs; |
| 242 | old_refs = ref_mutate(c, 1, 0 REF_MUTATE_PURPOSE("WEAK_REF")); |
| 243 | GPR_ASSERT(old_refs != 0); |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 244 | return c; |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Craig Tiller | 5de79ee | 2016-01-25 08:16:02 -0800 | [diff] [blame] | 247 | grpc_subchannel *grpc_subchannel_ref_from_weak_ref( |
| 248 | grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { |
Craig Tiller | 8cdba66 | 2016-01-22 20:01:55 -0800 | [diff] [blame] | 249 | if (!c) return NULL; |
| 250 | for (;;) { |
| 251 | gpr_atm old_refs = gpr_atm_acq_load(&c->ref_pair); |
| 252 | if (old_refs >= (1 << INTERNAL_REF_BITS)) { |
| 253 | gpr_atm new_refs = old_refs + (1 << INTERNAL_REF_BITS); |
| 254 | if (gpr_atm_rel_cas(&c->ref_pair, old_refs, new_refs)) { |
| 255 | return c; |
| 256 | } |
| 257 | } else { |
| 258 | return NULL; |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 263 | static void disconnect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) { |
| 264 | grpc_connected_subchannel *con; |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 265 | grpc_subchannel_index_unregister(exec_ctx, c->key, c); |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 266 | gpr_mu_lock(&c->mu); |
| 267 | GPR_ASSERT(!c->disconnected); |
| 268 | c->disconnected = 1; |
Craig Tiller | caa4e70 | 2015-12-01 06:55:25 -0800 | [diff] [blame] | 269 | grpc_connector_shutdown(exec_ctx, c->connector); |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 270 | con = GET_CONNECTED_SUBCHANNEL(c, no_barrier); |
| 271 | if (con != NULL) { |
| 272 | GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, con, "connection"); |
| 273 | gpr_atm_no_barrier_store(&c->connected_subchannel, 0xdeadbeef); |
| 274 | } |
| 275 | gpr_mu_unlock(&c->mu); |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void grpc_subchannel_unref(grpc_exec_ctx *exec_ctx, |
| 279 | grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 280 | gpr_atm old_refs; |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 281 | old_refs = ref_mutate(c, (gpr_atm)1 - (gpr_atm)(1 << INTERNAL_REF_BITS), |
| 282 | 1 REF_MUTATE_PURPOSE("STRONG_UNREF")); |
Craig Tiller | 50ec267 | 2015-11-27 21:45:11 -0800 | [diff] [blame] | 283 | if ((old_refs & STRONG_REF_MASK) == (1 << INTERNAL_REF_BITS)) { |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 284 | disconnect(exec_ctx, c); |
| 285 | } |
| 286 | GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "strong-unref"); |
| 287 | } |
| 288 | |
| 289 | void grpc_subchannel_weak_unref(grpc_exec_ctx *exec_ctx, |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 290 | grpc_subchannel *c |
| 291 | GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 292 | gpr_atm old_refs; |
| 293 | old_refs = ref_mutate(c, -(gpr_atm)1, 1 REF_MUTATE_PURPOSE("WEAK_UNREF")); |
Craig Tiller | f036a64 | 2015-12-01 17:00:40 -0800 | [diff] [blame] | 294 | if (old_refs == 1) { |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 295 | grpc_exec_ctx_enqueue(exec_ctx, grpc_closure_create(subchannel_destroy, c), |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 296 | true, NULL); |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 300 | static uint32_t random_seed() { |
| 301 | return (uint32_t)(gpr_time_to_millis(gpr_now(GPR_CLOCK_MONOTONIC))); |
yang-g | b4e262c | 2015-07-21 16:11:55 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 304 | grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, |
| 305 | grpc_connector *connector, |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 306 | grpc_subchannel_args *args) { |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 307 | grpc_subchannel_key *key = grpc_subchannel_key_create(connector, args); |
| 308 | grpc_subchannel *c = grpc_subchannel_index_find(exec_ctx, key); |
| 309 | if (c) { |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 310 | grpc_subchannel_key_destroy(exec_ctx, key); |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 311 | return c; |
| 312 | } |
| 313 | |
| 314 | c = gpr_malloc(sizeof(*c)); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 315 | memset(c, 0, sizeof(*c)); |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 316 | c->key = key; |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 317 | gpr_atm_no_barrier_store(&c->ref_pair, 1 << INTERNAL_REF_BITS); |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 318 | c->connector = connector; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 319 | grpc_connector_ref(c->connector); |
Craig Tiller | 5945ee1 | 2015-06-27 10:36:09 -0700 | [diff] [blame] | 320 | c->num_filters = args->filter_count; |
Craig Tiller | b9c5505 | 2016-01-27 15:22:48 -0800 | [diff] [blame] | 321 | if (c->num_filters > 0) { |
| 322 | c->filters = gpr_malloc(sizeof(grpc_channel_filter *) * c->num_filters); |
| 323 | memcpy((void *)c->filters, args->filters, |
| 324 | sizeof(grpc_channel_filter *) * c->num_filters); |
| 325 | } else { |
| 326 | c->filters = NULL; |
| 327 | } |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 328 | c->addr = gpr_malloc(args->addr_len); |
| 329 | memcpy(c->addr, args->addr, args->addr_len); |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 330 | c->pollset_set = grpc_pollset_set_create(); |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 331 | c->addr_len = args->addr_len; |
yang-g | a612412 | 2015-11-05 22:36:20 -0800 | [diff] [blame] | 332 | grpc_set_initial_connect_string(&c->addr, &c->addr_len, |
| 333 | &c->initial_connect_string); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 334 | c->args = grpc_channel_args_copy(args->args); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 335 | c->random = random_seed(); |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 336 | c->root_external_state_watcher.next = c->root_external_state_watcher.prev = |
| 337 | &c->root_external_state_watcher; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 338 | grpc_closure_init(&c->connected, subchannel_connected, c); |
| 339 | grpc_connectivity_state_init(&c->state_tracker, GRPC_CHANNEL_IDLE, |
| 340 | "subchannel"); |
Craig Tiller | 536fc53 | 2016-03-11 12:36:56 -0800 | [diff] [blame] | 341 | gpr_backoff_init(&c->backoff_state, |
| 342 | GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER, |
| 343 | GRPC_SUBCHANNEL_RECONNECT_JITTER, |
| 344 | GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS * 1000, |
| 345 | GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS * 1000); |
| 346 | if (c->args) { |
| 347 | for (size_t i = 0; i < c->args->num_args; i++) { |
| 348 | if (0 == strcmp(c->args->args[i].key, |
| 349 | "grpc.testing.fixed_reconnect_backoff")) { |
| 350 | GPR_ASSERT(c->args->args[i].type == GRPC_ARG_INTEGER); |
| 351 | gpr_backoff_init(&c->backoff_state, 1.0, 0.0, |
| 352 | c->args->args[i].value.integer, |
| 353 | c->args->args[i].value.integer); |
| 354 | } |
| 355 | } |
| 356 | } |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 357 | gpr_mu_init(&c->mu); |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 358 | |
| 359 | return grpc_subchannel_index_register(exec_ctx, key, c); |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 362 | static void continue_connect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) { |
Craig Tiller | 4ab82d2 | 2015-06-29 09:40:33 -0700 | [diff] [blame] | 363 | grpc_connect_in_args args; |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 364 | |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 365 | args.interested_parties = c->pollset_set; |
Craig Tiller | 4ab82d2 | 2015-06-29 09:40:33 -0700 | [diff] [blame] | 366 | args.addr = c->addr; |
| 367 | args.addr_len = c->addr_len; |
Craig Tiller | 536fc53 | 2016-03-11 12:36:56 -0800 | [diff] [blame] | 368 | args.deadline = c->next_attempt; |
Craig Tiller | 4ab82d2 | 2015-06-29 09:40:33 -0700 | [diff] [blame] | 369 | args.channel_args = c->args; |
yang-g | a612412 | 2015-11-05 22:36:20 -0800 | [diff] [blame] | 370 | args.initial_connect_string = c->initial_connect_string; |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 371 | |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 372 | grpc_connectivity_state_set(exec_ctx, &c->state_tracker, |
| 373 | GRPC_CHANNEL_CONNECTING, "state_change"); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 374 | grpc_connector_connect(exec_ctx, c->connector, &args, &c->connecting_result, |
| 375 | &c->connected); |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 378 | static void start_connect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) { |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 379 | c->next_attempt = |
Craig Tiller | 536fc53 | 2016-03-11 12:36:56 -0800 | [diff] [blame] | 380 | gpr_backoff_begin(&c->backoff_state, gpr_now(GPR_CLOCK_MONOTONIC)); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 381 | continue_connect(exec_ctx, c); |
Craig Tiller | ff3ae68 | 2015-06-29 17:44:04 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 384 | grpc_connectivity_state grpc_subchannel_check_connectivity(grpc_subchannel *c) { |
Craig Tiller | 5f84c84 | 2015-06-26 16:08:21 -0700 | [diff] [blame] | 385 | grpc_connectivity_state state; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 386 | gpr_mu_lock(&c->mu); |
| 387 | state = grpc_connectivity_state_check(&c->state_tracker); |
| 388 | gpr_mu_unlock(&c->mu); |
Craig Tiller | 5f84c84 | 2015-06-26 16:08:21 -0700 | [diff] [blame] | 389 | return state; |
| 390 | } |
| 391 | |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 392 | static void on_external_state_watcher_done(grpc_exec_ctx *exec_ctx, void *arg, |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 393 | bool success) { |
Craig Tiller | 86c9958 | 2015-11-25 15:22:26 -0800 | [diff] [blame] | 394 | external_state_watcher *w = arg; |
| 395 | grpc_closure *follow_up = w->notify; |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 396 | if (w->pollset_set != NULL) { |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 397 | grpc_pollset_set_del_pollset_set(exec_ctx, w->subchannel->pollset_set, |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 398 | w->pollset_set); |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 399 | } |
| 400 | gpr_mu_lock(&w->subchannel->mu); |
| 401 | w->next->prev = w->prev; |
| 402 | w->prev->next = w->next; |
| 403 | gpr_mu_unlock(&w->subchannel->mu); |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 404 | GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, w->subchannel, "external_state_watcher"); |
Craig Tiller | 86c9958 | 2015-11-25 15:22:26 -0800 | [diff] [blame] | 405 | gpr_free(w); |
| 406 | follow_up->cb(exec_ctx, follow_up->cb_arg, success); |
| 407 | } |
| 408 | |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 409 | void grpc_subchannel_notify_on_state_change( |
| 410 | grpc_exec_ctx *exec_ctx, grpc_subchannel *c, |
| 411 | grpc_pollset_set *interested_parties, grpc_connectivity_state *state, |
| 412 | grpc_closure *notify) { |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 413 | external_state_watcher *w; |
| 414 | |
| 415 | if (state == NULL) { |
| 416 | gpr_mu_lock(&c->mu); |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 417 | for (w = c->root_external_state_watcher.next; |
| 418 | w != &c->root_external_state_watcher; w = w->next) { |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 419 | if (w->notify == notify) { |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 420 | grpc_connectivity_state_notify_on_state_change( |
| 421 | exec_ctx, &c->state_tracker, NULL, &w->closure); |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | gpr_mu_unlock(&c->mu); |
| 425 | } else { |
| 426 | w = gpr_malloc(sizeof(*w)); |
| 427 | w->subchannel = c; |
| 428 | w->pollset_set = interested_parties; |
| 429 | w->notify = notify; |
| 430 | grpc_closure_init(&w->closure, on_external_state_watcher_done, w); |
| 431 | if (interested_parties != NULL) { |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 432 | grpc_pollset_set_add_pollset_set(exec_ctx, c->pollset_set, |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 433 | interested_parties); |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 434 | } |
| 435 | GRPC_SUBCHANNEL_WEAK_REF(c, "external_state_watcher"); |
| 436 | gpr_mu_lock(&c->mu); |
| 437 | w->next = &c->root_external_state_watcher; |
| 438 | w->prev = w->next->prev; |
| 439 | w->next->prev = w->prev->next = w; |
| 440 | if (grpc_connectivity_state_notify_on_state_change( |
| 441 | exec_ctx, &c->state_tracker, state, &w->closure)) { |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 442 | c->connecting = 1; |
| 443 | /* released by connection */ |
| 444 | GRPC_SUBCHANNEL_WEAK_REF(c, "connecting"); |
Craig Tiller | 8e19f61 | 2016-03-01 21:41:13 -0800 | [diff] [blame] | 445 | start_connect(exec_ctx, c); |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 446 | } |
| 447 | gpr_mu_unlock(&c->mu); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 448 | } |
Craig Tiller | 5f84c84 | 2015-06-26 16:08:21 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 451 | void grpc_connected_subchannel_process_transport_op( |
| 452 | grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, |
| 453 | grpc_transport_op *op) { |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 454 | grpc_channel_stack *channel_stack = CHANNEL_STACK_FROM_CONNECTION(con); |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 455 | grpc_channel_element *top_elem = grpc_channel_stack_element(channel_stack, 0); |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 456 | top_elem->filter->start_transport_op(exec_ctx, top_elem, op); |
| 457 | } |
| 458 | |
| 459 | static void subchannel_on_child_state_changed(grpc_exec_ctx *exec_ctx, void *p, |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 460 | bool iomgr_success) { |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 461 | state_watcher *sw = p; |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 462 | grpc_subchannel *c = sw->subchannel; |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 463 | gpr_mu *mu = &c->mu; |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 464 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 465 | gpr_mu_lock(mu); |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 466 | |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 467 | /* if we failed just leave this closure */ |
| 468 | if (iomgr_success) { |
Craig Tiller | 2c17494 | 2015-11-24 16:51:23 -0800 | [diff] [blame] | 469 | if (sw->connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) { |
| 470 | /* any errors on a subchannel ==> we're done, create a new one */ |
| 471 | sw->connectivity_state = GRPC_CHANNEL_FATAL_FAILURE; |
| 472 | } |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 473 | grpc_connectivity_state_set(exec_ctx, &c->state_tracker, |
| 474 | sw->connectivity_state, "reflect_child"); |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 475 | if (sw->connectivity_state != GRPC_CHANNEL_FATAL_FAILURE) { |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 476 | grpc_connected_subchannel_notify_on_state_change( |
Craig Tiller | f036a64 | 2015-12-01 17:00:40 -0800 | [diff] [blame] | 477 | exec_ctx, GET_CONNECTED_SUBCHANNEL(c, no_barrier), NULL, |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 478 | &sw->connectivity_state, &sw->closure); |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 479 | GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher"); |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 480 | sw = NULL; |
| 481 | } |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 482 | } |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 483 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 484 | gpr_mu_unlock(mu); |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 485 | GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "state_watcher"); |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 486 | gpr_free(sw); |
| 487 | } |
| 488 | |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 489 | static void connected_subchannel_state_op(grpc_exec_ctx *exec_ctx, |
| 490 | grpc_connected_subchannel *con, |
Craig Tiller | f036a64 | 2015-12-01 17:00:40 -0800 | [diff] [blame] | 491 | grpc_pollset_set *interested_parties, |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 492 | grpc_connectivity_state *state, |
| 493 | grpc_closure *closure) { |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 494 | grpc_transport_op op; |
| 495 | grpc_channel_element *elem; |
| 496 | memset(&op, 0, sizeof(op)); |
| 497 | op.connectivity_state = state; |
| 498 | op.on_connectivity_state_change = closure; |
Craig Tiller | f036a64 | 2015-12-01 17:00:40 -0800 | [diff] [blame] | 499 | op.bind_pollset_set = interested_parties; |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 500 | elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); |
| 501 | elem->filter->start_transport_op(exec_ctx, elem, &op); |
| 502 | } |
| 503 | |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 504 | void grpc_connected_subchannel_notify_on_state_change( |
| 505 | grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, |
Craig Tiller | a6bebf4 | 2015-12-01 17:02:35 -0800 | [diff] [blame] | 506 | grpc_pollset_set *interested_parties, grpc_connectivity_state *state, |
| 507 | grpc_closure *closure) { |
| 508 | connected_subchannel_state_op(exec_ctx, con, interested_parties, state, |
| 509 | closure); |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 510 | } |
| 511 | |
Craig Tiller | e2c6237 | 2015-12-07 16:11:03 -0800 | [diff] [blame] | 512 | void grpc_connected_subchannel_ping(grpc_exec_ctx *exec_ctx, |
| 513 | grpc_connected_subchannel *con, |
| 514 | grpc_closure *closure) { |
Craig Tiller | 28bf891 | 2015-12-07 16:07:04 -0800 | [diff] [blame] | 515 | grpc_transport_op op; |
| 516 | grpc_channel_element *elem; |
| 517 | memset(&op, 0, sizeof(op)); |
| 518 | op.send_ping = closure; |
| 519 | elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); |
| 520 | elem->filter->start_transport_op(exec_ctx, elem, &op); |
| 521 | } |
| 522 | |
Craig Tiller | 3591482 | 2016-03-11 19:29:23 -0800 | [diff] [blame] | 523 | static void publish_transport_locked(grpc_exec_ctx *exec_ctx, |
| 524 | grpc_subchannel *c) { |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 525 | grpc_connected_subchannel *con; |
Craig Tiller | 4ab82d2 | 2015-06-29 09:40:33 -0700 | [diff] [blame] | 526 | grpc_channel_stack *stk; |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 527 | state_watcher *sw_subchannel; |
Craig Tiller | 5945ee1 | 2015-06-27 10:36:09 -0700 | [diff] [blame] | 528 | |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 529 | /* construct channel stack */ |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 530 | con = grpc_channel_init_create_stack( |
| 531 | exec_ctx, GRPC_CLIENT_SUBCHANNEL, 0, c->connecting_result.channel_args, 1, |
| 532 | connection_destroy, NULL, c->connecting_result.transport); |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 533 | stk = CHANNEL_STACK_FROM_CONNECTION(con); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 534 | memset(&c->connecting_result, 0, sizeof(c->connecting_result)); |
Craig Tiller | ff54c92 | 2015-06-26 16:57:20 -0700 | [diff] [blame] | 535 | |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 536 | /* initialize state watcher */ |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 537 | sw_subchannel = gpr_malloc(sizeof(*sw_subchannel)); |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 538 | sw_subchannel->subchannel = c; |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 539 | sw_subchannel->connectivity_state = GRPC_CHANNEL_READY; |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 540 | grpc_closure_init(&sw_subchannel->closure, subchannel_on_child_state_changed, |
| 541 | sw_subchannel); |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 542 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 543 | if (c->disconnected) { |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 544 | gpr_free(sw_subchannel); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 545 | grpc_channel_stack_destroy(exec_ctx, stk); |
Craig Tiller | 50ec267 | 2015-11-27 21:45:11 -0800 | [diff] [blame] | 546 | gpr_free(con); |
| 547 | GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 548 | return; |
| 549 | } |
Craig Tiller | b6fbf1d | 2015-06-29 15:25:49 -0700 | [diff] [blame] | 550 | |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 551 | /* publish */ |
Craig Tiller | 493c151 | 2016-01-27 11:55:44 -0800 | [diff] [blame] | 552 | /* TODO(ctiller): this full barrier seems to clear up a TSAN failure. |
| 553 | I'd have expected the rel_cas below to be enough, but |
| 554 | seemingly it's not. |
| 555 | Re-evaluate if we really need this. */ |
Craig Tiller | 9ebc87a | 2016-01-26 15:10:09 +0000 | [diff] [blame] | 556 | gpr_atm_full_barrier(); |
Craig Tiller | d9d474a | 2016-01-26 06:50:51 -0800 | [diff] [blame] | 557 | GPR_ASSERT(gpr_atm_rel_cas(&c->connected_subchannel, 0, (gpr_atm)con)); |
Craig Tiller | 4ab82d2 | 2015-06-29 09:40:33 -0700 | [diff] [blame] | 558 | c->connecting = 0; |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 559 | |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 560 | /* setup subchannel watching connected subchannel for changes; subchannel ref |
| 561 | for connecting is donated |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 562 | to the state watcher */ |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 563 | GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher"); |
Craig Tiller | 50ec267 | 2015-11-27 21:45:11 -0800 | [diff] [blame] | 564 | GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 565 | grpc_connected_subchannel_notify_on_state_change( |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 566 | exec_ctx, con, c->pollset_set, &sw_subchannel->connectivity_state, |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 567 | &sw_subchannel->closure); |
Craig Tiller | df91ba5 | 2015-06-29 10:55:46 -0700 | [diff] [blame] | 568 | |
| 569 | /* signal completion */ |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 570 | grpc_connectivity_state_set(exec_ctx, &c->state_tracker, GRPC_CHANNEL_READY, |
| 571 | "connected"); |
Craig Tiller | 4ab82d2 | 2015-06-29 09:40:33 -0700 | [diff] [blame] | 572 | } |
Craig Tiller | ff54c92 | 2015-06-26 16:57:20 -0700 | [diff] [blame] | 573 | |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 574 | static void on_alarm(grpc_exec_ctx *exec_ctx, void *arg, bool iomgr_success) { |
Craig Tiller | ff3ae68 | 2015-06-29 17:44:04 -0700 | [diff] [blame] | 575 | grpc_subchannel *c = arg; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 576 | gpr_mu_lock(&c->mu); |
Craig Tiller | ff3ae68 | 2015-06-29 17:44:04 -0700 | [diff] [blame] | 577 | c->have_alarm = 0; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 578 | if (c->disconnected) { |
| 579 | iomgr_success = 0; |
| 580 | } |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 581 | if (iomgr_success) { |
Craig Tiller | 536fc53 | 2016-03-11 12:36:56 -0800 | [diff] [blame] | 582 | c->next_attempt = |
| 583 | gpr_backoff_step(&c->backoff_state, gpr_now(GPR_CLOCK_MONOTONIC)); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 584 | continue_connect(exec_ctx, c); |
Craig Tiller | 8e19f61 | 2016-03-01 21:41:13 -0800 | [diff] [blame] | 585 | gpr_mu_unlock(&c->mu); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 586 | } else { |
Craig Tiller | 8e19f61 | 2016-03-01 21:41:13 -0800 | [diff] [blame] | 587 | gpr_mu_unlock(&c->mu); |
Craig Tiller | 50ec267 | 2015-11-27 21:45:11 -0800 | [diff] [blame] | 588 | GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 589 | } |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 592 | static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 593 | bool iomgr_success) { |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 594 | grpc_subchannel *c = arg; |
Craig Tiller | 50ec267 | 2015-11-27 21:45:11 -0800 | [diff] [blame] | 595 | |
Craig Tiller | 2ba4133 | 2016-03-11 17:09:12 -0800 | [diff] [blame] | 596 | GRPC_SUBCHANNEL_WEAK_REF(c, "connected"); |
| 597 | gpr_mu_lock(&c->mu); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 598 | if (c->connecting_result.transport != NULL) { |
Craig Tiller | 3591482 | 2016-03-11 19:29:23 -0800 | [diff] [blame] | 599 | publish_transport_locked(exec_ctx, c); |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 600 | } else if (c->disconnected) { |
Craig Tiller | 50ec267 | 2015-11-27 21:45:11 -0800 | [diff] [blame] | 601 | GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 602 | } else { |
| 603 | gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 604 | GPR_ASSERT(!c->have_alarm); |
| 605 | c->have_alarm = 1; |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 606 | grpc_connectivity_state_set(exec_ctx, &c->state_tracker, |
| 607 | GRPC_CHANNEL_TRANSIENT_FAILURE, |
| 608 | "connect_failed"); |
David Garcia Quintas | f747bbc | 2015-10-04 23:09:47 -0700 | [diff] [blame] | 609 | grpc_timer_init(exec_ctx, &c->alarm, c->next_attempt, on_alarm, c, now); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 610 | } |
Craig Tiller | 2ba4133 | 2016-03-11 17:09:12 -0800 | [diff] [blame] | 611 | gpr_mu_unlock(&c->mu); |
| 612 | GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 615 | /* |
| 616 | * grpc_subchannel_call implementation |
| 617 | */ |
| 618 | |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 619 | static void subchannel_call_destroy(grpc_exec_ctx *exec_ctx, void *call, |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 620 | bool success) { |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 621 | grpc_subchannel_call *c = call; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 622 | GPR_TIMER_BEGIN("grpc_subchannel_call_unref.destroy", 0); |
| 623 | grpc_call_stack_destroy(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c)); |
Craig Tiller | 53ee040 | 2015-11-25 09:07:09 -0800 | [diff] [blame] | 624 | GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, c->connection, "subchannel_call"); |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 625 | gpr_free(c); |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 626 | GPR_TIMER_END("grpc_subchannel_call_unref.destroy", 0); |
| 627 | } |
| 628 | |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 629 | void grpc_subchannel_call_ref( |
| 630 | grpc_subchannel_call *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 631 | GRPC_CALL_STACK_REF(SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); |
Craig Tiller | c396753 | 2015-06-29 14:59:38 -0700 | [diff] [blame] | 632 | } |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 633 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 634 | void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, |
| 635 | grpc_subchannel_call *c |
| 636 | GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 637 | GRPC_CALL_STACK_UNREF(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 640 | char *grpc_subchannel_call_get_peer(grpc_exec_ctx *exec_ctx, |
| 641 | grpc_subchannel_call *call) { |
| 642 | grpc_call_stack *call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call); |
| 643 | grpc_call_element *top_elem = grpc_call_stack_element(call_stack, 0); |
| 644 | return top_elem->filter->get_peer(exec_ctx, top_elem); |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 647 | void grpc_subchannel_call_process_op(grpc_exec_ctx *exec_ctx, |
| 648 | grpc_subchannel_call *call, |
| 649 | grpc_transport_stream_op *op) { |
| 650 | grpc_call_stack *call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call); |
| 651 | grpc_call_element *top_elem = grpc_call_stack_element(call_stack, 0); |
| 652 | top_elem->filter->start_transport_stream_op(exec_ctx, top_elem, op); |
Craig Tiller | 2595ab7 | 2015-06-25 15:26:00 -0700 | [diff] [blame] | 653 | } |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 654 | |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 655 | grpc_connected_subchannel *grpc_subchannel_get_connected_subchannel( |
| 656 | grpc_subchannel *c) { |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 657 | return GET_CONNECTED_SUBCHANNEL(c, acq); |
| 658 | } |
| 659 | |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 660 | grpc_subchannel_call *grpc_connected_subchannel_create_call( |
| 661 | grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, |
| 662 | grpc_pollset *pollset) { |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 663 | grpc_channel_stack *chanstk = CHANNEL_STACK_FROM_CONNECTION(con); |
| 664 | grpc_subchannel_call *call = |
| 665 | gpr_malloc(sizeof(grpc_subchannel_call) + chanstk->call_stack_size); |
| 666 | grpc_call_stack *callstk = SUBCHANNEL_CALL_TO_CALL_STACK(call); |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 667 | call->connection = con; |
Craig Tiller | 53ee040 | 2015-11-25 09:07:09 -0800 | [diff] [blame] | 668 | GRPC_CONNECTED_SUBCHANNEL_REF(con, "subchannel_call"); |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 669 | grpc_call_stack_init(exec_ctx, chanstk, 1, subchannel_call_destroy, call, |
| 670 | NULL, NULL, callstk); |
| 671 | grpc_call_stack_set_pollset(exec_ctx, callstk, pollset); |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 672 | return call; |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 673 | } |
David Garcia Quintas | 7b1bd2c | 2015-10-05 18:22:10 -0700 | [diff] [blame] | 674 | |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 675 | grpc_call_stack *grpc_subchannel_call_get_call_stack( |
| 676 | grpc_subchannel_call *subchannel_call) { |
| 677 | return SUBCHANNEL_CALL_TO_CALL_STACK(subchannel_call); |
| 678 | } |