blob: 0ca28c0fef1824980707ba64afac4b68ac50465b [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * 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" Noble1ff52d52015-03-01 05:24:36 +010034#ifndef GRPC_GRPC_H
35#define GRPC_GRPC_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
37#include <grpc/status.h>
38
David Garcia Quintas25d02d52015-06-04 17:40:54 -070039#include <grpc/byte_buffer.h>
Craig Tillerf40df232016-03-25 13:38:14 -070040#include <grpc/impl/codegen/connectivity_state.h>
41#include <grpc/impl/codegen/grpc_types.h>
42#include <grpc/impl/codegen/propagation_bits.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080043#include <grpc/support/slice.h>
44#include <grpc/support/time.h>
Craig Tillerf40df232016-03-25 13:38:14 -070045#include <stddef.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080046
47#ifdef __cplusplus
48extern "C" {
49#endif
50
Craig Tiller2d984bf2015-07-20 15:01:38 -070051/*! \mainpage GRPC Core
52 *
Craig Tillerd6599a32015-09-03 09:37:02 -070053 * The GRPC Core library is a low-level library designed to be wrapped by higher
54 * level libraries. The top-level API is provided in grpc.h. Security related
55 * functionality lives in grpc_security.h.
Craig Tiller2d984bf2015-07-20 15:01:38 -070056 */
57
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010058GRPCAPI void grpc_metadata_array_init(grpc_metadata_array *array);
59GRPCAPI void grpc_metadata_array_destroy(grpc_metadata_array *array);
Craig Tillerea61b072015-02-03 19:19:27 -080060
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010061GRPCAPI void grpc_call_details_init(grpc_call_details *details);
62GRPCAPI void grpc_call_details_destroy(grpc_call_details *details);
Craig Tillerea61b072015-02-03 19:19:27 -080063
Hongwei Wang85ad6852015-08-13 16:13:10 -070064/** Registers a plugin to be initialized and destroyed with the library.
Hongwei Wanga83d1b32015-08-06 12:52:18 -070065
Craig Tillerd6c98df2015-08-18 09:33:44 -070066 The \a init and \a destroy functions will be invoked as part of
67 \a grpc_init() and \a grpc_shutdown(), respectively.
Hongwei Wang85ad6852015-08-13 16:13:10 -070068 Note that these functions can be invoked an arbitrary number of times
69 (and hence so will \a init and \a destroy).
Craig Tillerd6c98df2015-08-18 09:33:44 -070070 It is safe to pass NULL to either argument. Plugins are destroyed in
Hongwei Wang85ad6852015-08-13 16:13:10 -070071 the reverse order they were initialized. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010072GRPCAPI void grpc_register_plugin(void (*init)(void), void (*destroy)(void));
Hongwei Wanga3780a82015-07-17 15:27:18 -070073
Craig Tillere793ba12015-05-18 09:37:22 -070074/** Initialize the grpc library.
Craig Tiller8674cb12015-06-05 07:09:25 -070075
Craig Tillere793ba12015-05-18 09:37:22 -070076 It is not safe to call any other grpc functions before calling this.
77 (To avoid overhead, little checking is done, and some things may work. We
78 do not warrant that they will continue to do so in future revisions of this
79 library). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010080GRPCAPI void grpc_init(void);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080081
Craig Tillere793ba12015-05-18 09:37:22 -070082/** Shut down the grpc library.
Craig Tiller8674cb12015-06-05 07:09:25 -070083
Craig Tillere793ba12015-05-18 09:37:22 -070084 No memory is used by grpc after this call returns, nor are any instructions
85 executing within the grpc library.
86 Prior to calling, all application owned grpc objects must have been
87 destroyed. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010088GRPCAPI void grpc_shutdown(void);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080089
Craig Tiller2e622bc2015-07-10 07:46:03 -070090/** Return a string representing the current version of grpc */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010091GRPCAPI const char *grpc_version_string(void);
Craig Tiller2e622bc2015-07-10 07:46:03 -070092
Craig Tillere793ba12015-05-18 09:37:22 -070093/** Create a completion queue */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010094GRPCAPI grpc_completion_queue *grpc_completion_queue_create(void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080095
Craig Tillere793ba12015-05-18 09:37:22 -070096/** Blocks until an event is available, the completion queue is being shut down,
Craig Tiller8674cb12015-06-05 07:09:25 -070097 or deadline is reached.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080098
vjpai1854d772015-06-08 01:12:29 -070099 Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout,
100 otherwise a grpc_event describing the event that occurred.
Craig Tillere793ba12015-05-18 09:37:22 -0700101
102 Callers must not call grpc_completion_queue_next and
103 grpc_completion_queue_pluck simultaneously on the same completion queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100104GRPCAPI grpc_event grpc_completion_queue_next(grpc_completion_queue *cq,
105 gpr_timespec deadline,
106 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800107
Craig Tillere793ba12015-05-18 09:37:22 -0700108/** Blocks until an event with tag 'tag' is available, the completion queue is
Craig Tiller8674cb12015-06-05 07:09:25 -0700109 being shutdown or deadline is reached.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800110
vjpai1854d772015-06-08 01:12:29 -0700111 Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout,
112 otherwise a grpc_event describing the event that occurred.
Craig Tillere793ba12015-05-18 09:37:22 -0700113
114 Callers must not call grpc_completion_queue_next and
Hongwei Wang85ad6852015-08-13 16:13:10 -0700115 grpc_completion_queue_pluck simultaneously on the same completion queue.
116
Craig Tiller489df072015-08-01 16:15:45 -0700117 Completion queues support a maximum of GRPC_MAX_COMPLETION_QUEUE_PLUCKERS
118 concurrently executing plucks at any time. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100119GRPCAPI grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq,
120 void *tag, gpr_timespec deadline,
121 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800122
Craig Tiller489df072015-08-01 16:15:45 -0700123/** Maximum number of outstanding grpc_completion_queue_pluck executions per
124 completion queue */
125#define GRPC_MAX_COMPLETION_QUEUE_PLUCKERS 6
126
Craig Tiller2d984bf2015-07-20 15:01:38 -0700127/** Begin destruction of a completion queue. Once all possible events are
128 drained then grpc_completion_queue_next will start to produce
129 GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call
130 grpc_completion_queue_destroy.
Craig Tillerb20111c2015-04-10 23:27:11 +0000131
Craig Tiller2d984bf2015-07-20 15:01:38 -0700132 After calling this function applications should ensure that no
133 NEW work is added to be published on this completion queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100134GRPCAPI void grpc_completion_queue_shutdown(grpc_completion_queue *cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800135
Craig Tiller2d984bf2015-07-20 15:01:38 -0700136/** Destroy a completion queue. The caller must ensure that the queue is
137 drained and no threads are executing grpc_completion_queue_next */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100138GRPCAPI void grpc_completion_queue_destroy(grpc_completion_queue *cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800139
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700140/** Create a completion queue alarm instance associated to \a cq.
141 *
David Garcia Quintas7fd0fd52015-10-07 17:41:08 -0700142 * Once the alarm expires (at \a deadline) or it's cancelled (see \a
143 * grpc_alarm_cancel), an event with tag \a tag will be added to \a cq. If the
144 * alarm expired, the event's success bit will be true, false otherwise (ie,
145 * upon cancellation). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100146GRPCAPI grpc_alarm *grpc_alarm_create(grpc_completion_queue *cq,
147 gpr_timespec deadline, void *tag);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700148
David Garcia Quintas7fd0fd52015-10-07 17:41:08 -0700149/** Cancel a completion queue alarm. Calling this function over an alarm that
150 * has already fired has no effect. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100151GRPCAPI void grpc_alarm_cancel(grpc_alarm *alarm);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700152
153/** Destroy the given completion queue alarm, cancelling it in the process. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100154GRPCAPI void grpc_alarm_destroy(grpc_alarm *alarm);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700155
Craig Tiller48cb07c2015-07-15 16:16:15 -0700156/** Check the connectivity state of a channel. */
Craig Tillerf40df232016-03-25 13:38:14 -0700157GRPCAPI grpc_connectivity_state grpc_channel_check_connectivity_state(
158 grpc_channel *channel, int try_to_connect);
Craig Tiller48cb07c2015-07-15 16:16:15 -0700159
160/** Watch for a change in connectivity state.
161 Once the channel connectivity state is different from last_observed_state,
162 tag will be enqueued on cq with success=1.
163 If deadline expires BEFORE the state is changed, tag will be enqueued on cq
Craig Tiller2cd9dd92015-07-31 16:34:37 -0700164 with success=0. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100165GRPCAPI void grpc_channel_watch_connectivity_state(
Craig Tiller48cb07c2015-07-15 16:16:15 -0700166 grpc_channel *channel, grpc_connectivity_state last_observed_state,
Craig Tiller2cd9dd92015-07-31 16:34:37 -0700167 gpr_timespec deadline, grpc_completion_queue *cq, void *tag);
Craig Tiller48cb07c2015-07-15 16:16:15 -0700168
Craig Tiller2d984bf2015-07-20 15:01:38 -0700169/** Create a call given a grpc_channel, in order to call 'method'. All
170 completions are sent to 'completion_queue'. 'method' and 'host' need only
Craig Tiller58471772015-07-31 17:12:34 -0700171 live through the invocation of this function.
172 If parent_call is non-NULL, it must be a server-side call. It will be used
Hongwei Wang85ad6852015-08-13 16:13:10 -0700173 to propagate properties from the server call to this new client call.
Craig Tiller58471772015-07-31 17:12:34 -0700174 */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100175GRPCAPI grpc_call *grpc_channel_create_call(
Craig Tillerd6546c92016-01-29 07:59:35 -0800176 grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
177 grpc_completion_queue *completion_queue, const char *method,
178 const char *host, gpr_timespec deadline, void *reserved);
Craig Tiller034929c2015-02-02 16:56:15 -0800179
Craig Tillere2c62372015-12-07 16:11:03 -0800180/** Ping the channels peer (load balanced channels will select one sub-channel
Craig Tiller26dab312015-12-07 14:43:47 -0800181 to ping); if the channel is not connected, posts a failed. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100182GRPCAPI void grpc_channel_ping(grpc_channel *channel, grpc_completion_queue *cq,
183 void *tag, void *reserved);
Craig Tiller26dab312015-12-07 14:43:47 -0800184
Craig Tiller2d984bf2015-07-20 15:01:38 -0700185/** Pre-register a method/host pair on a channel. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100186GRPCAPI void *grpc_channel_register_call(grpc_channel *channel,
187 const char *method, const char *host,
188 void *reserved);
Craig Tiller08453372015-04-10 16:05:38 -0700189
Craig Tiller2d984bf2015-07-20 15:01:38 -0700190/** Create a call given a handle returned from grpc_channel_register_call */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100191GRPCAPI grpc_call *grpc_channel_create_registered_call(
Craig Tiller7536af02015-12-22 13:49:30 -0800192 grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
Craig Tiller3e7c6a72015-07-31 16:17:04 -0700193 grpc_completion_queue *completion_queue, void *registered_call_handle,
Nicolas "Pixel" Noble9d72b142015-08-08 01:45:38 +0200194 gpr_timespec deadline, void *reserved);
Craig Tiller08453372015-04-10 16:05:38 -0700195
Craig Tiller2d984bf2015-07-20 15:01:38 -0700196/** Start a batch of operations defined in the array ops; when complete, post a
197 completion of type 'tag' to the completion queue bound to the call.
198 The order of ops specified in the batch has no significance.
199 Only one operation of each type can be active at once in any given
200 batch. You must call grpc_completion_queue_next or
201 grpc_completion_queue_pluck on the completion queue associated with 'call'
202 for work to be performed.
203 THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment
204 needs to be synchronized. As an optimization, you may synchronize batches
205 containing just send operations independently from batches containing just
206 receive operations. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100207GRPCAPI grpc_call_error grpc_call_start_batch(grpc_call *call,
208 const grpc_op *ops, size_t nops,
209 void *tag, void *reserved);
Craig Tillerfef76692015-02-02 16:44:26 -0800210
Craig Tiller45249422015-07-20 16:16:35 -0700211/** Returns a newly allocated string representing the endpoint to which this
212 call is communicating with. The string is in the uri format accepted by
213 grpc_channel_create.
Alistair Veitchff32faf2015-07-30 09:54:15 -0700214 The returned string should be disposed of with gpr_free().
Craig Tiller45249422015-07-20 16:16:35 -0700215
216 WARNING: this value is never authenticated or subject to any security
217 related code. It must not be used for any authentication related
218 functionality. Instead, use grpc_auth_context. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100219GRPCAPI char *grpc_call_get_peer(grpc_call *call);
Craig Tiller1b22b9d2015-07-20 13:42:22 -0700220
Alistair Veitchff32faf2015-07-30 09:54:15 -0700221struct census_context;
222
223/* Set census context for a call; Must be called before first call to
224 grpc_call_start_batch(). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100225GRPCAPI void grpc_census_call_set_context(grpc_call *call,
226 struct census_context *context);
Alistair Veitchff32faf2015-07-30 09:54:15 -0700227
228/* Retrieve the calls current census context. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100229GRPCAPI struct census_context *grpc_census_call_get_context(grpc_call *call);
Alistair Veitchff32faf2015-07-30 09:54:15 -0700230
Craig Tiller45249422015-07-20 16:16:35 -0700231/** Return a newly allocated string representing the target a channel was
232 created for. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100233GRPCAPI char *grpc_channel_get_target(grpc_channel *channel);
Craig Tiller45249422015-07-20 16:16:35 -0700234
Craig Tiller2d984bf2015-07-20 15:01:38 -0700235/** Create a client channel to 'target'. Additional channel level configuration
236 MAY be provided by grpc_channel_args, though the expectation is that most
237 clients will want to simply pass NULL. See grpc_channel_args definition for
238 more on this. The data in 'args' need only live through the invocation of
239 this function. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100240GRPCAPI grpc_channel *grpc_insecure_channel_create(
Craig Tillerd6546c92016-01-29 07:59:35 -0800241 const char *target, const grpc_channel_args *args, void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800242
Craig Tiller2d984bf2015-07-20 15:01:38 -0700243/** Create a lame client: this client fails every operation attempted on it. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100244GRPCAPI grpc_channel *grpc_lame_client_channel_create(
Craig Tillerd6546c92016-01-29 07:59:35 -0800245 const char *target, grpc_status_code error_code, const char *error_message);
Craig Tiller42bc87c2015-02-23 08:50:19 -0800246
Craig Tiller2d984bf2015-07-20 15:01:38 -0700247/** Close and destroy a grpc channel */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100248GRPCAPI void grpc_channel_destroy(grpc_channel *channel);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800249
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800250/* Error handling for grpc_call
251 Most grpc_call functions return a grpc_error. If the error is not GRPC_OK
252 then the operation failed due to some unsatisfied precondition.
253 If a grpc_call fails, it's guaranteed that no change to the call state
254 has been made. */
255
Craig Tiller2d984bf2015-07-20 15:01:38 -0700256/** Called by clients to cancel an RPC on the server.
257 Can be called multiple times, from any thread.
258 THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status
259 are thread-safe, and can be called at any point before grpc_call_destroy
260 is called.*/
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100261GRPCAPI grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800262
Craig Tiller2d984bf2015-07-20 15:01:38 -0700263/** Called by clients to cancel an RPC on the server.
264 Can be called multiple times, from any thread.
265 If a status has not been received for the call, set it to the status code
266 and description passed in.
267 Importantly, this function does not send status nor description to the
268 remote endpoint. */
Craig Tillerf40df232016-03-25 13:38:14 -0700269GRPCAPI grpc_call_error grpc_call_cancel_with_status(grpc_call *call,
270 grpc_status_code status,
271 const char *description,
272 void *reserved);
Craig Tillerd248c242015-01-14 11:49:12 -0800273
Craig Tiller2d984bf2015-07-20 15:01:38 -0700274/** Destroy a call.
275 THREAD SAFETY: grpc_call_destroy is thread-compatible */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100276GRPCAPI void grpc_call_destroy(grpc_call *call);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800277
David G. Quintasb2a1c592015-08-20 14:44:27 -0700278/** Request notification of a new call.
Craig Tillerddf3a512015-09-24 13:03:44 -0700279 Once a call is received, a notification tagged with \a tag_new is added to
280 \a cq_for_notification. \a call, \a details and \a request_metadata are
Craig Tiller1359a122015-08-24 14:43:32 -0700281 updated with the appropriate call information. \a cq_bound_to_call is bound
282 to \a call, and batch operation notifications for that call will be posted
283 to \a cq_bound_to_call.
David G. Quintasb2a1c592015-08-20 14:44:27 -0700284 Note that \a cq_for_notification must have been registered to the server via
285 \a grpc_server_register_completion_queue. */
Craig Tillerf40df232016-03-25 13:38:14 -0700286GRPCAPI grpc_call_error grpc_server_request_call(
287 grpc_server *server, grpc_call **call, grpc_call_details *details,
288 grpc_metadata_array *request_metadata,
289 grpc_completion_queue *cq_bound_to_call,
290 grpc_completion_queue *cq_for_notification, void *tag_new);
Craig Tiller034929c2015-02-02 16:56:15 -0800291
Craig Tiller06cb1a92016-04-04 08:10:47 -0700292/** How to handle payloads for a registered method */
293typedef enum {
294 /** Don't try to read the payload */
295 GRPC_SRM_PAYLOAD_NONE,
296 /** Read the initial payload as a byte buffer */
297 GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER
298} grpc_server_register_method_payload_handling;
299
Craig Tiller2d984bf2015-07-20 15:01:38 -0700300/** Registers a method in the server.
301 Methods to this (host, method) pair will not be reported by
302 grpc_server_request_call, but instead be reported by
303 grpc_server_request_registered_call when passed the appropriate
304 registered_method (as returned by this function).
305 Must be called before grpc_server_start.
306 Returns NULL on failure. */
Craig Tiller06cb1a92016-04-04 08:10:47 -0700307GRPCAPI void *grpc_server_register_method(
308 grpc_server *server, const char *method, const char *host,
309 grpc_server_register_method_payload_handling payload_handling,
310 uint32_t flags);
Craig Tiller24be0f72015-02-10 14:04:22 -0800311
Alistair Veitchff32faf2015-07-30 09:54:15 -0700312/** Request notification of a new pre-registered call. 'cq_for_notification'
313 must have been registered to the server via
Craig Tiller2d984bf2015-07-20 15:01:38 -0700314 grpc_server_register_completion_queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100315GRPCAPI grpc_call_error grpc_server_request_registered_call(
Craig Tiller24be0f72015-02-10 14:04:22 -0800316 grpc_server *server, void *registered_method, grpc_call **call,
317 gpr_timespec *deadline, grpc_metadata_array *request_metadata,
318 grpc_byte_buffer **optional_payload,
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700319 grpc_completion_queue *cq_bound_to_call,
320 grpc_completion_queue *cq_for_notification, void *tag_new);
Craig Tiller24be0f72015-02-10 14:04:22 -0800321
Craig Tiller2d984bf2015-07-20 15:01:38 -0700322/** Create a server. Additional configuration for each incoming channel can
323 be specified with args. If no additional configuration is needed, args can
324 be NULL. See grpc_channel_args for more. The data in 'args' need only live
325 through the invocation of this function. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100326GRPCAPI grpc_server *grpc_server_create(const grpc_channel_args *args,
327 void *reserved);
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700328
Craig Tiller2d984bf2015-07-20 15:01:38 -0700329/** Register a completion queue with the server. Must be done for any
330 notification completion queue that is passed to grpc_server_request_*_call
331 and to grpc_server_shutdown_and_notify. Must be performed prior to
332 grpc_server_start. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100333GRPCAPI void grpc_server_register_completion_queue(grpc_server *server,
334 grpc_completion_queue *cq,
335 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800336
Craig Tiller2d984bf2015-07-20 15:01:38 -0700337/** Add a HTTP2 over plaintext over tcp listener.
338 Returns bound port number on success, 0 on failure.
339 REQUIRES: server not started */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100340GRPCAPI int grpc_server_add_insecure_http2_port(grpc_server *server,
341 const char *addr);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800342
Craig Tiller2d984bf2015-07-20 15:01:38 -0700343/** Start a server - tells all listeners to start listening */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100344GRPCAPI void grpc_server_start(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800345
Craig Tiller2d984bf2015-07-20 15:01:38 -0700346/** Begin shutting down a server.
347 After completion, no new calls or connections will be admitted.
348 Existing calls will be allowed to complete.
349 Send a GRPC_OP_COMPLETE event when there are no more calls being serviced.
350 Shutdown is idempotent, and all tags will be notified at once if multiple
351 grpc_server_shutdown_and_notify calls are made. 'cq' must have been
352 registered to this server via grpc_server_register_completion_queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100353GRPCAPI void grpc_server_shutdown_and_notify(grpc_server *server,
354 grpc_completion_queue *cq,
355 void *tag);
Craig Tiller4ffdcd52015-01-16 11:34:55 -0800356
Craig Tiller2d984bf2015-07-20 15:01:38 -0700357/** Cancel all in-progress calls.
358 Only usable after shutdown. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100359GRPCAPI void grpc_server_cancel_all_calls(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800360
Craig Tiller2d984bf2015-07-20 15:01:38 -0700361/** Destroy a server.
362 Shutdown must have completed beforehand (i.e. all tags generated by
363 grpc_server_shutdown_and_notify must have been received, and at least
364 one call to grpc_server_shutdown_and_notify must have been made). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100365GRPCAPI void grpc_server_destroy(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800366
Craig Tilleraf7abf92015-06-03 17:18:58 -0700367/** Enable or disable a tracer.
368
369 Tracers (usually controlled by the environment variable GRPC_TRACE)
370 allow printf-style debugging on GRPC internals, and are useful for
Craig Tiller9a576332015-06-17 10:21:49 -0700371 tracking down problems in the field.
Craig Tilleraf7abf92015-06-03 17:18:58 -0700372
Craig Tiller9a576332015-06-17 10:21:49 -0700373 Use of this function is not strictly thread-safe, but the
Craig Tilleraf7abf92015-06-03 17:18:58 -0700374 thread-safety issues raised by it should not be of concern. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100375GRPCAPI int grpc_tracer_set_enabled(const char *name, int enabled);
Craig Tilleraf7abf92015-06-03 17:18:58 -0700376
murgatroid99c3910ca2016-01-06 13:14:23 -0800377/** Check whether a metadata key is legal (will be accepted by core) */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100378GRPCAPI int grpc_header_key_is_legal(const char *key, size_t length);
murgatroid99c3910ca2016-01-06 13:14:23 -0800379
380/** Check whether a non-binary metadata value is legal (will be accepted by
381 core) */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100382GRPCAPI int grpc_header_nonbin_value_is_legal(const char *value, size_t length);
murgatroid99c3910ca2016-01-06 13:14:23 -0800383
384/** Check whether a metadata key corresponds to a binary value */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100385GRPCAPI int grpc_is_binary_header(const char *key, size_t length);
murgatroid99c3910ca2016-01-06 13:14:23 -0800386
Yuchen Zeng2e7d9572016-04-15 17:29:57 -0700387/** Convert grpc_call_error values to a string */
388GRPCAPI const char *grpc_call_error_to_string(grpc_call_error error);
389
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800390#ifdef __cplusplus
391}
392#endif
393
Craig Tillerb20111c2015-04-10 23:27:11 +0000394#endif /* GRPC_GRPC_H */