Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -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 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_LIB_CHANNEL_SUBCHANNEL_CALL_HOLDER_H |
| 35 | #define GRPC_CORE_LIB_CHANNEL_SUBCHANNEL_CALL_HOLDER_H |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 36 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 37 | #include "src/core/lib/client_config/subchannel.h" |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 38 | |
Craig Tiller | 892f2d3 | 2015-11-08 13:53:04 +0000 | [diff] [blame] | 39 | /** Pick a subchannel for grpc_subchannel_call_holder; |
| 40 | Return 1 if subchannel is available immediately (in which case on_ready |
| 41 | should not be called), or 0 otherwise (in which case on_ready should be |
| 42 | called when the subchannel is available) */ |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 43 | typedef int (*grpc_subchannel_call_holder_pick_subchannel)( |
| 44 | grpc_exec_ctx *exec_ctx, void *arg, grpc_metadata_batch *initial_metadata, |
Craig Tiller | 8c0d96f | 2016-03-11 14:27:52 -0800 | [diff] [blame] | 45 | uint32_t initial_metadata_flags, |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 46 | grpc_connected_subchannel **connected_subchannel, grpc_closure *on_ready); |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 47 | |
| 48 | typedef enum { |
| 49 | GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING, |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 50 | GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 51 | } grpc_subchannel_call_holder_creation_phase; |
| 52 | |
Craig Tiller | 892f2d3 | 2015-11-08 13:53:04 +0000 | [diff] [blame] | 53 | /** Wrapper for holding a pointer to grpc_subchannel_call, and the |
| 54 | associated machinery to create such a pointer. |
| 55 | Handles queueing of stream ops until a call object is ready, waiting |
| 56 | for initial metadata before trying to create a call object, |
| 57 | and handling cancellation gracefully. |
| 58 | |
David Garcia Quintas | fb349b9 | 2016-03-21 15:37:20 -0700 | [diff] [blame] | 59 | The channel filter uses this as their call_data. */ |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 60 | typedef struct grpc_subchannel_call_holder { |
Craig Tiller | 892f2d3 | 2015-11-08 13:53:04 +0000 | [diff] [blame] | 61 | /** either 0 for no call, 1 for cancelled, or a pointer to a |
| 62 | grpc_subchannel_call */ |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 63 | gpr_atm subchannel_call; |
Craig Tiller | 892f2d3 | 2015-11-08 13:53:04 +0000 | [diff] [blame] | 64 | /** Helper function to choose the subchannel on which to create |
| 65 | the call object. Channel filter delegates to the load |
David Garcia Quintas | fb349b9 | 2016-03-21 15:37:20 -0700 | [diff] [blame] | 66 | balancing policy (once it's ready). */ |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 67 | grpc_subchannel_call_holder_pick_subchannel pick_subchannel; |
| 68 | void *pick_subchannel_arg; |
| 69 | |
| 70 | gpr_mu mu; |
| 71 | |
| 72 | grpc_subchannel_call_holder_creation_phase creation_phase; |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 73 | grpc_connected_subchannel *connected_subchannel; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 74 | grpc_pollset *pollset; |
| 75 | |
| 76 | grpc_transport_stream_op *waiting_ops; |
| 77 | size_t waiting_ops_count; |
| 78 | size_t waiting_ops_capacity; |
| 79 | |
| 80 | grpc_closure next_step; |
Craig Tiller | 11beb9a | 2015-11-24 10:29:32 -0800 | [diff] [blame] | 81 | |
| 82 | grpc_call_stack *owning_call; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 83 | } grpc_subchannel_call_holder; |
| 84 | |
| 85 | void grpc_subchannel_call_holder_init( |
| 86 | grpc_subchannel_call_holder *holder, |
| 87 | grpc_subchannel_call_holder_pick_subchannel pick_subchannel, |
Craig Tiller | 11beb9a | 2015-11-24 10:29:32 -0800 | [diff] [blame] | 88 | void *pick_subchannel_arg, grpc_call_stack *owning_call); |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 89 | void grpc_subchannel_call_holder_destroy(grpc_exec_ctx *exec_ctx, |
| 90 | grpc_subchannel_call_holder *holder); |
| 91 | |
| 92 | void grpc_subchannel_call_holder_perform_op(grpc_exec_ctx *exec_ctx, |
| 93 | grpc_subchannel_call_holder *holder, |
| 94 | grpc_transport_stream_op *op); |
| 95 | char *grpc_subchannel_call_holder_get_peer(grpc_exec_ctx *exec_ctx, |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 96 | grpc_subchannel_call_holder *holder); |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 97 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 98 | #endif /* GRPC_CORE_LIB_CHANNEL_SUBCHANNEL_CALL_HOLDER_H */ |