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