Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -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, |
| 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 | |
Craig Tiller | 5aceb27 | 2016-03-31 13:50:42 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_H |
| 35 | #define GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_H |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 36 | |
Craig Tiller | d4c9833 | 2016-03-31 13:45:47 -0700 | [diff] [blame] | 37 | #include "src/core/ext/client_config/connector.h" |
Craig Tiller | 4a6dad3 | 2016-04-01 13:51:14 -0700 | [diff] [blame] | 38 | #include "src/core/lib/channel/channel_stack.h" |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 39 | #include "src/core/lib/iomgr/polling_entity.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 40 | #include "src/core/lib/transport/connectivity_state.h" |
Craig Tiller | af69180 | 2015-06-23 14:57:07 -0700 | [diff] [blame] | 41 | |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 42 | /** A (sub-)channel that knows how to connect to exactly one target |
| 43 | address. Provides a target for load balancing. */ |
Craig Tiller | 9e8f911 | 2015-06-23 10:56:11 -0700 | [diff] [blame] | 44 | typedef struct grpc_subchannel grpc_subchannel; |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 45 | typedef struct grpc_connected_subchannel grpc_connected_subchannel; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 46 | typedef struct grpc_subchannel_call grpc_subchannel_call; |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 47 | typedef struct grpc_subchannel_args grpc_subchannel_args; |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 48 | |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 49 | #ifdef GRPC_STREAM_REFCOUNT_DEBUG |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 50 | #define GRPC_SUBCHANNEL_REF(p, r) \ |
| 51 | grpc_subchannel_ref((p), __FILE__, __LINE__, (r)) |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 52 | #define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \ |
| 53 | grpc_subchannel_ref_from_weak_ref((p), __FILE__, __LINE__, (r)) |
Craig Tiller | 8af4c33 | 2015-09-22 12:32:31 -0700 | [diff] [blame] | 54 | #define GRPC_SUBCHANNEL_UNREF(cl, p, r) \ |
| 55 | grpc_subchannel_unref((cl), (p), __FILE__, __LINE__, (r)) |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 56 | #define GRPC_SUBCHANNEL_WEAK_REF(p, r) \ |
| 57 | grpc_subchannel_weak_ref((p), __FILE__, __LINE__, (r)) |
| 58 | #define GRPC_SUBCHANNEL_WEAK_UNREF(cl, p, r) \ |
| 59 | grpc_subchannel_weak_unref((cl), (p), __FILE__, __LINE__, (r)) |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 60 | #define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) \ |
| 61 | grpc_connected_subchannel_ref((p), __FILE__, __LINE__, (r)) |
| 62 | #define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ |
| 63 | grpc_connected_subchannel_unref((cl), (p), __FILE__, __LINE__, (r)) |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 64 | #define GRPC_SUBCHANNEL_CALL_REF(p, r) \ |
| 65 | grpc_subchannel_call_ref((p), __FILE__, __LINE__, (r)) |
Craig Tiller | 8af4c33 | 2015-09-22 12:32:31 -0700 | [diff] [blame] | 66 | #define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ |
| 67 | grpc_subchannel_call_unref((cl), (p), __FILE__, __LINE__, (r)) |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 68 | #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS \ |
| 69 | , const char *file, int line, const char *reason |
Craig Tiller | c396753 | 2015-06-29 14:59:38 -0700 | [diff] [blame] | 70 | #else |
| 71 | #define GRPC_SUBCHANNEL_REF(p, r) grpc_subchannel_ref((p)) |
Craig Tiller | 5de79ee | 2016-01-25 08:16:02 -0800 | [diff] [blame] | 72 | #define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \ |
| 73 | grpc_subchannel_ref_from_weak_ref((p)) |
Craig Tiller | 8af4c33 | 2015-09-22 12:32:31 -0700 | [diff] [blame] | 74 | #define GRPC_SUBCHANNEL_UNREF(cl, p, r) grpc_subchannel_unref((cl), (p)) |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 75 | #define GRPC_SUBCHANNEL_WEAK_REF(p, r) grpc_subchannel_weak_ref((p)) |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 76 | #define GRPC_SUBCHANNEL_WEAK_UNREF(cl, p, r) \ |
| 77 | grpc_subchannel_weak_unref((cl), (p)) |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 78 | #define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) grpc_connected_subchannel_ref((p)) |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 79 | #define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ |
| 80 | grpc_connected_subchannel_unref((cl), (p)) |
Craig Tiller | c396753 | 2015-06-29 14:59:38 -0700 | [diff] [blame] | 81 | #define GRPC_SUBCHANNEL_CALL_REF(p, r) grpc_subchannel_call_ref((p)) |
Craig Tiller | 8af4c33 | 2015-09-22 12:32:31 -0700 | [diff] [blame] | 82 | #define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ |
| 83 | grpc_subchannel_call_unref((cl), (p)) |
Craig Tiller | c396753 | 2015-06-29 14:59:38 -0700 | [diff] [blame] | 84 | #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS |
| 85 | #endif |
| 86 | |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 87 | grpc_subchannel *grpc_subchannel_ref( |
| 88 | grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
Craig Tiller | 5de79ee | 2016-01-25 08:16:02 -0800 | [diff] [blame] | 89 | grpc_subchannel *grpc_subchannel_ref_from_weak_ref( |
| 90 | grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 91 | void grpc_subchannel_unref(grpc_exec_ctx *exec_ctx, |
| 92 | grpc_subchannel *channel |
Craig Tiller | ddf3a51 | 2015-09-24 13:03:44 -0700 | [diff] [blame] | 93 | GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 94 | grpc_subchannel *grpc_subchannel_weak_ref( |
| 95 | grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
Craig Tiller | 12ad5d6 | 2015-11-27 12:17:30 -0800 | [diff] [blame] | 96 | void grpc_subchannel_weak_unref(grpc_exec_ctx *exec_ctx, |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 97 | grpc_subchannel *channel |
| 98 | GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 99 | void grpc_connected_subchannel_ref( |
| 100 | grpc_connected_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 101 | void grpc_connected_subchannel_unref(grpc_exec_ctx *exec_ctx, |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 102 | grpc_connected_subchannel *channel |
| 103 | GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 104 | void grpc_subchannel_call_ref( |
| 105 | grpc_subchannel_call *call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 106 | void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, |
| 107 | grpc_subchannel_call *call |
Craig Tiller | ddf3a51 | 2015-09-24 13:03:44 -0700 | [diff] [blame] | 108 | GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 109 | |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 110 | /** construct a subchannel call */ |
Mark D. Roth | 09e6698 | 2016-06-23 11:14:18 -0700 | [diff] [blame] | 111 | grpc_error *grpc_connected_subchannel_create_call( |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 112 | grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *connected_subchannel, |
Mark D. Roth | 76d2442 | 2016-06-23 13:22:10 -0700 | [diff] [blame] | 113 | grpc_polling_entity *pollent, grpc_subchannel_call **subchannel_call); |
David Garcia Quintas | 17ee390 | 2015-10-05 16:10:20 -0700 | [diff] [blame] | 114 | |
Craig Tiller | c7b5f76 | 2015-06-27 11:48:42 -0700 | [diff] [blame] | 115 | /** process a transport level op */ |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 116 | void grpc_connected_subchannel_process_transport_op( |
| 117 | grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *subchannel, |
| 118 | grpc_transport_op *op); |
Craig Tiller | c7b5f76 | 2015-06-27 11:48:42 -0700 | [diff] [blame] | 119 | |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 120 | /** poll the current connectivity state of a channel */ |
Craig Tiller | 9e8f911 | 2015-06-23 10:56:11 -0700 | [diff] [blame] | 121 | grpc_connectivity_state grpc_subchannel_check_connectivity( |
Craig Tiller | 804ff71 | 2016-05-05 16:25:40 -0700 | [diff] [blame] | 122 | grpc_subchannel *channel, grpc_error **error); |
Craig Tiller | d58b5b8 | 2015-06-23 12:30:00 -0700 | [diff] [blame] | 123 | |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 124 | /** call notify when the connectivity state of a channel changes from *state. |
| 125 | Updates *state with the new state of the channel */ |
Craig Tiller | 1d881fb | 2015-12-01 07:39:04 -0800 | [diff] [blame] | 126 | void grpc_subchannel_notify_on_state_change( |
| 127 | grpc_exec_ctx *exec_ctx, grpc_subchannel *channel, |
| 128 | grpc_pollset_set *interested_parties, grpc_connectivity_state *state, |
| 129 | grpc_closure *notify); |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 130 | void grpc_connected_subchannel_notify_on_state_change( |
| 131 | grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *channel, |
Craig Tiller | a6bebf4 | 2015-12-01 17:02:35 -0800 | [diff] [blame] | 132 | grpc_pollset_set *interested_parties, grpc_connectivity_state *state, |
| 133 | grpc_closure *notify); |
Craig Tiller | e2c6237 | 2015-12-07 16:11:03 -0800 | [diff] [blame] | 134 | void grpc_connected_subchannel_ping(grpc_exec_ctx *exec_ctx, |
| 135 | grpc_connected_subchannel *channel, |
| 136 | grpc_closure *notify); |
Craig Tiller | d58b5b8 | 2015-06-23 12:30:00 -0700 | [diff] [blame] | 137 | |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 138 | /** retrieve the grpc_connected_subchannel - or NULL if called before |
| 139 | the subchannel becomes connected */ |
Craig Tiller | ab33b48 | 2015-11-21 08:11:04 -0800 | [diff] [blame] | 140 | grpc_connected_subchannel *grpc_subchannel_get_connected_subchannel( |
| 141 | grpc_subchannel *subchannel); |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 142 | |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 143 | /** continue processing a transport op */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 144 | void grpc_subchannel_call_process_op(grpc_exec_ctx *exec_ctx, |
| 145 | grpc_subchannel_call *subchannel_call, |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 146 | grpc_transport_stream_op *op); |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 147 | |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 148 | /** continue querying for peer */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 149 | char *grpc_subchannel_call_get_peer(grpc_exec_ctx *exec_ctx, |
| 150 | grpc_subchannel_call *subchannel_call); |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 151 | |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 152 | grpc_call_stack *grpc_subchannel_call_get_call_stack( |
| 153 | grpc_subchannel_call *subchannel_call); |
| 154 | |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 155 | struct grpc_subchannel_args { |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 156 | /* When updating this struct, also update subchannel_index.c */ |
Craig Tiller | 5de79ee | 2016-01-25 08:16:02 -0800 | [diff] [blame] | 157 | |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 158 | /** Channel filters for this channel - wrapped factories will likely |
| 159 | want to mutate this */ |
| 160 | const grpc_channel_filter **filters; |
| 161 | /** The number of filters in the above array */ |
| 162 | size_t filter_count; |
| 163 | /** Channel arguments to be supplied to the newly created channel */ |
| 164 | const grpc_channel_args *args; |
Mark D. Roth | e273b03 | 2016-07-22 13:24:21 -0700 | [diff] [blame] | 165 | /** Server name */ |
| 166 | char *server_name; // Does not own. |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 167 | /** Address to connect to */ |
| 168 | struct sockaddr *addr; |
| 169 | size_t addr_len; |
| 170 | }; |
| 171 | |
Craig Tiller | 9162466 | 2015-06-25 16:31:02 -0700 | [diff] [blame] | 172 | /** create a subchannel given a connector */ |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 173 | grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, |
| 174 | grpc_connector *connector, |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 175 | grpc_subchannel_args *args); |
Craig Tiller | 9162466 | 2015-06-25 16:31:02 -0700 | [diff] [blame] | 176 | |
Craig Tiller | 5aceb27 | 2016-03-31 13:50:42 -0700 | [diff] [blame] | 177 | #endif /* GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_H */ |