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