blob: 4ccb5a4dd593e886bd4e4c402dbf70c6917a1919 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
3 * Copyright 2014, Google Inc.
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
34#ifndef __GRPC_GRPC_H__
35#define __GRPC_GRPC_H__
36
37#include <grpc/status.h>
38
39#include <stddef.h>
40#include <grpc/support/slice.h>
41#include <grpc/support/time.h>
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/* Completion Channels enable notification of the completion of asynchronous
48 actions. */
49typedef struct grpc_completion_queue grpc_completion_queue;
50
51/* The Channel interface allows creation of Call objects. */
52typedef struct grpc_channel grpc_channel;
53
54/* A server listens to some port and responds to request calls */
55typedef struct grpc_server grpc_server;
56
57/* A Call represents an RPC. When created, it is in a configuration state
58 allowing properties to be set until it is invoked. After invoke, the Call
59 can have messages written to it and read from it. */
60typedef struct grpc_call grpc_call;
61
62/* Type specifier for grpc_arg */
63typedef enum {
64 GRPC_ARG_STRING,
65 GRPC_ARG_INTEGER,
66 GRPC_ARG_POINTER
67} grpc_arg_type;
68
69/* A single argument... each argument has a key and a value
70
71 A note on naming keys:
72 Keys are namespaced into groups, usually grouped by library, and are
73 keys for module XYZ are named XYZ.key1, XYZ.key2, etc. Module names must
74 be restricted to the regex [A-Za-z][_A-Za-z0-9]{,15}.
75 Key names must be restricted to the regex [A-Za-z][_A-Za-z0-9]{,47}.
76
77 GRPC core library keys are prefixed by grpc.
78
79 Library authors are strongly encouraged to #define symbolic constants for
80 their keys so that it's possible to change them in the future. */
81typedef struct {
82 grpc_arg_type type;
83 char *key;
84 union {
85 char *string;
86 int integer;
87 struct {
88 void *p;
89 void *(*copy)(void *p);
90 void (*destroy)(void *p);
91 } pointer;
92 } value;
93} grpc_arg;
94
95/* An array of arguments that can be passed around */
96typedef struct {
97 size_t num_args;
98 grpc_arg *args;
99} grpc_channel_args;
100
101/* Channel argument keys: */
102/* Enable census for tracing and stats collection */
103#define GRPC_ARG_ENABLE_CENSUS "grpc.census"
104/* Maximum number of concurrent incoming streams to allow on a http2
105 connection */
106#define GRPC_ARG_MAX_CONCURRENT_STREAMS "grpc.max_concurrent_streams"
107/* Maximum message length that the channel can receive */
108#define GRPC_ARG_MAX_MESSAGE_LENGTH "grpc.max_message_length"
109
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800110/* Result of a grpc call. If the caller satisfies the prerequisites of a
111 particular operation, the grpc_call_error returned will be GRPC_CALL_OK.
112 Receiving any other value listed here is an indication of a bug in the
113 caller. */
114typedef enum grpc_call_error {
115 /* everything went ok */
116 GRPC_CALL_OK = 0,
117 /* something failed, we don't know what */
118 GRPC_CALL_ERROR,
119 /* this method is not available on the server */
120 GRPC_CALL_ERROR_NOT_ON_SERVER,
121 /* this method is not available on the client */
122 GRPC_CALL_ERROR_NOT_ON_CLIENT,
nnoble0c475f02014-12-05 15:37:39 -0800123 /* this method must be called before server_accept */
124 GRPC_CALL_ERROR_ALREADY_ACCEPTED,
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800125 /* this method must be called before invoke */
126 GRPC_CALL_ERROR_ALREADY_INVOKED,
127 /* this method must be called after invoke */
128 GRPC_CALL_ERROR_NOT_INVOKED,
129 /* this call is already finished
130 (writes_done or write_status has already been called) */
131 GRPC_CALL_ERROR_ALREADY_FINISHED,
132 /* there is already an outstanding read/write operation on the call */
133 GRPC_CALL_ERROR_TOO_MANY_OPERATIONS,
134 /* the flags value was illegal for this call */
135 GRPC_CALL_ERROR_INVALID_FLAGS
136} grpc_call_error;
137
138/* Result of a grpc operation */
139typedef enum grpc_op_error {
140 /* everything went ok */
141 GRPC_OP_OK = 0,
142 /* something failed, we don't know what */
143 GRPC_OP_ERROR
144} grpc_op_error;
145
146/* Write Flags: */
147/* Hint that the write may be buffered and need not go out on the wire
148 immediately. GRPC is free to buffer the message until the next non-buffered
149 write, or until writes_done, but it need not buffer completely or at all. */
150#define GRPC_WRITE_BUFFER_HINT (0x00000001u)
151/* Force compression to be disabled for a particular write
152 (start_write/add_metadata). Illegal on invoke/accept. */
153#define GRPC_WRITE_NO_COMPRESS (0x00000002u)
154
155/* A buffer of bytes */
156struct grpc_byte_buffer;
157typedef struct grpc_byte_buffer grpc_byte_buffer;
158
159/* Sample helpers to obtain byte buffers (these will certainly move place */
160grpc_byte_buffer *grpc_byte_buffer_create(gpr_slice *slices, size_t nslices);
Craig Tiller80fa15c2015-01-13 16:10:49 -0800161grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800162size_t grpc_byte_buffer_length(grpc_byte_buffer *bb);
163void grpc_byte_buffer_destroy(grpc_byte_buffer *byte_buffer);
164
165/* Reader for byte buffers. Iterates over slices in the byte buffer */
166struct grpc_byte_buffer_reader;
167typedef struct grpc_byte_buffer_reader grpc_byte_buffer_reader;
168
169grpc_byte_buffer_reader *grpc_byte_buffer_reader_create(
170 grpc_byte_buffer *buffer);
171/* At the end of the stream, returns 0. Otherwise, returns 1 and sets slice to
172 be the returned slice. Caller is responsible for calling gpr_slice_unref on
173 the result. */
174int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader *reader,
175 gpr_slice *slice);
176void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader *reader);
177
178/* A single metadata element */
179typedef struct grpc_metadata {
Craig Tiller4f972732015-02-05 12:40:20 -0800180 const char *key;
181 const char *value;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800182 size_t value_length;
183} grpc_metadata;
184
185typedef enum grpc_completion_type {
Craig Tillerfef76692015-02-02 16:44:26 -0800186 GRPC_QUEUE_SHUTDOWN, /* Shutting down */
Craig Tillerfb189f82015-02-03 12:07:07 -0800187 GRPC_OP_COMPLETE, /* operation completion */
Craig Tillerfef76692015-02-02 16:44:26 -0800188 GRPC_READ, /* A read has completed */
189 GRPC_WRITE_ACCEPTED, /* A write has been accepted by
190 flow control */
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800191 GRPC_FINISH_ACCEPTED, /* writes_done or write_status has been accepted */
192 GRPC_CLIENT_METADATA_READ, /* The metadata array sent by server received at
193 client */
Craig Tillerfef76692015-02-02 16:44:26 -0800194 GRPC_FINISHED, /* An RPC has finished. The event contains status.
195 On the server this will be OK or Cancelled. */
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800196 GRPC_SERVER_RPC_NEW, /* A new RPC has arrived at the server */
Craig Tiller4ffdcd52015-01-16 11:34:55 -0800197 GRPC_SERVER_SHUTDOWN, /* The server has finished shutting down */
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800198 GRPC_COMPLETION_DO_NOT_USE /* must be last, forces users to include
199 a default: case */
200} grpc_completion_type;
201
202typedef struct grpc_event {
203 grpc_completion_type type;
204 void *tag;
205 grpc_call *call;
206 /* Data associated with the completion type. Field names match the type of
207 completion as listed in grpc_completion_type. */
208 union {
209 /* Contains a pointer to the buffer that was read, or NULL at the end of a
210 stream. */
211 grpc_byte_buffer *read;
212 grpc_op_error write_accepted;
213 grpc_op_error finish_accepted;
214 grpc_op_error invoke_accepted;
Craig Tillerfb189f82015-02-03 12:07:07 -0800215 grpc_op_error op_complete;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800216 struct {
217 size_t count;
218 grpc_metadata *elements;
219 } client_metadata_read;
ctiller2845cad2014-12-15 15:14:12 -0800220 struct {
221 grpc_status_code status;
222 const char *details;
223 size_t metadata_count;
224 grpc_metadata *metadata_elements;
225 } finished;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800226 struct {
227 const char *method;
228 const char *host;
229 gpr_timespec deadline;
230 size_t metadata_count;
231 grpc_metadata *metadata_elements;
232 } server_rpc_new;
233 } data;
234} grpc_event;
235
Craig Tillerfef76692015-02-02 16:44:26 -0800236typedef struct {
237 size_t count;
238 size_t capacity;
239 grpc_metadata *metadata;
240} grpc_metadata_array;
241
Craig Tillerea61b072015-02-03 19:19:27 -0800242void grpc_metadata_array_init(grpc_metadata_array *array);
243void grpc_metadata_array_destroy(grpc_metadata_array *array);
244
Craig Tillerfef76692015-02-02 16:44:26 -0800245typedef struct {
Craig Tillerea61b072015-02-03 19:19:27 -0800246 char *method;
Craig Tiller034929c2015-02-02 16:56:15 -0800247 size_t method_capacity;
Craig Tillerea61b072015-02-03 19:19:27 -0800248 char *host;
Craig Tiller034929c2015-02-02 16:56:15 -0800249 size_t host_capacity;
Craig Tillerfef76692015-02-02 16:44:26 -0800250 gpr_timespec deadline;
251} grpc_call_details;
252
Craig Tillerea61b072015-02-03 19:19:27 -0800253void grpc_call_details_init(grpc_call_details *details);
254void grpc_call_details_destroy(grpc_call_details *details);
255
Craig Tillerfef76692015-02-02 16:44:26 -0800256typedef enum {
Craig Tiller24be0f72015-02-10 14:04:22 -0800257 /* Send initial metadata: one and only one instance MUST be sent for each
258 call,
Craig Tillerb7800c12015-02-04 18:25:38 -0800259 unless the call was cancelled - in which case this can be skipped */
Craig Tillerfef76692015-02-02 16:44:26 -0800260 GRPC_OP_SEND_INITIAL_METADATA = 0,
Craig Tillerb7800c12015-02-04 18:25:38 -0800261 /* Send a message: 0 or more of these operations can occur for each call */
Craig Tillerfef76692015-02-02 16:44:26 -0800262 GRPC_OP_SEND_MESSAGE,
Craig Tiller24be0f72015-02-10 14:04:22 -0800263 /* Send a close from the server: one and only one instance MUST be sent from
264 the client,
Craig Tillerb7800c12015-02-04 18:25:38 -0800265 unless the call was cancelled - in which case this can be skipped */
Craig Tillerfef76692015-02-02 16:44:26 -0800266 GRPC_OP_SEND_CLOSE_FROM_CLIENT,
Craig Tiller24be0f72015-02-10 14:04:22 -0800267 /* Send status from the server: one and only one instance MUST be sent from
268 the server
Craig Tillerb7800c12015-02-04 18:25:38 -0800269 unless the call was cancelled - in which case this can be skipped */
Craig Tillerfef76692015-02-02 16:44:26 -0800270 GRPC_OP_SEND_STATUS_FROM_SERVER,
Craig Tillerb7800c12015-02-04 18:25:38 -0800271 /* Receive initial metadata: one and only one MUST be made on the client, must
272 not be made on the server */
Craig Tillerfef76692015-02-02 16:44:26 -0800273 GRPC_OP_RECV_INITIAL_METADATA,
Craig Tillerb7800c12015-02-04 18:25:38 -0800274 /* Receive a message: 0 or more of these operations can occur for each call */
Craig Tillerfb189f82015-02-03 12:07:07 -0800275 GRPC_OP_RECV_MESSAGE,
Craig Tiller24be0f72015-02-10 14:04:22 -0800276 /* Receive status on the client: one and only one must be made on the client
277 */
Craig Tillerfef76692015-02-02 16:44:26 -0800278 GRPC_OP_RECV_STATUS_ON_CLIENT,
Craig Tiller24be0f72015-02-10 14:04:22 -0800279 /* Receive status on the server: one and only one must be made on the server
280 */
Craig Tillerfef76692015-02-02 16:44:26 -0800281 GRPC_OP_RECV_CLOSE_ON_SERVER
282} grpc_op_type;
283
Craig Tiller24be0f72015-02-10 14:04:22 -0800284/* Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT
285 which has
Craig Tillerb7800c12015-02-04 18:25:38 -0800286 no arguments) */
Craig Tillerfef76692015-02-02 16:44:26 -0800287typedef struct grpc_op {
288 grpc_op_type op;
289 union {
290 struct {
291 size_t count;
292 const grpc_metadata *metadata;
293 } send_initial_metadata;
294 grpc_byte_buffer *send_message;
295 struct {
296 size_t trailing_metadata_count;
297 grpc_metadata *trailing_metadata;
298 grpc_status_code status;
299 const char *status_details;
300 } send_status_from_server;
Craig Tiller4f972732015-02-05 12:40:20 -0800301 /* ownership of the array is with the caller, but ownership of the elements
Craig Tillerc56b2cb2015-02-05 16:35:38 -0800302 stays with the call object (ie key, value members are owned by the call
303 object, recv_initial_metadata->array is owned by the caller).
304 After the operation completes, call grpc_metadata_array_destroy on this
305 value, or reuse it in a future op. */
Craig Tillerfef76692015-02-02 16:44:26 -0800306 grpc_metadata_array *recv_initial_metadata;
307 grpc_byte_buffer **recv_message;
308 struct {
Craig Tiller24be0f72015-02-10 14:04:22 -0800309 /* ownership of the array is with the caller, but ownership of the
310 elements
Craig Tillerc56b2cb2015-02-05 16:35:38 -0800311 stays with the call object (ie key, value members are owned by the call
312 object, trailing_metadata->array is owned by the caller).
313 After the operation completes, call grpc_metadata_array_destroy on this
314 value, or reuse it in a future op. */
Craig Tillerfef76692015-02-02 16:44:26 -0800315 grpc_metadata_array *trailing_metadata;
316 grpc_status_code *status;
Craig Tiller24be0f72015-02-10 14:04:22 -0800317 /* status_details is a buffer owned by the application before the op
318 completes
319 and after the op has completed. During the operation status_details may
320 be
321 reallocated to a size larger than *status_details_capacity, in which
322 case
Craig Tillerc56b2cb2015-02-05 16:35:38 -0800323 *status_details_capacity will be updated with the new array capacity.
324
325 Pre-allocating space:
326 size_t my_capacity = 8;
327 char *my_details = gpr_malloc(my_capacity);
328 x.status_details = &my_details;
Craig Tiller24be0f72015-02-10 14:04:22 -0800329 x.status_details_capacity = &my_capacity;
Craig Tillerc56b2cb2015-02-05 16:35:38 -0800330
331 Not pre-allocating space:
332 size_t my_capacity = 0;
333 char *my_details = NULL;
334 x.status_details = &my_details;
Craig Tiller24be0f72015-02-10 14:04:22 -0800335 x.status_details_capacity = &my_capacity;
Craig Tillerc56b2cb2015-02-05 16:35:38 -0800336
337 After the call:
338 gpr_free(my_details); */
Craig Tillerfef76692015-02-02 16:44:26 -0800339 char **status_details;
340 size_t *status_details_capacity;
341 } recv_status_on_client;
342 struct {
Craig Tiller24be0f72015-02-10 14:04:22 -0800343 /* out argument, set to 1 if the call failed in any way (seen as a
344 cancellation
Craig Tiller0a5bcbc2015-02-09 21:39:04 -0800345 on the server), or 0 if the call succeeded */
Craig Tillerfef76692015-02-02 16:44:26 -0800346 int *cancelled;
347 } recv_close_on_server;
348 } data;
349} grpc_op;
350
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800351/* Initialize the grpc library */
Craig Tiller32946d32015-01-15 11:37:30 -0800352void grpc_init(void);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800353
354/* Shutdown the grpc library */
Craig Tiller32946d32015-01-15 11:37:30 -0800355void grpc_shutdown(void);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800356
Craig Tiller32946d32015-01-15 11:37:30 -0800357grpc_completion_queue *grpc_completion_queue_create(void);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800358
359/* Blocks until an event is available, the completion queue is being shutdown,
360 or deadline is reached. Returns NULL on timeout, otherwise the event that
361 occurred. Callers should call grpc_event_finish once they have processed
362 the event.
363
364 Callers must not call grpc_completion_queue_next and
365 grpc_completion_queue_pluck simultaneously on the same completion queue. */
366grpc_event *grpc_completion_queue_next(grpc_completion_queue *cq,
367 gpr_timespec deadline);
368
369/* Blocks until an event with tag 'tag' is available, the completion queue is
370 being shutdown or deadline is reached. Returns NULL on timeout, or a pointer
371 to the event that occurred. Callers should call grpc_event_finish once they
372 have processed the event.
373
374 Callers must not call grpc_completion_queue_next and
375 grpc_completion_queue_pluck simultaneously on the same completion queue. */
376grpc_event *grpc_completion_queue_pluck(grpc_completion_queue *cq, void *tag,
377 gpr_timespec deadline);
378
379/* Cleanup any data owned by the event */
380void grpc_event_finish(grpc_event *event);
381
382/* Begin destruction of a completion queue. Once all possible events are
383 drained it's safe to call grpc_completion_queue_destroy. */
384void grpc_completion_queue_shutdown(grpc_completion_queue *cq);
385
386/* Destroy a completion queue. The caller must ensure that the queue is
387 drained and no threads are executing grpc_completion_queue_next */
388void grpc_completion_queue_destroy(grpc_completion_queue *cq);
389
390/* Create a call given a grpc_channel, in order to call 'method'. The request
391 is not sent until grpc_call_invoke is called. All completions are sent to
392 'completion_queue'. */
Craig Tillerc4f0ebe2015-02-02 10:16:30 -0800393grpc_call *grpc_channel_create_call_old(grpc_channel *channel,
394 const char *method, const char *host,
395 gpr_timespec deadline);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800396
Craig Tiller034929c2015-02-02 16:56:15 -0800397/* Create a call given a grpc_channel, in order to call 'method'. The request
398 is not sent until grpc_call_invoke is called. All completions are sent to
399 'completion_queue'. */
Craig Tillerfb189f82015-02-03 12:07:07 -0800400grpc_call *grpc_channel_create_call(grpc_channel *channel,
401 grpc_completion_queue *completion_queue,
402 const char *method, const char *host,
403 gpr_timespec deadline);
Craig Tiller034929c2015-02-02 16:56:15 -0800404
405/* Start a batch of operations defined in the array ops; when complete, post a
Craig Tiller24be0f72015-02-10 14:04:22 -0800406 completion of type 'tag' to the completion queue bound to the call.
Craig Tillerb7800c12015-02-04 18:25:38 -0800407 The order of ops specified in the batch has no significance.
408 Only one operation of each type can be active at once in any given
409 batch. */
Craig Tillerfef76692015-02-02 16:44:26 -0800410grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops,
411 size_t nops, void *tag);
412
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800413/* Create a client channel */
414grpc_channel *grpc_channel_create(const char *target,
415 const grpc_channel_args *args);
416
417/* Close and destroy a grpc channel */
418void grpc_channel_destroy(grpc_channel *channel);
419
420/* THREAD-SAFETY for grpc_call
421 The following functions are thread-compatible for any given call:
422 grpc_call_add_metadata
423 grpc_call_invoke
424 grpc_call_start_write
425 grpc_call_writes_done
426 grpc_call_start_read
427 grpc_call_destroy
428 The function grpc_call_cancel is thread-safe, and can be called at any
429 point before grpc_call_destroy is called. */
430
431/* Error handling for grpc_call
432 Most grpc_call functions return a grpc_error. If the error is not GRPC_OK
433 then the operation failed due to some unsatisfied precondition.
434 If a grpc_call fails, it's guaranteed that no change to the call state
435 has been made. */
436
437/* Add a single metadata element to the call, to be sent upon invocation.
438 flags is a bit-field combination of the write flags defined above.
yanggfb3aa262014-12-16 15:29:57 -0800439 REQUIRES: grpc_call_start_invoke/grpc_call_server_end_initial_metadata have
440 not been called on this call.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800441 Produces no events. */
Craig Tillerc4f0ebe2015-02-02 10:16:30 -0800442grpc_call_error grpc_call_add_metadata_old(grpc_call *call,
443 grpc_metadata *metadata,
444 gpr_uint32 flags);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800445
446/* Invoke the RPC. Starts sending metadata and request headers on the wire.
447 flags is a bit-field combination of the write flags defined above.
448 REQUIRES: Can be called at most once per call.
449 Can only be called on the client.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800450 Produces a GRPC_CLIENT_METADATA_READ event with metadata_read_tag when
451 the servers initial metadata has been read.
452 Produces a GRPC_FINISHED event with finished_tag when the call has been
453 completed (there may be other events for the call pending at this
454 time) */
Craig Tillerc4f0ebe2015-02-02 10:16:30 -0800455grpc_call_error grpc_call_invoke_old(grpc_call *call, grpc_completion_queue *cq,
456 void *metadata_read_tag,
457 void *finished_tag, gpr_uint32 flags);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800458
nnoble0c475f02014-12-05 15:37:39 -0800459/* Accept an incoming RPC, binding a completion queue to it.
460 To be called before sending or receiving messages.
nnoble0c475f02014-12-05 15:37:39 -0800461 REQUIRES: Can be called at most once per call.
462 Can only be called on the server.
463 Produces a GRPC_FINISHED event with finished_tag when the call has been
464 completed (there may be other events for the call pending at this
465 time) */
Craig Tillerc4f0ebe2015-02-02 10:16:30 -0800466grpc_call_error grpc_call_server_accept_old(grpc_call *call,
467 grpc_completion_queue *cq,
468 void *finished_tag);
nnoble0c475f02014-12-05 15:37:39 -0800469
yanggfb3aa262014-12-16 15:29:57 -0800470/* Start sending metadata.
nnoble0c475f02014-12-05 15:37:39 -0800471 To be called before sending messages.
472 flags is a bit-field combination of the write flags defined above.
473 REQUIRES: Can be called at most once per call.
474 Can only be called on the server.
475 Must be called after grpc_call_server_accept */
Craig Tillerc4f0ebe2015-02-02 10:16:30 -0800476grpc_call_error grpc_call_server_end_initial_metadata_old(grpc_call *call,
477 gpr_uint32 flags);
nnoble0c475f02014-12-05 15:37:39 -0800478
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800479/* Called by clients to cancel an RPC on the server.
480 Can be called multiple times, from any thread. */
481grpc_call_error grpc_call_cancel(grpc_call *call);
482
Craig Tillerd248c242015-01-14 11:49:12 -0800483/* Called by clients to cancel an RPC on the server.
Craig Tiller6046dc32015-01-14 12:55:45 -0800484 Can be called multiple times, from any thread.
Craig Tillerd248c242015-01-14 11:49:12 -0800485 If a status has not been received for the call, set it to the status code
Craig Tiller6046dc32015-01-14 12:55:45 -0800486 and description passed in.
Craig Tillerd248c242015-01-14 11:49:12 -0800487 Importantly, this function does not send status nor description to the
488 remote endpoint. */
Craig Tiller6046dc32015-01-14 12:55:45 -0800489grpc_call_error grpc_call_cancel_with_status(grpc_call *call,
490 grpc_status_code status,
491 const char *description);
Craig Tillerd248c242015-01-14 11:49:12 -0800492
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800493/* Queue a byte buffer for writing.
494 flags is a bit-field combination of the write flags defined above.
495 A write with byte_buffer null is allowed, and will not send any bytes on the
496 wire. If this is performed without GRPC_WRITE_BUFFER_HINT flag it provides
497 a mechanism to flush any previously buffered writes to outgoing flow control.
498 REQUIRES: No other writes are pending on the call. It is only safe to
499 start the next write after the corresponding write_accepted event
500 is received.
501 GRPC_INVOKE_ACCEPTED must have been received by the application
502 prior to calling this on the client. On the server,
nnoble0c475f02014-12-05 15:37:39 -0800503 grpc_call_server_end_of_initial_metadata must have been called
504 successfully.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800505 Produces a GRPC_WRITE_ACCEPTED event. */
Craig Tillerc4f0ebe2015-02-02 10:16:30 -0800506grpc_call_error grpc_call_start_write_old(grpc_call *call,
507 grpc_byte_buffer *byte_buffer,
508 void *tag, gpr_uint32 flags);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800509
510/* Queue a status for writing.
511 REQUIRES: No other writes are pending on the call.
yanggfb3aa262014-12-16 15:29:57 -0800512 grpc_call_server_end_initial_metadata must have been called on the
513 call prior to calling this.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800514 Only callable on the server.
515 Produces a GRPC_FINISH_ACCEPTED event when the status is sent. */
Craig Tillerc4f0ebe2015-02-02 10:16:30 -0800516grpc_call_error grpc_call_start_write_status_old(grpc_call *call,
517 grpc_status_code status_code,
518 const char *status_message,
519 void *tag);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800520
521/* No more messages to send.
522 REQUIRES: No other writes are pending on the call.
523 Only callable on the client.
524 Produces a GRPC_FINISH_ACCEPTED event when all bytes for the call have passed
525 outgoing flow control. */
Craig Tillerc4f0ebe2015-02-02 10:16:30 -0800526grpc_call_error grpc_call_writes_done_old(grpc_call *call, void *tag);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800527
528/* Initiate a read on a call. Output event contains a byte buffer with the
529 result of the read.
530 REQUIRES: No other reads are pending on the call. It is only safe to start
531 the next read after the corresponding read event is received.
nnoble0c475f02014-12-05 15:37:39 -0800532 On the client:
533 GRPC_INVOKE_ACCEPTED must have been received by the application
534 prior to calling this.
535 On the server:
536 grpc_call_server_accept must be called before calling this.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800537 Produces a single GRPC_READ event. */
Craig Tillerc4f0ebe2015-02-02 10:16:30 -0800538grpc_call_error grpc_call_start_read_old(grpc_call *call, void *tag);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800539
540/* Destroy a call. */
541void grpc_call_destroy(grpc_call *call);
542
543/* Request a call on a server.
544 Allows the server to create a single GRPC_SERVER_RPC_NEW event, with tag
545 tag_new.
546 If the call is subsequently cancelled, the cancellation will occur with tag
547 tag_cancel.
548 REQUIRES: Server must not have been shutdown.
549 NOTE: calling this is the only way to obtain GRPC_SERVER_RPC_NEW events. */
Craig Tillerc4f0ebe2015-02-02 10:16:30 -0800550grpc_call_error grpc_server_request_call_old(grpc_server *server,
551 void *tag_new);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800552
Craig Tillerfb189f82015-02-03 12:07:07 -0800553grpc_call_error grpc_server_request_call(
Craig Tillerea61b072015-02-03 19:19:27 -0800554 grpc_server *server, grpc_call **call, grpc_call_details *details,
Craig Tillerfb189f82015-02-03 12:07:07 -0800555 grpc_metadata_array *request_metadata,
556 grpc_completion_queue *completion_queue, void *tag_new);
Craig Tiller034929c2015-02-02 16:56:15 -0800557
Craig Tiller24be0f72015-02-10 14:04:22 -0800558void *grpc_server_register_method(grpc_server *server, const char *method,
559 const char *host);
560
561grpc_call_error grpc_server_request_registered_call(
562 grpc_server *server, void *registered_method, grpc_call **call,
563 gpr_timespec *deadline, grpc_metadata_array *request_metadata,
564 grpc_byte_buffer **optional_payload,
565 grpc_completion_queue *completion_queue, void *tag_new);
566
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800567/* Create a server */
568grpc_server *grpc_server_create(grpc_completion_queue *cq,
569 const grpc_channel_args *args);
570
ctiller570d1f42015-01-12 16:29:52 -0800571/* Add a http2 over tcp listener.
572 Returns bound port number on success, 0 on failure.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800573 REQUIRES: server not started */
574int grpc_server_add_http2_port(grpc_server *server, const char *addr);
575
murgatroid99c896e192015-01-21 11:36:23 -0800576/* Add a secure port to server.
577 Returns bound port number on success, 0 on failure.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800578 REQUIRES: server not started */
579int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr);
580
581/* Start a server - tells all listeners to start listening */
582void grpc_server_start(grpc_server *server);
583
ctiller9a58df02014-12-11 16:26:49 -0800584/* Begin shutting down a server.
585 After completion, no new calls or connections will be admitted.
586 Existing calls will be allowed to complete. */
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800587void grpc_server_shutdown(grpc_server *server);
588
Craig Tiller4ffdcd52015-01-16 11:34:55 -0800589/* As per grpc_server_shutdown, but send a GRPC_SERVER_SHUTDOWN event when
590 there are no more calls being serviced. */
591void grpc_server_shutdown_and_notify(grpc_server *server, void *tag);
592
ctiller9a58df02014-12-11 16:26:49 -0800593/* Destroy a server.
594 Forcefully cancels all existing calls. */
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800595void grpc_server_destroy(grpc_server *server);
596
597#ifdef __cplusplus
598}
599#endif
600
Craig Tillerb5dcec52015-01-13 11:13:42 -0800601#endif /* __GRPC_GRPC_H__ */