blob: 769e22b061f40221e0838fa65aaf38c9985b2927 [file] [log] [blame]
Craig Tiller577c9b22015-11-02 14:11:15 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Craig Tiller577c9b22015-11-02 14:11:15 -08004 * 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 Tiller9a4dddd2016-03-25 17:08:13 -070034#ifndef GRPC_CORE_LIB_CHANNEL_SUBCHANNEL_CALL_HOLDER_H
35#define GRPC_CORE_LIB_CHANNEL_SUBCHANNEL_CALL_HOLDER_H
Craig Tiller577c9b22015-11-02 14:11:15 -080036
Craig Tiller9533d042016-03-25 17:11:06 -070037#include "src/core/lib/client_config/subchannel.h"
Craig Tiller577c9b22015-11-02 14:11:15 -080038
Craig Tiller892f2d32015-11-08 13:53:04 +000039/** 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 Tiller577c9b22015-11-02 14:11:15 -080043typedef int (*grpc_subchannel_call_holder_pick_subchannel)(
44 grpc_exec_ctx *exec_ctx, void *arg, grpc_metadata_batch *initial_metadata,
Craig Tiller8c0d96f2016-03-11 14:27:52 -080045 uint32_t initial_metadata_flags,
Craig Tillerb5585d42015-11-17 07:18:31 -080046 grpc_connected_subchannel **connected_subchannel, grpc_closure *on_ready);
Craig Tiller577c9b22015-11-02 14:11:15 -080047
48typedef enum {
49 GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING,
Craig Tillerb5585d42015-11-17 07:18:31 -080050 GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL
Craig Tiller577c9b22015-11-02 14:11:15 -080051} grpc_subchannel_call_holder_creation_phase;
52
Craig Tiller892f2d32015-11-08 13:53:04 +000053/** 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 Quintasfb349b92016-03-21 15:37:20 -070059 The channel filter uses this as their call_data. */
Craig Tiller577c9b22015-11-02 14:11:15 -080060typedef struct grpc_subchannel_call_holder {
Craig Tiller892f2d32015-11-08 13:53:04 +000061 /** either 0 for no call, 1 for cancelled, or a pointer to a
62 grpc_subchannel_call */
Craig Tiller577c9b22015-11-02 14:11:15 -080063 gpr_atm subchannel_call;
Craig Tiller892f2d32015-11-08 13:53:04 +000064 /** Helper function to choose the subchannel on which to create
65 the call object. Channel filter delegates to the load
David Garcia Quintasfb349b92016-03-21 15:37:20 -070066 balancing policy (once it's ready). */
Craig Tiller577c9b22015-11-02 14:11:15 -080067 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 Tillerb5585d42015-11-17 07:18:31 -080073 grpc_connected_subchannel *connected_subchannel;
Craig Tiller577c9b22015-11-02 14:11:15 -080074 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 Tiller11beb9a2015-11-24 10:29:32 -080081
82 grpc_call_stack *owning_call;
Craig Tiller577c9b22015-11-02 14:11:15 -080083} grpc_subchannel_call_holder;
84
85void grpc_subchannel_call_holder_init(
86 grpc_subchannel_call_holder *holder,
87 grpc_subchannel_call_holder_pick_subchannel pick_subchannel,
Craig Tiller11beb9a2015-11-24 10:29:32 -080088 void *pick_subchannel_arg, grpc_call_stack *owning_call);
Craig Tiller577c9b22015-11-02 14:11:15 -080089void grpc_subchannel_call_holder_destroy(grpc_exec_ctx *exec_ctx,
90 grpc_subchannel_call_holder *holder);
91
92void grpc_subchannel_call_holder_perform_op(grpc_exec_ctx *exec_ctx,
93 grpc_subchannel_call_holder *holder,
94 grpc_transport_stream_op *op);
95char *grpc_subchannel_call_holder_get_peer(grpc_exec_ctx *exec_ctx,
Craig Tiller906e3bc2015-11-24 07:31:31 -080096 grpc_subchannel_call_holder *holder);
Craig Tiller577c9b22015-11-02 14:11:15 -080097
Craig Tiller9a4dddd2016-03-25 17:08:13 -070098#endif /* GRPC_CORE_LIB_CHANNEL_SUBCHANNEL_CALL_HOLDER_H */