Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [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 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_LIB_TRANSPORT_TRANSPORT_H |
| 35 | #define GRPC_CORE_LIB_TRANSPORT_TRANSPORT_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
| 37 | #include <stddef.h> |
| 38 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 39 | #include "src/core/lib/channel/context.h" |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 40 | #include "src/core/lib/iomgr/polling_entity.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 41 | #include "src/core/lib/iomgr/pollset.h" |
| 42 | #include "src/core/lib/iomgr/pollset_set.h" |
| 43 | #include "src/core/lib/transport/byte_stream.h" |
| 44 | #include "src/core/lib/transport/metadata_batch.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 45 | |
Mark D. Roth | 035cb3a | 2016-06-16 14:52:41 -0700 | [diff] [blame] | 46 | #ifdef __cplusplus |
| 47 | extern "C" { |
| 48 | #endif |
| 49 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 50 | /* forward declarations */ |
| 51 | typedef struct grpc_transport grpc_transport; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 52 | |
| 53 | /* grpc_stream doesn't actually exist. It's used as a typesafe |
| 54 | opaque pointer for whatever data the transport wants to track |
| 55 | for a stream. */ |
| 56 | typedef struct grpc_stream grpc_stream; |
| 57 | |
Craig Tiller | f0e1119 | 2016-08-19 11:32:28 -0700 | [diff] [blame] | 58 | //#define GRPC_STREAM_REFCOUNT_DEBUG |
Craig Tiller | 4861304 | 2015-11-29 14:45:11 -0800 | [diff] [blame] | 59 | |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 60 | typedef struct grpc_stream_refcount { |
| 61 | gpr_refcount refs; |
| 62 | grpc_closure destroy; |
Craig Tiller | 27e5aa4 | 2015-11-24 16:28:54 -0800 | [diff] [blame] | 63 | #ifdef GRPC_STREAM_REFCOUNT_DEBUG |
| 64 | const char *object_type; |
| 65 | #endif |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 66 | } grpc_stream_refcount; |
| 67 | |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 68 | #ifdef GRPC_STREAM_REFCOUNT_DEBUG |
Craig Tiller | 27e5aa4 | 2015-11-24 16:28:54 -0800 | [diff] [blame] | 69 | void grpc_stream_ref_init(grpc_stream_refcount *refcount, int initial_refs, |
| 70 | grpc_iomgr_cb_func cb, void *cb_arg, |
| 71 | const char *object_type); |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 72 | void grpc_stream_ref(grpc_stream_refcount *refcount, const char *reason); |
| 73 | void grpc_stream_unref(grpc_exec_ctx *exec_ctx, grpc_stream_refcount *refcount, |
| 74 | const char *reason); |
Craig Tiller | 27e5aa4 | 2015-11-24 16:28:54 -0800 | [diff] [blame] | 75 | #define GRPC_STREAM_REF_INIT(rc, ir, cb, cb_arg, objtype) \ |
| 76 | grpc_stream_ref_init(rc, ir, cb, cb_arg, objtype) |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 77 | #else |
Craig Tiller | 27e5aa4 | 2015-11-24 16:28:54 -0800 | [diff] [blame] | 78 | void grpc_stream_ref_init(grpc_stream_refcount *refcount, int initial_refs, |
| 79 | grpc_iomgr_cb_func cb, void *cb_arg); |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 80 | void grpc_stream_ref(grpc_stream_refcount *refcount); |
| 81 | void grpc_stream_unref(grpc_exec_ctx *exec_ctx, grpc_stream_refcount *refcount); |
Craig Tiller | 27e5aa4 | 2015-11-24 16:28:54 -0800 | [diff] [blame] | 82 | #define GRPC_STREAM_REF_INIT(rc, ir, cb, cb_arg, objtype) \ |
| 83 | grpc_stream_ref_init(rc, ir, cb, cb_arg) |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 84 | #endif |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 85 | |
Craig Tiller | 466129e | 2016-03-09 14:43:18 -0800 | [diff] [blame] | 86 | typedef struct { |
| 87 | uint64_t framing_bytes; |
| 88 | uint64_t data_bytes; |
| 89 | uint64_t header_bytes; |
| 90 | } grpc_transport_one_way_stats; |
| 91 | |
| 92 | typedef struct grpc_transport_stream_stats { |
| 93 | grpc_transport_one_way_stats incoming; |
| 94 | grpc_transport_one_way_stats outgoing; |
| 95 | } grpc_transport_stream_stats; |
| 96 | |
| 97 | void grpc_transport_move_one_way_stats(grpc_transport_one_way_stats *from, |
| 98 | grpc_transport_one_way_stats *to); |
| 99 | |
| 100 | void grpc_transport_move_stats(grpc_transport_stream_stats *from, |
| 101 | grpc_transport_stream_stats *to); |
| 102 | |
Craig Tiller | 93023e4 | 2016-07-11 12:43:23 -0700 | [diff] [blame] | 103 | typedef struct { |
| 104 | grpc_closure closure; |
| 105 | void *args[2]; |
| 106 | } grpc_transport_private_op_data; |
| 107 | |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 108 | /* Transport stream op: a set of operations to perform on a transport |
| 109 | against a single stream */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 110 | typedef struct grpc_transport_stream_op { |
Craig Tiller | a67a83e | 2016-03-22 21:43:59 -0700 | [diff] [blame] | 111 | /** Should be enqueued when all requested operations (excluding recv_message |
| 112 | and recv_initial_metadata which have their own closures) in a given batch |
| 113 | have been completed. */ |
| 114 | grpc_closure *on_complete; |
| 115 | |
Craig Tiller | c654976 | 2016-03-09 17:10:43 -0800 | [diff] [blame] | 116 | /** Send initial metadata to the peer, from the provided metadata batch. |
| 117 | idempotent_request MUST be set if this is non-null */ |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 118 | grpc_metadata_batch *send_initial_metadata; |
Craig Tiller | 8c0d96f | 2016-03-11 14:27:52 -0800 | [diff] [blame] | 119 | /** Iff send_initial_metadata != NULL, flags associated with |
| 120 | send_initial_metadata: a bitfield of GRPC_INITIAL_METADATA_xxx */ |
| 121 | uint32_t send_initial_metadata_flags; |
Robbie Shade | 9891e8f | 2016-01-25 13:19:32 -0500 | [diff] [blame] | 122 | |
| 123 | /** Send trailing metadata to the peer, from the provided metadata batch. */ |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 124 | grpc_metadata_batch *send_trailing_metadata; |
Craig Tiller | 5dde66e | 2015-06-02 09:05:23 -0700 | [diff] [blame] | 125 | |
Robbie Shade | 9891e8f | 2016-01-25 13:19:32 -0500 | [diff] [blame] | 126 | /** Send message data to the peer, from the provided byte stream. */ |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 127 | grpc_byte_stream *send_message; |
Craig Tiller | 3f2c221 | 2015-04-23 07:56:33 -0700 | [diff] [blame] | 128 | |
Robbie Shade | 9891e8f | 2016-01-25 13:19:32 -0500 | [diff] [blame] | 129 | /** Receive initial metadata from the stream, into provided metadata batch. */ |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 130 | grpc_metadata_batch *recv_initial_metadata; |
Craig Tiller | 4d40ba3 | 2016-03-09 17:48:40 -0800 | [diff] [blame] | 131 | bool *recv_idempotent_request; |
Craig Tiller | a44cbfc | 2016-02-03 16:02:49 -0800 | [diff] [blame] | 132 | /** Should be enqueued when initial metadata is ready to be processed. */ |
| 133 | grpc_closure *recv_initial_metadata_ready; |
Robbie Shade | 9891e8f | 2016-01-25 13:19:32 -0500 | [diff] [blame] | 134 | |
| 135 | /** Receive message data from the stream, into provided byte stream. */ |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 136 | grpc_byte_stream **recv_message; |
Robbie Shade | 9891e8f | 2016-01-25 13:19:32 -0500 | [diff] [blame] | 137 | /** Should be enqueued when one message is ready to be processed. */ |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 138 | grpc_closure *recv_message_ready; |
Robbie Shade | 9891e8f | 2016-01-25 13:19:32 -0500 | [diff] [blame] | 139 | |
Robbie Shade | cdc182e | 2016-01-29 09:39:57 -0500 | [diff] [blame] | 140 | /** Receive trailing metadata from the stream, into provided metadata batch. |
| 141 | */ |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 142 | grpc_metadata_batch *recv_trailing_metadata; |
Craig Tiller | 3f2c221 | 2015-04-23 07:56:33 -0700 | [diff] [blame] | 143 | |
Craig Tiller | 466129e | 2016-03-09 14:43:18 -0800 | [diff] [blame] | 144 | /** Collect any stats into provided buffer, zero internal stat counters */ |
| 145 | grpc_transport_stream_stats *collect_stats; |
| 146 | |
Craig Tiller | f0f70a8 | 2016-06-23 13:55:06 -0700 | [diff] [blame] | 147 | /** If != GRPC_ERROR_NONE, cancel this stream */ |
| 148 | grpc_error *cancel_error; |
Craig Tiller | 935cf42 | 2015-05-01 14:10:46 -0700 | [diff] [blame] | 149 | |
Nicolas "Pixel" Noble | 4b4266a | 2016-07-23 00:20:02 +0200 | [diff] [blame] | 150 | /** If != GRPC_ERROR_NONE, send grpc-status, grpc-message, and close this |
Craig Tiller | 45ce927 | 2015-07-31 11:22:35 -0700 | [diff] [blame] | 151 | stream for both reading and writing */ |
Craig Tiller | f0f70a8 | 2016-06-23 13:55:06 -0700 | [diff] [blame] | 152 | grpc_error *close_error; |
Craig Tiller | 45ce927 | 2015-07-31 11:22:35 -0700 | [diff] [blame] | 153 | |
Craig Tiller | 935cf42 | 2015-05-01 14:10:46 -0700 | [diff] [blame] | 154 | /* Indexes correspond to grpc_context_index enum values */ |
Julien Boeuf | 83b0297 | 2015-05-20 22:50:34 -0700 | [diff] [blame] | 155 | grpc_call_context_element *context; |
Craig Tiller | 93023e4 | 2016-07-11 12:43:23 -0700 | [diff] [blame] | 156 | |
| 157 | /*************************************************************************** |
| 158 | * remaining fields are initialized and used at the discretion of the |
| 159 | * transport implementation */ |
| 160 | |
| 161 | grpc_transport_private_op_data transport_private; |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 162 | } grpc_transport_stream_op; |
Craig Tiller | 3f2c221 | 2015-04-23 07:56:33 -0700 | [diff] [blame] | 163 | |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 164 | /** Transport op: a set of operations to perform on a transport as a whole */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 165 | typedef struct grpc_transport_op { |
Craig Tiller | 1bd9ea4 | 2016-03-03 21:09:31 -0800 | [diff] [blame] | 166 | /** Called when processing of this op is done. */ |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 167 | grpc_closure *on_consumed; |
Craig Tiller | b5585d4 | 2015-11-17 07:18:31 -0800 | [diff] [blame] | 168 | /** connectivity monitoring - set connectivity_state to NULL to unsubscribe */ |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 169 | grpc_closure *on_connectivity_state_change; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 170 | grpc_connectivity_state *connectivity_state; |
| 171 | /** should the transport be disconnected */ |
Craig Tiller | 804ff71 | 2016-05-05 16:25:40 -0700 | [diff] [blame] | 172 | grpc_error *disconnect_with_error; |
Craig Tiller | 9188d7a | 2015-07-05 12:44:37 -0700 | [diff] [blame] | 173 | /** should we send a goaway? |
| 174 | after a goaway is sent, once there are no more active calls on |
| 175 | the transport, the transport should disconnect */ |
Mark D. Roth | 7f8db25 | 2016-06-24 08:24:15 -0700 | [diff] [blame] | 176 | bool send_goaway; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 177 | /** what should the goaway contain? */ |
| 178 | grpc_status_code goaway_status; |
| 179 | gpr_slice *goaway_message; |
| 180 | /** set the callback for accepting new streams; |
Craig Tiller | 389297d | 2016-03-03 21:02:54 -0800 | [diff] [blame] | 181 | this is a permanent callback, unlike the other one-shot closures. |
| 182 | If true, the callback is set to set_accept_stream_fn, with its |
| 183 | user_data argument set to set_accept_stream_user_data */ |
Craig Tiller | d7f12e3 | 2016-03-03 10:08:31 -0800 | [diff] [blame] | 184 | bool set_accept_stream; |
| 185 | void (*set_accept_stream_fn)(grpc_exec_ctx *exec_ctx, void *user_data, |
| 186 | grpc_transport *transport, |
| 187 | const void *server_data); |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 188 | void *set_accept_stream_user_data; |
| 189 | /** add this transport to a pollset */ |
| 190 | grpc_pollset *bind_pollset; |
Craig Tiller | 1ada6ad | 2015-07-16 16:19:14 -0700 | [diff] [blame] | 191 | /** add this transport to a pollset_set */ |
| 192 | grpc_pollset_set *bind_pollset_set; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 193 | /** send a ping, call this back if not NULL */ |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 194 | grpc_closure *send_ping; |
Craig Tiller | 93023e4 | 2016-07-11 12:43:23 -0700 | [diff] [blame] | 195 | |
| 196 | /*************************************************************************** |
| 197 | * remaining fields are initialized and used at the discretion of the |
| 198 | * transport implementation */ |
| 199 | |
| 200 | grpc_transport_private_op_data transport_private; |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 201 | } grpc_transport_op; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 202 | |
| 203 | /* Returns the amount of memory required to store a grpc_stream for this |
| 204 | transport */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 205 | size_t grpc_transport_stream_size(grpc_transport *transport); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 206 | |
| 207 | /* Initialize transport data for a stream. |
| 208 | |
| 209 | Returns 0 on success, any other (transport-defined) value for failure. |
| 210 | |
| 211 | Arguments: |
| 212 | transport - the transport on which to create this stream |
| 213 | stream - a pointer to uninitialized memory to initialize |
| 214 | server_data - either NULL for a client initiated stream, or a pointer |
| 215 | supplied from the accept_stream callback function */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 216 | int grpc_transport_init_stream(grpc_exec_ctx *exec_ctx, |
| 217 | grpc_transport *transport, grpc_stream *stream, |
Craig Tiller | 9d35a1f | 2015-11-02 14:16:12 -0800 | [diff] [blame] | 218 | grpc_stream_refcount *refcount, |
| 219 | const void *server_data); |
| 220 | |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 221 | void grpc_transport_set_pops(grpc_exec_ctx *exec_ctx, grpc_transport *transport, |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 222 | grpc_stream *stream, grpc_polling_entity *pollent); |
David Garcia Quintas | 4afce7e | 2016-04-18 16:25:17 -0700 | [diff] [blame] | 223 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 224 | /* Destroy transport data for a stream. |
| 225 | |
| 226 | Requires: a recv_batch with final_state == GRPC_STREAM_CLOSED has been |
| 227 | received by the up-layer. Must not be called in the same call stack as |
| 228 | recv_frame. |
| 229 | |
| 230 | Arguments: |
| 231 | transport - the transport on which to create this stream |
| 232 | stream - the grpc_stream to destroy (memory is still owned by the |
| 233 | caller, but any child memory must be cleaned up) */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 234 | void grpc_transport_destroy_stream(grpc_exec_ctx *exec_ctx, |
| 235 | grpc_transport *transport, |
Craig Tiller | 2c8063c | 2016-03-22 22:12:15 -0700 | [diff] [blame] | 236 | grpc_stream *stream, void *and_free_memory); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 237 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 238 | void grpc_transport_stream_op_finish_with_failure(grpc_exec_ctx *exec_ctx, |
Craig Tiller | f51457b | 2016-05-03 17:06:32 -0700 | [diff] [blame] | 239 | grpc_transport_stream_op *op, |
| 240 | grpc_error *error); |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 241 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 242 | void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op, |
| 243 | grpc_status_code status); |
Craig Tiller | 45ce927 | 2015-07-31 11:22:35 -0700 | [diff] [blame] | 244 | |
Yuchen Zeng | ec066b3 | 2016-06-13 18:10:23 -0700 | [diff] [blame] | 245 | void grpc_transport_stream_op_add_cancellation_with_message( |
| 246 | grpc_transport_stream_op *op, grpc_status_code status, |
| 247 | gpr_slice *optional_message); |
| 248 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 249 | void grpc_transport_stream_op_add_close(grpc_transport_stream_op *op, |
| 250 | grpc_status_code status, |
| 251 | gpr_slice *optional_message); |
Craig Tiller | 2ea37fd | 2015-04-24 13:03:49 -0700 | [diff] [blame] | 252 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 253 | char *grpc_transport_stream_op_string(grpc_transport_stream_op *op); |
Craig Tiller | e194ff0 | 2016-08-29 15:48:41 -0700 | [diff] [blame^] | 254 | char *grpc_transport_op_string(grpc_transport_op *op); |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 255 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 256 | /* Send a batch of operations on a transport |
| 257 | |
| 258 | Takes ownership of any objects contained in ops. |
| 259 | |
| 260 | Arguments: |
| 261 | transport - the transport on which to initiate the stream |
| 262 | stream - the stream on which to send the operations. This must be |
| 263 | non-NULL and previously initialized by the same transport. |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 264 | op - a grpc_transport_stream_op specifying the op to perform */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 265 | void grpc_transport_perform_stream_op(grpc_exec_ctx *exec_ctx, |
| 266 | grpc_transport *transport, |
| 267 | grpc_stream *stream, |
| 268 | grpc_transport_stream_op *op); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 269 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 270 | void grpc_transport_perform_op(grpc_exec_ctx *exec_ctx, |
| 271 | grpc_transport *transport, |
| 272 | grpc_transport_op *op); |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 273 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 274 | /* Send a ping on a transport |
| 275 | |
Craig Tiller | 4aa71a1 | 2015-06-15 13:00:55 -0700 | [diff] [blame] | 276 | Calls cb with user data when a response is received. */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 277 | void grpc_transport_ping(grpc_transport *transport, grpc_closure *cb); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 278 | |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 279 | /* Advise peer of pending connection termination. */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 280 | void grpc_transport_goaway(grpc_transport *transport, grpc_status_code status, |
| 281 | gpr_slice debug_data); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 282 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 283 | /* Close a transport. Aborts all open streams. */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 284 | void grpc_transport_close(grpc_transport *transport); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 285 | |
| 286 | /* Destroy the transport */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 287 | void grpc_transport_destroy(grpc_exec_ctx *exec_ctx, grpc_transport *transport); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 288 | |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 289 | /* Get the transports peer */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 290 | char *grpc_transport_get_peer(grpc_exec_ctx *exec_ctx, |
| 291 | grpc_transport *transport); |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 292 | |
Craig Tiller | e0221ff | 2016-07-11 15:56:08 -0700 | [diff] [blame] | 293 | /* Allocate a grpc_transport_op, and preconfigure the on_consumed closure to |
| 294 | \a on_consumed and then delete the returned transport op */ |
| 295 | grpc_transport_op *grpc_make_transport_op(grpc_closure *on_consumed); |
Craig Tiller | dfd3a8f | 2016-08-24 09:43:45 -0700 | [diff] [blame] | 296 | /* Allocate a grpc_transport_stream_op, and preconfigure the on_consumed closure |
| 297 | to \a on_consumed and then delete the returned transport op */ |
| 298 | grpc_transport_stream_op *grpc_make_transport_stream_op( |
| 299 | grpc_closure *on_consumed); |
Craig Tiller | e0221ff | 2016-07-11 15:56:08 -0700 | [diff] [blame] | 300 | |
Mark D. Roth | 035cb3a | 2016-06-16 14:52:41 -0700 | [diff] [blame] | 301 | #ifdef __cplusplus |
| 302 | } |
| 303 | #endif |
| 304 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 305 | #endif /* GRPC_CORE_LIB_TRANSPORT_TRANSPORT_H */ |