Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [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 | |
Nicolas "Pixel" Noble | 1ff52d5 | 2015-03-01 05:24:36 +0100 | [diff] [blame] | 34 | #ifndef GRPC_GRPC_H |
| 35 | #define GRPC_GRPC_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
| 37 | #include <grpc/status.h> |
| 38 | |
| 39 | #include <stddef.h> |
David Garcia Quintas | 25d02d5 | 2015-06-04 17:40:54 -0700 | [diff] [blame] | 40 | #include <grpc/byte_buffer.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 41 | #include <grpc/support/slice.h> |
| 42 | #include <grpc/support/time.h> |
| 43 | |
| 44 | #ifdef __cplusplus |
| 45 | extern "C" { |
| 46 | #endif |
| 47 | |
Nathaniel Manista | 6d41a05 | 2015-02-16 02:12:48 +0000 | [diff] [blame] | 48 | /* Completion Queues enable notification of the completion of asynchronous |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 49 | actions. */ |
| 50 | typedef struct grpc_completion_queue grpc_completion_queue; |
| 51 | |
| 52 | /* The Channel interface allows creation of Call objects. */ |
| 53 | typedef struct grpc_channel grpc_channel; |
| 54 | |
| 55 | /* A server listens to some port and responds to request calls */ |
| 56 | typedef struct grpc_server grpc_server; |
| 57 | |
| 58 | /* A Call represents an RPC. When created, it is in a configuration state |
| 59 | allowing properties to be set until it is invoked. After invoke, the Call |
| 60 | can have messages written to it and read from it. */ |
| 61 | typedef struct grpc_call grpc_call; |
| 62 | |
| 63 | /* Type specifier for grpc_arg */ |
| 64 | typedef enum { |
| 65 | GRPC_ARG_STRING, |
| 66 | GRPC_ARG_INTEGER, |
| 67 | GRPC_ARG_POINTER |
| 68 | } grpc_arg_type; |
| 69 | |
| 70 | /* A single argument... each argument has a key and a value |
| 71 | |
| 72 | A note on naming keys: |
| 73 | Keys are namespaced into groups, usually grouped by library, and are |
| 74 | keys for module XYZ are named XYZ.key1, XYZ.key2, etc. Module names must |
| 75 | be restricted to the regex [A-Za-z][_A-Za-z0-9]{,15}. |
| 76 | Key names must be restricted to the regex [A-Za-z][_A-Za-z0-9]{,47}. |
| 77 | |
| 78 | GRPC core library keys are prefixed by grpc. |
| 79 | |
| 80 | Library authors are strongly encouraged to #define symbolic constants for |
| 81 | their keys so that it's possible to change them in the future. */ |
| 82 | typedef struct { |
| 83 | grpc_arg_type type; |
| 84 | char *key; |
| 85 | union { |
| 86 | char *string; |
| 87 | int integer; |
| 88 | struct { |
| 89 | void *p; |
| 90 | void *(*copy)(void *p); |
| 91 | void (*destroy)(void *p); |
| 92 | } pointer; |
| 93 | } value; |
| 94 | } grpc_arg; |
| 95 | |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 96 | /** An array of arguments that can be passed around. |
David Garcia Quintas | 02c677c | 2015-06-02 14:40:07 -0700 | [diff] [blame] | 97 | |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 98 | Used to set optional channel-level configuration. |
| 99 | These configuration options are modelled as key-value pairs as defined |
| 100 | by grpc_arg; keys are strings to allow easy backwards-compatible extension |
| 101 | by arbitrary parties. |
Masood Malekghassemi | 7128a90 | 2015-06-17 13:17:58 -0700 | [diff] [blame] | 102 | All evaluation is performed at channel creation time (i.e. the values in |
| 103 | this structure need only live through the creation invocation). */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 104 | typedef struct { |
| 105 | size_t num_args; |
| 106 | grpc_arg *args; |
| 107 | } grpc_channel_args; |
| 108 | |
| 109 | /* Channel argument keys: */ |
| 110 | /* Enable census for tracing and stats collection */ |
| 111 | #define GRPC_ARG_ENABLE_CENSUS "grpc.census" |
| 112 | /* Maximum number of concurrent incoming streams to allow on a http2 |
| 113 | connection */ |
| 114 | #define GRPC_ARG_MAX_CONCURRENT_STREAMS "grpc.max_concurrent_streams" |
| 115 | /* Maximum message length that the channel can receive */ |
| 116 | #define GRPC_ARG_MAX_MESSAGE_LENGTH "grpc.max_message_length" |
Craig Tiller | 8802558 | 2015-05-04 09:41:10 -0700 | [diff] [blame] | 117 | /* Initial sequence number for http2 transports */ |
| 118 | #define GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER \ |
| 119 | "grpc.http2.initial_sequence_number" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 120 | |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 121 | /** Connectivity state of a channel. */ |
| 122 | typedef enum { |
Craig Tiller | 11bf14e | 2015-06-29 16:35:41 -0700 | [diff] [blame] | 123 | /** channel is idle */ |
| 124 | GRPC_CHANNEL_IDLE, |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 125 | /** channel is connecting */ |
| 126 | GRPC_CHANNEL_CONNECTING, |
| 127 | /** channel is ready for work */ |
| 128 | GRPC_CHANNEL_READY, |
| 129 | /** channel has seen a failure but expects to recover */ |
| 130 | GRPC_CHANNEL_TRANSIENT_FAILURE, |
Craig Tiller | 3f47542 | 2015-06-25 10:43:05 -0700 | [diff] [blame] | 131 | /** channel has seen a failure that it cannot recover from */ |
| 132 | GRPC_CHANNEL_FATAL_FAILURE |
| 133 | } grpc_connectivity_state; |
| 134 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 135 | /* Result of a grpc call. If the caller satisfies the prerequisites of a |
| 136 | particular operation, the grpc_call_error returned will be GRPC_CALL_OK. |
| 137 | Receiving any other value listed here is an indication of a bug in the |
| 138 | caller. */ |
| 139 | typedef enum grpc_call_error { |
| 140 | /* everything went ok */ |
| 141 | GRPC_CALL_OK = 0, |
| 142 | /* something failed, we don't know what */ |
| 143 | GRPC_CALL_ERROR, |
| 144 | /* this method is not available on the server */ |
| 145 | GRPC_CALL_ERROR_NOT_ON_SERVER, |
| 146 | /* this method is not available on the client */ |
| 147 | GRPC_CALL_ERROR_NOT_ON_CLIENT, |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 148 | /* this method must be called before server_accept */ |
| 149 | GRPC_CALL_ERROR_ALREADY_ACCEPTED, |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 150 | /* this method must be called before invoke */ |
| 151 | GRPC_CALL_ERROR_ALREADY_INVOKED, |
| 152 | /* this method must be called after invoke */ |
| 153 | GRPC_CALL_ERROR_NOT_INVOKED, |
| 154 | /* this call is already finished |
| 155 | (writes_done or write_status has already been called) */ |
| 156 | GRPC_CALL_ERROR_ALREADY_FINISHED, |
| 157 | /* there is already an outstanding read/write operation on the call */ |
| 158 | GRPC_CALL_ERROR_TOO_MANY_OPERATIONS, |
| 159 | /* the flags value was illegal for this call */ |
Craig Tiller | b96d001 | 2015-05-06 15:33:23 -0700 | [diff] [blame] | 160 | GRPC_CALL_ERROR_INVALID_FLAGS, |
| 161 | /* invalid metadata was passed to this call */ |
Craig Tiller | b56975c | 2015-06-15 10:11:16 -0700 | [diff] [blame] | 162 | GRPC_CALL_ERROR_INVALID_METADATA, |
| 163 | /* completion queue for notification has not been registered with the server |
| 164 | */ |
| 165 | GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 166 | } grpc_call_error; |
| 167 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 168 | /* Write Flags: */ |
| 169 | /* Hint that the write may be buffered and need not go out on the wire |
| 170 | immediately. GRPC is free to buffer the message until the next non-buffered |
| 171 | write, or until writes_done, but it need not buffer completely or at all. */ |
| 172 | #define GRPC_WRITE_BUFFER_HINT (0x00000001u) |
| 173 | /* Force compression to be disabled for a particular write |
| 174 | (start_write/add_metadata). Illegal on invoke/accept. */ |
| 175 | #define GRPC_WRITE_NO_COMPRESS (0x00000002u) |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 176 | /* Mask of all valid flags. */ |
| 177 | #define GRPC_WRITE_USED_MASK (GRPC_WRITE_BUFFER_HINT | GRPC_WRITE_NO_COMPRESS) |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 178 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 179 | /* A single metadata element */ |
| 180 | typedef struct grpc_metadata { |
Craig Tiller | 4f97273 | 2015-02-05 12:40:20 -0800 | [diff] [blame] | 181 | const char *key; |
| 182 | const char *value; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 183 | size_t value_length; |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 184 | |
| 185 | /* The following fields are reserved for grpc internal use. |
| 186 | There is no need to initialize them, and they will be set to garbage during |
| 187 | calls to grpc. */ |
| 188 | struct { |
Craig Tiller | 9c9d4e0 | 2015-04-20 09:03:29 -0700 | [diff] [blame] | 189 | void *obfuscated[3]; |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 190 | } internal_data; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 191 | } grpc_metadata; |
| 192 | |
Craig Tiller | 73b66ef | 2015-05-18 20:46:47 -0700 | [diff] [blame] | 193 | /** The type of completion (for grpc_event) */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 194 | typedef enum grpc_completion_type { |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 195 | /** Shutting down */ |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 196 | GRPC_QUEUE_SHUTDOWN, |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 197 | /** No event before timeout */ |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 198 | GRPC_QUEUE_TIMEOUT, |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 199 | /** Operation completion */ |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 200 | GRPC_OP_COMPLETE |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 201 | } grpc_completion_type; |
| 202 | |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 203 | /** The result of an operation. |
| 204 | |
| 205 | Returned by a completion queue when the operation started with tag. */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 206 | typedef struct grpc_event { |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 207 | /** The type of the completion. */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 208 | grpc_completion_type type; |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 209 | /** non-zero if the operation was successful, 0 upon failure. |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 210 | Only GRPC_OP_COMPLETE can succeed or fail. */ |
Craig Tiller | 64be9f7 | 2015-05-04 14:53:51 -0700 | [diff] [blame] | 211 | int success; |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 212 | /** The tag passed to grpc_call_start_batch etc to start this operation. |
| 213 | Only GRPC_OP_COMPLETE has a tag. */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 214 | void *tag; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 215 | } grpc_event; |
| 216 | |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 217 | typedef struct { |
| 218 | size_t count; |
| 219 | size_t capacity; |
| 220 | grpc_metadata *metadata; |
| 221 | } grpc_metadata_array; |
| 222 | |
Craig Tiller | ea61b07 | 2015-02-03 19:19:27 -0800 | [diff] [blame] | 223 | void grpc_metadata_array_init(grpc_metadata_array *array); |
| 224 | void grpc_metadata_array_destroy(grpc_metadata_array *array); |
| 225 | |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 226 | typedef struct { |
Craig Tiller | ea61b07 | 2015-02-03 19:19:27 -0800 | [diff] [blame] | 227 | char *method; |
Craig Tiller | 034929c | 2015-02-02 16:56:15 -0800 | [diff] [blame] | 228 | size_t method_capacity; |
Craig Tiller | ea61b07 | 2015-02-03 19:19:27 -0800 | [diff] [blame] | 229 | char *host; |
Craig Tiller | 034929c | 2015-02-02 16:56:15 -0800 | [diff] [blame] | 230 | size_t host_capacity; |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 231 | gpr_timespec deadline; |
| 232 | } grpc_call_details; |
| 233 | |
Craig Tiller | ea61b07 | 2015-02-03 19:19:27 -0800 | [diff] [blame] | 234 | void grpc_call_details_init(grpc_call_details *details); |
| 235 | void grpc_call_details_destroy(grpc_call_details *details); |
| 236 | |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 237 | typedef enum { |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 238 | /* Send initial metadata: one and only one instance MUST be sent for each |
| 239 | call, |
Craig Tiller | b7800c1 | 2015-02-04 18:25:38 -0800 | [diff] [blame] | 240 | unless the call was cancelled - in which case this can be skipped */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 241 | GRPC_OP_SEND_INITIAL_METADATA = 0, |
Craig Tiller | b7800c1 | 2015-02-04 18:25:38 -0800 | [diff] [blame] | 242 | /* Send a message: 0 or more of these operations can occur for each call */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 243 | GRPC_OP_SEND_MESSAGE, |
Eric Dobson | 255971d | 2015-06-14 16:04:15 -0700 | [diff] [blame] | 244 | /* Send a close from the client: one and only one instance MUST be sent from |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 245 | the client, |
Craig Tiller | b7800c1 | 2015-02-04 18:25:38 -0800 | [diff] [blame] | 246 | unless the call was cancelled - in which case this can be skipped */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 247 | GRPC_OP_SEND_CLOSE_FROM_CLIENT, |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 248 | /* Send status from the server: one and only one instance MUST be sent from |
| 249 | the server |
Craig Tiller | b7800c1 | 2015-02-04 18:25:38 -0800 | [diff] [blame] | 250 | unless the call was cancelled - in which case this can be skipped */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 251 | GRPC_OP_SEND_STATUS_FROM_SERVER, |
Craig Tiller | b7800c1 | 2015-02-04 18:25:38 -0800 | [diff] [blame] | 252 | /* Receive initial metadata: one and only one MUST be made on the client, must |
| 253 | not be made on the server */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 254 | GRPC_OP_RECV_INITIAL_METADATA, |
Craig Tiller | b7800c1 | 2015-02-04 18:25:38 -0800 | [diff] [blame] | 255 | /* Receive a message: 0 or more of these operations can occur for each call */ |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 256 | GRPC_OP_RECV_MESSAGE, |
Craig Tiller | 69eed29 | 2015-05-19 10:43:05 -0700 | [diff] [blame] | 257 | /* Receive status on the client: one and only one must be made on the client. |
| 258 | This operation always succeeds, meaning ops paired with this operation |
| 259 | will also appear to succeed, even though they may not have. In that case |
| 260 | the status will indicate some failure. |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 261 | */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 262 | GRPC_OP_RECV_STATUS_ON_CLIENT, |
Eric Dobson | 255971d | 2015-06-14 16:04:15 -0700 | [diff] [blame] | 263 | /* Receive close on the server: one and only one must be made on the server |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 264 | */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 265 | GRPC_OP_RECV_CLOSE_ON_SERVER |
| 266 | } grpc_op_type; |
| 267 | |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 268 | /* Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT |
| 269 | which has |
Craig Tiller | b7800c1 | 2015-02-04 18:25:38 -0800 | [diff] [blame] | 270 | no arguments) */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 271 | typedef struct grpc_op { |
| 272 | grpc_op_type op; |
Craig Tiller | 9a57633 | 2015-06-17 10:21:49 -0700 | [diff] [blame] | 273 | gpr_uint32 flags; /**< Write flags bitset for grpc_begin_messages */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 274 | union { |
| 275 | struct { |
| 276 | size_t count; |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 277 | grpc_metadata *metadata; |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 278 | } send_initial_metadata; |
| 279 | grpc_byte_buffer *send_message; |
| 280 | struct { |
| 281 | size_t trailing_metadata_count; |
| 282 | grpc_metadata *trailing_metadata; |
| 283 | grpc_status_code status; |
| 284 | const char *status_details; |
| 285 | } send_status_from_server; |
Craig Tiller | 4f97273 | 2015-02-05 12:40:20 -0800 | [diff] [blame] | 286 | /* ownership of the array is with the caller, but ownership of the elements |
Craig Tiller | c56b2cb | 2015-02-05 16:35:38 -0800 | [diff] [blame] | 287 | stays with the call object (ie key, value members are owned by the call |
| 288 | object, recv_initial_metadata->array is owned by the caller). |
| 289 | After the operation completes, call grpc_metadata_array_destroy on this |
| 290 | value, or reuse it in a future op. */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 291 | grpc_metadata_array *recv_initial_metadata; |
Masood Malekghassemi | 7128a90 | 2015-06-17 13:17:58 -0700 | [diff] [blame] | 292 | /* ownership of the byte buffer is moved to the caller; the caller must call |
| 293 | grpc_byte_buffer_destroy on this value, or reuse it in a future op. */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 294 | grpc_byte_buffer **recv_message; |
| 295 | struct { |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 296 | /* ownership of the array is with the caller, but ownership of the |
| 297 | elements |
Craig Tiller | c56b2cb | 2015-02-05 16:35:38 -0800 | [diff] [blame] | 298 | stays with the call object (ie key, value members are owned by the call |
| 299 | object, trailing_metadata->array is owned by the caller). |
| 300 | After the operation completes, call grpc_metadata_array_destroy on this |
| 301 | value, or reuse it in a future op. */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 302 | grpc_metadata_array *trailing_metadata; |
| 303 | grpc_status_code *status; |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 304 | /* status_details is a buffer owned by the application before the op |
| 305 | completes |
| 306 | and after the op has completed. During the operation status_details may |
| 307 | be |
| 308 | reallocated to a size larger than *status_details_capacity, in which |
| 309 | case |
Craig Tiller | c56b2cb | 2015-02-05 16:35:38 -0800 | [diff] [blame] | 310 | *status_details_capacity will be updated with the new array capacity. |
| 311 | |
| 312 | Pre-allocating space: |
| 313 | size_t my_capacity = 8; |
| 314 | char *my_details = gpr_malloc(my_capacity); |
| 315 | x.status_details = &my_details; |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 316 | x.status_details_capacity = &my_capacity; |
Craig Tiller | c56b2cb | 2015-02-05 16:35:38 -0800 | [diff] [blame] | 317 | |
| 318 | Not pre-allocating space: |
| 319 | size_t my_capacity = 0; |
| 320 | char *my_details = NULL; |
| 321 | x.status_details = &my_details; |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 322 | x.status_details_capacity = &my_capacity; |
Craig Tiller | c56b2cb | 2015-02-05 16:35:38 -0800 | [diff] [blame] | 323 | |
| 324 | After the call: |
| 325 | gpr_free(my_details); */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 326 | char **status_details; |
| 327 | size_t *status_details_capacity; |
| 328 | } recv_status_on_client; |
| 329 | struct { |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 330 | /* out argument, set to 1 if the call failed in any way (seen as a |
| 331 | cancellation |
Craig Tiller | 0a5bcbc | 2015-02-09 21:39:04 -0800 | [diff] [blame] | 332 | on the server), or 0 if the call succeeded */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 333 | int *cancelled; |
| 334 | } recv_close_on_server; |
| 335 | } data; |
| 336 | } grpc_op; |
| 337 | |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 338 | /** Initialize the grpc library. |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 339 | |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 340 | It is not safe to call any other grpc functions before calling this. |
| 341 | (To avoid overhead, little checking is done, and some things may work. We |
| 342 | do not warrant that they will continue to do so in future revisions of this |
| 343 | library). */ |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 344 | void grpc_init(void); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 345 | |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 346 | /** Shut down the grpc library. |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 347 | |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 348 | No memory is used by grpc after this call returns, nor are any instructions |
| 349 | executing within the grpc library. |
| 350 | Prior to calling, all application owned grpc objects must have been |
| 351 | destroyed. */ |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 352 | void grpc_shutdown(void); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 353 | |
Craig Tiller | 2e622bc | 2015-07-10 07:46:03 -0700 | [diff] [blame] | 354 | /** Return a string representing the current version of grpc */ |
| 355 | const char *grpc_version_string(void); |
| 356 | |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 357 | /** Create a completion queue */ |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 358 | grpc_completion_queue *grpc_completion_queue_create(void); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 359 | |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 360 | /** Blocks until an event is available, the completion queue is being shut down, |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 361 | or deadline is reached. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 362 | |
vjpai | 1854d77 | 2015-06-08 01:12:29 -0700 | [diff] [blame] | 363 | Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout, |
| 364 | otherwise a grpc_event describing the event that occurred. |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 365 | |
| 366 | Callers must not call grpc_completion_queue_next and |
| 367 | grpc_completion_queue_pluck simultaneously on the same completion queue. */ |
Craig Tiller | 64be9f7 | 2015-05-04 14:53:51 -0700 | [diff] [blame] | 368 | grpc_event grpc_completion_queue_next(grpc_completion_queue *cq, |
| 369 | gpr_timespec deadline); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 370 | |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 371 | /** Blocks until an event with tag 'tag' is available, the completion queue is |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 372 | being shutdown or deadline is reached. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 373 | |
vjpai | 1854d77 | 2015-06-08 01:12:29 -0700 | [diff] [blame] | 374 | Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout, |
| 375 | otherwise a grpc_event describing the event that occurred. |
Craig Tiller | e793ba1 | 2015-05-18 09:37:22 -0700 | [diff] [blame] | 376 | |
| 377 | Callers must not call grpc_completion_queue_next and |
| 378 | grpc_completion_queue_pluck simultaneously on the same completion queue. */ |
Craig Tiller | 64be9f7 | 2015-05-04 14:53:51 -0700 | [diff] [blame] | 379 | grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq, void *tag, |
| 380 | gpr_timespec deadline); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 381 | |
| 382 | /* Begin destruction of a completion queue. Once all possible events are |
Craig Tiller | 8ac56c9 | 2015-02-17 22:51:36 -0800 | [diff] [blame] | 383 | drained then grpc_completion_queue_next will start to produce |
Craig Tiller | b20111c | 2015-04-10 23:27:11 +0000 | [diff] [blame] | 384 | GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call |
| 385 | grpc_completion_queue_destroy. |
| 386 | |
Craig Tiller | 8ac56c9 | 2015-02-17 22:51:36 -0800 | [diff] [blame] | 387 | After calling this function applications should ensure that no |
| 388 | NEW work is added to be published on this completion queue. */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 389 | void grpc_completion_queue_shutdown(grpc_completion_queue *cq); |
| 390 | |
| 391 | /* Destroy a completion queue. The caller must ensure that the queue is |
| 392 | drained and no threads are executing grpc_completion_queue_next */ |
| 393 | void grpc_completion_queue_destroy(grpc_completion_queue *cq); |
| 394 | |
Jan Tattermusch | 4bf27c5 | 2015-06-22 14:24:59 -0700 | [diff] [blame] | 395 | /* Create a call given a grpc_channel, in order to call 'method'. All |
| 396 | completions are sent to 'completion_queue'. 'method' and 'host' need only |
| 397 | live through the invocation of this function. */ |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 398 | grpc_call *grpc_channel_create_call(grpc_channel *channel, |
| 399 | grpc_completion_queue *completion_queue, |
| 400 | const char *method, const char *host, |
| 401 | gpr_timespec deadline); |
Craig Tiller | 034929c | 2015-02-02 16:56:15 -0800 | [diff] [blame] | 402 | |
Craig Tiller | 0845337 | 2015-04-10 16:05:38 -0700 | [diff] [blame] | 403 | /* Pre-register a method/host pair on a channel. */ |
Craig Tiller | b20111c | 2015-04-10 23:27:11 +0000 | [diff] [blame] | 404 | void *grpc_channel_register_call(grpc_channel *channel, const char *method, |
Craig Tiller | 0845337 | 2015-04-10 16:05:38 -0700 | [diff] [blame] | 405 | const char *host); |
| 406 | |
| 407 | /* Create a call given a handle returned from grpc_channel_register_call */ |
Craig Tiller | b20111c | 2015-04-10 23:27:11 +0000 | [diff] [blame] | 408 | grpc_call *grpc_channel_create_registered_call( |
| 409 | grpc_channel *channel, grpc_completion_queue *completion_queue, |
| 410 | void *registered_call_handle, gpr_timespec deadline); |
Craig Tiller | 0845337 | 2015-04-10 16:05:38 -0700 | [diff] [blame] | 411 | |
Craig Tiller | 034929c | 2015-02-02 16:56:15 -0800 | [diff] [blame] | 412 | /* Start a batch of operations defined in the array ops; when complete, post a |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 413 | completion of type 'tag' to the completion queue bound to the call. |
Craig Tiller | b7800c1 | 2015-02-04 18:25:38 -0800 | [diff] [blame] | 414 | The order of ops specified in the batch has no significance. |
| 415 | Only one operation of each type can be active at once in any given |
Masood Malekghassemi | b70b709 | 2015-06-26 16:25:11 -0700 | [diff] [blame] | 416 | batch. You must call grpc_completion_queue_next or |
| 417 | grpc_completion_queue_pluck on the completion queue associated with 'call' |
| 418 | for work to be performed. |
Jan Tattermusch | aadc13a | 2015-06-22 12:25:55 -0700 | [diff] [blame] | 419 | THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment |
| 420 | needs to be synchronized. As an optimization, you may synchronize batches |
| 421 | containing just send operations independently from batches containing just |
| 422 | receive operations. */ |
Craig Tiller | fef7669 | 2015-02-02 16:44:26 -0800 | [diff] [blame] | 423 | grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops, |
| 424 | size_t nops, void *tag); |
| 425 | |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame^] | 426 | /* Returns a newly allocated string representing the endpoint to which this |
| 427 | call is communicating with. The string is in the uri format accepted by |
| 428 | grpc_channel_create. |
| 429 | The returned string should be disposed of with gpr_free(). */ |
| 430 | char *grpc_call_get_peer(grpc_call *call); |
| 431 | |
Craig Tiller | 29f2b21 | 2015-02-17 17:01:24 -0800 | [diff] [blame] | 432 | /* Create a client channel to 'target'. Additional channel level configuration |
| 433 | MAY be provided by grpc_channel_args, though the expectation is that most |
Masood Malekghassemi | 7128a90 | 2015-06-17 13:17:58 -0700 | [diff] [blame] | 434 | clients will want to simply pass NULL. See grpc_channel_args definition for |
| 435 | more on this. The data in 'args' need only live through the invocation of |
| 436 | this function. */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 437 | grpc_channel *grpc_channel_create(const char *target, |
| 438 | const grpc_channel_args *args); |
| 439 | |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame^] | 440 | /* Return a newly allocated string representing the target a channel was |
| 441 | created for. */ |
| 442 | char *grpc_channel_get_target(grpc_channel *channel); |
| 443 | |
Craig Tiller | 42bc87c | 2015-02-23 08:50:19 -0800 | [diff] [blame] | 444 | /* Create a lame client: this client fails every operation attempted on it. */ |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame^] | 445 | grpc_channel *grpc_lame_client_channel_create(const char *target); |
Craig Tiller | 42bc87c | 2015-02-23 08:50:19 -0800 | [diff] [blame] | 446 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 447 | /* Close and destroy a grpc channel */ |
| 448 | void grpc_channel_destroy(grpc_channel *channel); |
| 449 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 450 | /* Error handling for grpc_call |
| 451 | Most grpc_call functions return a grpc_error. If the error is not GRPC_OK |
| 452 | then the operation failed due to some unsatisfied precondition. |
| 453 | If a grpc_call fails, it's guaranteed that no change to the call state |
| 454 | has been made. */ |
| 455 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 456 | /* Called by clients to cancel an RPC on the server. |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 457 | Can be called multiple times, from any thread. |
Jan Tattermusch | c878e2a | 2015-06-12 13:52:28 -0700 | [diff] [blame] | 458 | THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status |
| 459 | are thread-safe, and can be called at any point before grpc_call_destroy |
| 460 | is called.*/ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 461 | grpc_call_error grpc_call_cancel(grpc_call *call); |
| 462 | |
Craig Tiller | d248c24 | 2015-01-14 11:49:12 -0800 | [diff] [blame] | 463 | /* Called by clients to cancel an RPC on the server. |
Craig Tiller | 6046dc3 | 2015-01-14 12:55:45 -0800 | [diff] [blame] | 464 | Can be called multiple times, from any thread. |
Craig Tiller | d248c24 | 2015-01-14 11:49:12 -0800 | [diff] [blame] | 465 | If a status has not been received for the call, set it to the status code |
Craig Tiller | 6046dc3 | 2015-01-14 12:55:45 -0800 | [diff] [blame] | 466 | and description passed in. |
Craig Tiller | d248c24 | 2015-01-14 11:49:12 -0800 | [diff] [blame] | 467 | Importantly, this function does not send status nor description to the |
| 468 | remote endpoint. */ |
Craig Tiller | 6046dc3 | 2015-01-14 12:55:45 -0800 | [diff] [blame] | 469 | grpc_call_error grpc_call_cancel_with_status(grpc_call *call, |
| 470 | grpc_status_code status, |
| 471 | const char *description); |
Craig Tiller | d248c24 | 2015-01-14 11:49:12 -0800 | [diff] [blame] | 472 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 473 | /* Destroy a call. |
Jan Tattermusch | c878e2a | 2015-06-12 13:52:28 -0700 | [diff] [blame] | 474 | THREAD SAFETY: grpc_call_destroy is thread-compatible */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 475 | void grpc_call_destroy(grpc_call *call); |
| 476 | |
Masood Malekghassemi | aeb1a9f | 2015-06-18 16:23:24 -0700 | [diff] [blame] | 477 | /* Request notification of a new call. 'cq_for_notification' must |
| 478 | have been registered to the server via grpc_server_register_completion_queue. |
| 479 | */ |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 480 | grpc_call_error grpc_server_request_call( |
Craig Tiller | ea61b07 | 2015-02-03 19:19:27 -0800 | [diff] [blame] | 481 | grpc_server *server, grpc_call **call, grpc_call_details *details, |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 482 | grpc_metadata_array *request_metadata, |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 483 | grpc_completion_queue *cq_bound_to_call, |
| 484 | grpc_completion_queue *cq_for_notification, void *tag_new); |
Craig Tiller | 034929c | 2015-02-02 16:56:15 -0800 | [diff] [blame] | 485 | |
Craig Tiller | fada7d4 | 2015-02-11 23:03:55 -0800 | [diff] [blame] | 486 | /* Registers a method in the server. |
| 487 | Methods to this (host, method) pair will not be reported by |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 488 | grpc_server_request_call, but instead be reported by |
Craig Tiller | fada7d4 | 2015-02-11 23:03:55 -0800 | [diff] [blame] | 489 | grpc_server_request_registered_call when passed the appropriate |
| 490 | registered_method (as returned by this function). |
| 491 | Must be called before grpc_server_start. |
| 492 | Returns NULL on failure. */ |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 493 | void *grpc_server_register_method(grpc_server *server, const char *method, |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 494 | const char *host); |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 495 | |
Masood Malekghassemi | aeb1a9f | 2015-06-18 16:23:24 -0700 | [diff] [blame] | 496 | /* Request notification of a new pre-registered call. 'cq_for_notification' must |
| 497 | have been registered to the server via grpc_server_register_completion_queue. |
| 498 | */ |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 499 | grpc_call_error grpc_server_request_registered_call( |
| 500 | grpc_server *server, void *registered_method, grpc_call **call, |
| 501 | gpr_timespec *deadline, grpc_metadata_array *request_metadata, |
| 502 | grpc_byte_buffer **optional_payload, |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 503 | grpc_completion_queue *cq_bound_to_call, |
| 504 | grpc_completion_queue *cq_for_notification, void *tag_new); |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 505 | |
Craig Tiller | 29f2b21 | 2015-02-17 17:01:24 -0800 | [diff] [blame] | 506 | /* Create a server. Additional configuration for each incoming channel can |
Craig Tiller | e7163ab | 2015-02-17 20:46:08 -0800 | [diff] [blame] | 507 | be specified with args. If no additional configuration is needed, args can |
Masood Malekghassemi | 7128a90 | 2015-06-17 13:17:58 -0700 | [diff] [blame] | 508 | be NULL. See grpc_channel_args for more. The data in 'args' need only live |
| 509 | through the invocation of this function. */ |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 510 | grpc_server *grpc_server_create(const grpc_channel_args *args); |
| 511 | |
Masood Malekghassemi | aeb1a9f | 2015-06-18 16:23:24 -0700 | [diff] [blame] | 512 | /* Register a completion queue with the server. Must be done for any |
| 513 | notification completion queue that is passed to grpc_server_request_*_call |
| 514 | and to grpc_server_shutdown_and_notify. Must be performed prior to |
| 515 | grpc_server_start. */ |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 516 | void grpc_server_register_completion_queue(grpc_server *server, |
| 517 | grpc_completion_queue *cq); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 518 | |
Craig Tiller | d251ab9 | 2015-02-17 17:22:14 -0800 | [diff] [blame] | 519 | /* Add a HTTP2 over plaintext over tcp listener. |
ctiller | 570d1f4 | 2015-01-12 16:29:52 -0800 | [diff] [blame] | 520 | Returns bound port number on success, 0 on failure. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 521 | REQUIRES: server not started */ |
| 522 | int grpc_server_add_http2_port(grpc_server *server, const char *addr); |
| 523 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 524 | /* Start a server - tells all listeners to start listening */ |
| 525 | void grpc_server_start(grpc_server *server); |
| 526 | |
ctiller | 9a58df0 | 2014-12-11 16:26:49 -0800 | [diff] [blame] | 527 | /* Begin shutting down a server. |
| 528 | After completion, no new calls or connections will be admitted. |
Craig Tiller | aea2fc0 | 2015-02-17 16:54:53 -0800 | [diff] [blame] | 529 | Existing calls will be allowed to complete. |
Craig Tiller | ee945e8 | 2015-05-26 16:15:34 -0700 | [diff] [blame] | 530 | Send a GRPC_OP_COMPLETE event when there are no more calls being serviced. |
Craig Tiller | aea2fc0 | 2015-02-17 16:54:53 -0800 | [diff] [blame] | 531 | Shutdown is idempotent, and all tags will be notified at once if multiple |
Masood Malekghassemi | aeb1a9f | 2015-06-18 16:23:24 -0700 | [diff] [blame] | 532 | grpc_server_shutdown_and_notify calls are made. 'cq' must have been |
| 533 | registered to this server via grpc_server_register_completion_queue. */ |
Craig Tiller | bce999f | 2015-05-27 09:55:51 -0700 | [diff] [blame] | 534 | void grpc_server_shutdown_and_notify(grpc_server *server, |
| 535 | grpc_completion_queue *cq, void *tag); |
Craig Tiller | 4ffdcd5 | 2015-01-16 11:34:55 -0800 | [diff] [blame] | 536 | |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 537 | /* Cancel all in-progress calls. |
Craig Tiller | ee945e8 | 2015-05-26 16:15:34 -0700 | [diff] [blame] | 538 | Only usable after shutdown. */ |
| 539 | void grpc_server_cancel_all_calls(grpc_server *server); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 540 | |
| 541 | /* Destroy a server. |
Craig Tiller | 6ec402b | 2015-05-28 08:36:41 -0700 | [diff] [blame] | 542 | Shutdown must have completed beforehand (i.e. all tags generated by |
| 543 | grpc_server_shutdown_and_notify must have been received, and at least |
| 544 | one call to grpc_server_shutdown_and_notify must have been made). */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 545 | void grpc_server_destroy(grpc_server *server); |
| 546 | |
Craig Tiller | af7abf9 | 2015-06-03 17:18:58 -0700 | [diff] [blame] | 547 | /** Enable or disable a tracer. |
| 548 | |
| 549 | Tracers (usually controlled by the environment variable GRPC_TRACE) |
| 550 | allow printf-style debugging on GRPC internals, and are useful for |
Craig Tiller | 9a57633 | 2015-06-17 10:21:49 -0700 | [diff] [blame] | 551 | tracking down problems in the field. |
Craig Tiller | af7abf9 | 2015-06-03 17:18:58 -0700 | [diff] [blame] | 552 | |
Craig Tiller | 9a57633 | 2015-06-17 10:21:49 -0700 | [diff] [blame] | 553 | Use of this function is not strictly thread-safe, but the |
Craig Tiller | af7abf9 | 2015-06-03 17:18:58 -0700 | [diff] [blame] | 554 | thread-safety issues raised by it should not be of concern. */ |
| 555 | int grpc_tracer_set_enabled(const char *name, int enabled); |
| 556 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 557 | #ifdef __cplusplus |
| 558 | } |
| 559 | #endif |
| 560 | |
Craig Tiller | b20111c | 2015-04-10 23:27:11 +0000 | [diff] [blame] | 561 | #endif /* GRPC_GRPC_H */ |