blob: f1400e9ad8f5d137b57b1f3fc551e7c6801d4d21 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015-2016 gRPC authors.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080016 *
17 */
18
Nicolas "Pixel" Noble1ff52d52015-03-01 05:24:36 +010019#ifndef GRPC_GRPC_H
20#define GRPC_GRPC_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080021
22#include <grpc/status.h>
23
David Garcia Quintas25d02d52015-06-04 17:40:54 -070024#include <grpc/byte_buffer.h>
Craig Tillerf40df232016-03-25 13:38:14 -070025#include <grpc/impl/codegen/connectivity_state.h>
26#include <grpc/impl/codegen/grpc_types.h>
27#include <grpc/impl/codegen/propagation_bits.h>
Craig Tillerb37d53e2016-10-26 16:16:35 -070028#include <grpc/slice.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080029#include <grpc/support/time.h>
Craig Tillerf40df232016-03-25 13:38:14 -070030#include <stddef.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080031
32#ifdef __cplusplus
33extern "C" {
34#endif
35
Craig Tiller2d984bf2015-07-20 15:01:38 -070036/*! \mainpage GRPC Core
37 *
Craig Tillerd6599a32015-09-03 09:37:02 -070038 * The GRPC Core library is a low-level library designed to be wrapped by higher
39 * level libraries. The top-level API is provided in grpc.h. Security related
40 * functionality lives in grpc_security.h.
Craig Tiller2d984bf2015-07-20 15:01:38 -070041 */
42
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010043GRPCAPI void grpc_metadata_array_init(grpc_metadata_array *array);
44GRPCAPI void grpc_metadata_array_destroy(grpc_metadata_array *array);
Craig Tillerea61b072015-02-03 19:19:27 -080045
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010046GRPCAPI void grpc_call_details_init(grpc_call_details *details);
47GRPCAPI void grpc_call_details_destroy(grpc_call_details *details);
Craig Tillerea61b072015-02-03 19:19:27 -080048
Hongwei Wang85ad6852015-08-13 16:13:10 -070049/** Registers a plugin to be initialized and destroyed with the library.
Hongwei Wanga83d1b32015-08-06 12:52:18 -070050
Craig Tillerd6c98df2015-08-18 09:33:44 -070051 The \a init and \a destroy functions will be invoked as part of
52 \a grpc_init() and \a grpc_shutdown(), respectively.
Hongwei Wang85ad6852015-08-13 16:13:10 -070053 Note that these functions can be invoked an arbitrary number of times
54 (and hence so will \a init and \a destroy).
Craig Tillerd6c98df2015-08-18 09:33:44 -070055 It is safe to pass NULL to either argument. Plugins are destroyed in
Hongwei Wang85ad6852015-08-13 16:13:10 -070056 the reverse order they were initialized. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010057GRPCAPI void grpc_register_plugin(void (*init)(void), void (*destroy)(void));
Hongwei Wanga3780a82015-07-17 15:27:18 -070058
Craig Tillere793ba12015-05-18 09:37:22 -070059/** Initialize the grpc library.
Craig Tiller8674cb12015-06-05 07:09:25 -070060
Craig Tillere793ba12015-05-18 09:37:22 -070061 It is not safe to call any other grpc functions before calling this.
62 (To avoid overhead, little checking is done, and some things may work. We
63 do not warrant that they will continue to do so in future revisions of this
64 library). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010065GRPCAPI void grpc_init(void);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080066
Craig Tillere793ba12015-05-18 09:37:22 -070067/** Shut down the grpc library.
Craig Tiller8674cb12015-06-05 07:09:25 -070068
Craig Tillere793ba12015-05-18 09:37:22 -070069 No memory is used by grpc after this call returns, nor are any instructions
70 executing within the grpc library.
71 Prior to calling, all application owned grpc objects must have been
72 destroyed. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010073GRPCAPI void grpc_shutdown(void);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080074
Craig Tiller2e622bc2015-07-10 07:46:03 -070075/** Return a string representing the current version of grpc */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010076GRPCAPI const char *grpc_version_string(void);
Craig Tiller2e622bc2015-07-10 07:46:03 -070077
Craig Tiller8dfdb7e2016-08-29 11:25:56 -070078/** Return a string specifying what the 'g' in gRPC stands for */
79GRPCAPI const char *grpc_g_stands_for(void);
80
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070081/** Returns the completion queue factory based on the attributes. MAY return a
82 NULL if no factory can be found */
83GRPCAPI const grpc_completion_queue_factory *
84grpc_completion_queue_factory_lookup(
85 const grpc_completion_queue_attributes *attributes);
86
87/** Helper function to create a completion queue with grpc_cq_completion_type
88 of GRPC_CQ_NEXT and grpc_cq_polling_type of GRPC_CQ_DEFAULT_POLLING */
89GRPCAPI grpc_completion_queue *grpc_completion_queue_create_for_next(
90 void *reserved);
91
92/** Helper function to create a completion queue with grpc_cq_completion_type
93 of GRPC_CQ_PLUCK and grpc_cq_polling_type of GRPC_CQ_DEFAULT_POLLING */
94GRPCAPI grpc_completion_queue *grpc_completion_queue_create_for_pluck(
95 void *reserved);
96
Sree Kuchibhotla7a4e5b42017-02-17 09:28:46 -080097/** Create a completion queue */
Sree Kuchibhotla321881d2017-02-27 11:25:28 -080098GRPCAPI grpc_completion_queue *grpc_completion_queue_create(
Sree Kuchibhotla2abbf8a2017-03-21 17:31:03 -070099 const grpc_completion_queue_factory *factory,
100 const grpc_completion_queue_attributes *attributes, void *reserved);
Sree Kuchibhotla7a4e5b42017-02-17 09:28:46 -0800101
Craig Tillere793ba12015-05-18 09:37:22 -0700102/** Blocks until an event is available, the completion queue is being shut down,
Craig Tiller8674cb12015-06-05 07:09:25 -0700103 or deadline is reached.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800104
vjpai1854d772015-06-08 01:12:29 -0700105 Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout,
106 otherwise a grpc_event describing the event that occurred.
Craig Tillere793ba12015-05-18 09:37:22 -0700107
108 Callers must not call grpc_completion_queue_next and
109 grpc_completion_queue_pluck simultaneously on the same completion queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100110GRPCAPI grpc_event grpc_completion_queue_next(grpc_completion_queue *cq,
111 gpr_timespec deadline,
112 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800113
Craig Tillere793ba12015-05-18 09:37:22 -0700114/** Blocks until an event with tag 'tag' is available, the completion queue is
Craig Tiller8674cb12015-06-05 07:09:25 -0700115 being shutdown or deadline is reached.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800116
vjpai1854d772015-06-08 01:12:29 -0700117 Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout,
118 otherwise a grpc_event describing the event that occurred.
Craig Tillere793ba12015-05-18 09:37:22 -0700119
120 Callers must not call grpc_completion_queue_next and
Hongwei Wang85ad6852015-08-13 16:13:10 -0700121 grpc_completion_queue_pluck simultaneously on the same completion queue.
122
Craig Tiller489df072015-08-01 16:15:45 -0700123 Completion queues support a maximum of GRPC_MAX_COMPLETION_QUEUE_PLUCKERS
124 concurrently executing plucks at any time. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100125GRPCAPI grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq,
126 void *tag, gpr_timespec deadline,
127 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800128
Craig Tiller489df072015-08-01 16:15:45 -0700129/** Maximum number of outstanding grpc_completion_queue_pluck executions per
130 completion queue */
131#define GRPC_MAX_COMPLETION_QUEUE_PLUCKERS 6
132
Craig Tiller2d984bf2015-07-20 15:01:38 -0700133/** Begin destruction of a completion queue. Once all possible events are
134 drained then grpc_completion_queue_next will start to produce
135 GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call
136 grpc_completion_queue_destroy.
Craig Tillerb20111c2015-04-10 23:27:11 +0000137
Craig Tiller2d984bf2015-07-20 15:01:38 -0700138 After calling this function applications should ensure that no
139 NEW work is added to be published on this completion queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100140GRPCAPI void grpc_completion_queue_shutdown(grpc_completion_queue *cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800141
Craig Tiller2d984bf2015-07-20 15:01:38 -0700142/** Destroy a completion queue. The caller must ensure that the queue is
143 drained and no threads are executing grpc_completion_queue_next */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100144GRPCAPI void grpc_completion_queue_destroy(grpc_completion_queue *cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800145
Vijay Pai58c33ba2017-09-01 14:08:42 -0700146/** Create a completion queue alarm instance */
147GRPCAPI grpc_alarm *grpc_alarm_create(void *reserved);
148
149/** Set a completion queue alarm instance associated to \a cq.
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700150 *
David Garcia Quintas7fd0fd52015-10-07 17:41:08 -0700151 * Once the alarm expires (at \a deadline) or it's cancelled (see \a
152 * grpc_alarm_cancel), an event with tag \a tag will be added to \a cq. If the
153 * alarm expired, the event's success bit will be true, false otherwise (ie,
154 * upon cancellation). */
Vijay Pai58c33ba2017-09-01 14:08:42 -0700155GRPCAPI void grpc_alarm_set(grpc_alarm *alarm, grpc_completion_queue *cq,
156 gpr_timespec deadline, void *tag, void *reserved);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700157
David Garcia Quintas7fd0fd52015-10-07 17:41:08 -0700158/** Cancel a completion queue alarm. Calling this function over an alarm that
159 * has already fired has no effect. */
Vijay Pai58c33ba2017-09-01 14:08:42 -0700160GRPCAPI void grpc_alarm_cancel(grpc_alarm *alarm, void *reserved);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700161
162/** Destroy the given completion queue alarm, cancelling it in the process. */
Vijay Pai58c33ba2017-09-01 14:08:42 -0700163GRPCAPI void grpc_alarm_destroy(grpc_alarm *alarm, void *reserved);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700164
Craig Tiller48cb07c2015-07-15 16:16:15 -0700165/** Check the connectivity state of a channel. */
Craig Tillerf40df232016-03-25 13:38:14 -0700166GRPCAPI grpc_connectivity_state grpc_channel_check_connectivity_state(
167 grpc_channel *channel, int try_to_connect);
Craig Tiller48cb07c2015-07-15 16:16:15 -0700168
Alexander Polcync3b1f182017-04-18 13:51:36 -0700169/** Number of active "external connectivity state watchers" attached to a
170 * channel.
171 * Useful for testing. **/
172GRPCAPI int grpc_channel_num_external_connectivity_watchers(
173 grpc_channel *channel);
174
Craig Tiller48cb07c2015-07-15 16:16:15 -0700175/** Watch for a change in connectivity state.
176 Once the channel connectivity state is different from last_observed_state,
177 tag will be enqueued on cq with success=1.
178 If deadline expires BEFORE the state is changed, tag will be enqueued on cq
Craig Tiller2cd9dd92015-07-31 16:34:37 -0700179 with success=0. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100180GRPCAPI void grpc_channel_watch_connectivity_state(
Craig Tiller48cb07c2015-07-15 16:16:15 -0700181 grpc_channel *channel, grpc_connectivity_state last_observed_state,
Craig Tiller2cd9dd92015-07-31 16:34:37 -0700182 gpr_timespec deadline, grpc_completion_queue *cq, void *tag);
Craig Tiller48cb07c2015-07-15 16:16:15 -0700183
Craig Tiller2d984bf2015-07-20 15:01:38 -0700184/** Create a call given a grpc_channel, in order to call 'method'. All
185 completions are sent to 'completion_queue'. 'method' and 'host' need only
Craig Tiller58471772015-07-31 17:12:34 -0700186 live through the invocation of this function.
187 If parent_call is non-NULL, it must be a server-side call. It will be used
David Garcia Quintas15eba132016-08-09 15:20:48 -0700188 to propagate properties from the server call to this new client call,
189 depending on the value of \a propagation_mask (see propagation_bits.h for
190 possible values). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100191GRPCAPI grpc_call *grpc_channel_create_call(
Craig Tillerd6546c92016-01-29 07:59:35 -0800192 grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800193 grpc_completion_queue *completion_queue, grpc_slice method,
194 const grpc_slice *host, gpr_timespec deadline, void *reserved);
Craig Tiller034929c2015-02-02 16:56:15 -0800195
Craig Tillere2c62372015-12-07 16:11:03 -0800196/** Ping the channels peer (load balanced channels will select one sub-channel
Craig Tiller26dab312015-12-07 14:43:47 -0800197 to ping); if the channel is not connected, posts a failed. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100198GRPCAPI void grpc_channel_ping(grpc_channel *channel, grpc_completion_queue *cq,
199 void *tag, void *reserved);
Craig Tiller26dab312015-12-07 14:43:47 -0800200
Craig Tiller2d984bf2015-07-20 15:01:38 -0700201/** Pre-register a method/host pair on a channel. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100202GRPCAPI void *grpc_channel_register_call(grpc_channel *channel,
203 const char *method, const char *host,
204 void *reserved);
Craig Tiller08453372015-04-10 16:05:38 -0700205
David Garcia Quintas15eba132016-08-09 15:20:48 -0700206/** Create a call given a handle returned from grpc_channel_register_call.
207 \sa grpc_channel_create_call. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100208GRPCAPI grpc_call *grpc_channel_create_registered_call(
Craig Tiller7536af02015-12-22 13:49:30 -0800209 grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
Craig Tiller3e7c6a72015-07-31 16:17:04 -0700210 grpc_completion_queue *completion_queue, void *registered_call_handle,
Nicolas "Pixel" Noble9d72b142015-08-08 01:45:38 +0200211 gpr_timespec deadline, void *reserved);
Craig Tiller08453372015-04-10 16:05:38 -0700212
Craig Tiller58450912017-03-16 09:42:43 -0700213/** Allocate memory in the grpc_call arena: this memory is automatically
214 discarded at call completion */
215GRPCAPI void *grpc_call_arena_alloc(grpc_call *call, size_t size);
216
Craig Tiller2d984bf2015-07-20 15:01:38 -0700217/** Start a batch of operations defined in the array ops; when complete, post a
218 completion of type 'tag' to the completion queue bound to the call.
219 The order of ops specified in the batch has no significance.
220 Only one operation of each type can be active at once in any given
Nathaniel Manistac00d0f72016-11-30 23:16:42 +0000221 batch.
222 If a call to grpc_call_start_batch returns GRPC_CALL_OK you must call
223 grpc_completion_queue_next or grpc_completion_queue_pluck on the completion
224 queue associated with 'call' for work to be performed. If a call to
225 grpc_call_start_batch returns any value other than GRPC_CALL_OK it is
226 guaranteed that no state associated with 'call' is changed and it is not
227 appropriate to call grpc_completion_queue_next or
228 grpc_completion_queue_pluck consequent to the failed grpc_call_start_batch
229 call.
Craig Tiller2d984bf2015-07-20 15:01:38 -0700230 THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment
231 needs to be synchronized. As an optimization, you may synchronize batches
232 containing just send operations independently from batches containing just
233 receive operations. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100234GRPCAPI grpc_call_error grpc_call_start_batch(grpc_call *call,
235 const grpc_op *ops, size_t nops,
236 void *tag, void *reserved);
Craig Tillerfef76692015-02-02 16:44:26 -0800237
Craig Tiller45249422015-07-20 16:16:35 -0700238/** Returns a newly allocated string representing the endpoint to which this
239 call is communicating with. The string is in the uri format accepted by
240 grpc_channel_create.
Alistair Veitchff32faf2015-07-30 09:54:15 -0700241 The returned string should be disposed of with gpr_free().
Craig Tiller45249422015-07-20 16:16:35 -0700242
243 WARNING: this value is never authenticated or subject to any security
244 related code. It must not be used for any authentication related
245 functionality. Instead, use grpc_auth_context. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100246GRPCAPI char *grpc_call_get_peer(grpc_call *call);
Craig Tiller1b22b9d2015-07-20 13:42:22 -0700247
Alistair Veitchff32faf2015-07-30 09:54:15 -0700248struct census_context;
249
David Garcia Quintasf31f0962017-02-10 14:53:58 -0800250/** Set census context for a call; Must be called before first call to
Alistair Veitchff32faf2015-07-30 09:54:15 -0700251 grpc_call_start_batch(). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100252GRPCAPI void grpc_census_call_set_context(grpc_call *call,
253 struct census_context *context);
Alistair Veitchff32faf2015-07-30 09:54:15 -0700254
David Garcia Quintasf31f0962017-02-10 14:53:58 -0800255/** Retrieve the calls current census context. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100256GRPCAPI struct census_context *grpc_census_call_get_context(grpc_call *call);
Alistair Veitchff32faf2015-07-30 09:54:15 -0700257
Craig Tiller45249422015-07-20 16:16:35 -0700258/** Return a newly allocated string representing the target a channel was
259 created for. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100260GRPCAPI char *grpc_channel_get_target(grpc_channel *channel);
Craig Tiller45249422015-07-20 16:16:35 -0700261
Mark D. Rothf79ce7d2016-11-04 08:43:36 -0700262/** Request info about the channel.
263 \a channel_info indicates what information is being requested and
264 how that information will be returned.
265 \a channel_info is owned by the caller. */
Mark D. Rothb2d24882016-10-27 15:44:07 -0700266GRPCAPI void grpc_channel_get_info(grpc_channel *channel,
Mark D. Rothf79ce7d2016-11-04 08:43:36 -0700267 const grpc_channel_info *channel_info);
Mark D. Rothb2d24882016-10-27 15:44:07 -0700268
Craig Tiller2d984bf2015-07-20 15:01:38 -0700269/** Create a client channel to 'target'. Additional channel level configuration
270 MAY be provided by grpc_channel_args, though the expectation is that most
271 clients will want to simply pass NULL. See grpc_channel_args definition for
272 more on this. The data in 'args' need only live through the invocation of
273 this function. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100274GRPCAPI grpc_channel *grpc_insecure_channel_create(
Craig Tillerd6546c92016-01-29 07:59:35 -0800275 const char *target, const grpc_channel_args *args, void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800276
Craig Tiller2d984bf2015-07-20 15:01:38 -0700277/** Create a lame client: this client fails every operation attempted on it. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100278GRPCAPI grpc_channel *grpc_lame_client_channel_create(
Craig Tillerd6546c92016-01-29 07:59:35 -0800279 const char *target, grpc_status_code error_code, const char *error_message);
Craig Tiller42bc87c2015-02-23 08:50:19 -0800280
Craig Tiller2d984bf2015-07-20 15:01:38 -0700281/** Close and destroy a grpc channel */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100282GRPCAPI void grpc_channel_destroy(grpc_channel *channel);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800283
Alexander Polcynd809a152017-05-03 14:49:41 -0700284/** Error handling for grpc_call
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800285 Most grpc_call functions return a grpc_error. If the error is not GRPC_OK
286 then the operation failed due to some unsatisfied precondition.
287 If a grpc_call fails, it's guaranteed that no change to the call state
288 has been made. */
289
Craig Tiller2d984bf2015-07-20 15:01:38 -0700290/** Called by clients to cancel an RPC on the server.
291 Can be called multiple times, from any thread.
292 THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status
Craig Tillerdd36b152017-03-31 08:27:28 -0700293 are thread-safe, and can be called at any point before grpc_call_unref
Craig Tiller2d984bf2015-07-20 15:01:38 -0700294 is called.*/
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100295GRPCAPI grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800296
Craig Tiller2d984bf2015-07-20 15:01:38 -0700297/** Called by clients to cancel an RPC on the server.
298 Can be called multiple times, from any thread.
299 If a status has not been received for the call, set it to the status code
300 and description passed in.
301 Importantly, this function does not send status nor description to the
Alexander Polcyn088e85c2017-07-28 14:53:20 -0700302 remote endpoint.
303 Note that \a description doesn't need be a static string.
304 It doesn't need to be alive after the call to
305 grpc_call_cancel_with_status completes.
306 */
Craig Tillerf40df232016-03-25 13:38:14 -0700307GRPCAPI grpc_call_error grpc_call_cancel_with_status(grpc_call *call,
308 grpc_status_code status,
309 const char *description,
310 void *reserved);
Craig Tillerd248c242015-01-14 11:49:12 -0800311
Craig Tillerdd36b152017-03-31 08:27:28 -0700312/** Ref a call.
313 THREAD SAFETY: grpc_call_unref is thread-compatible */
314GRPCAPI void grpc_call_ref(grpc_call *call);
315
316/** Unref a call.
317 THREAD SAFETY: grpc_call_unref is thread-compatible */
318GRPCAPI void grpc_call_unref(grpc_call *call);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800319
David G. Quintasb2a1c592015-08-20 14:44:27 -0700320/** Request notification of a new call.
Craig Tillerddf3a512015-09-24 13:03:44 -0700321 Once a call is received, a notification tagged with \a tag_new is added to
322 \a cq_for_notification. \a call, \a details and \a request_metadata are
Craig Tiller1359a122015-08-24 14:43:32 -0700323 updated with the appropriate call information. \a cq_bound_to_call is bound
324 to \a call, and batch operation notifications for that call will be posted
325 to \a cq_bound_to_call.
David G. Quintasb2a1c592015-08-20 14:44:27 -0700326 Note that \a cq_for_notification must have been registered to the server via
327 \a grpc_server_register_completion_queue. */
Craig Tillerf40df232016-03-25 13:38:14 -0700328GRPCAPI grpc_call_error grpc_server_request_call(
329 grpc_server *server, grpc_call **call, grpc_call_details *details,
330 grpc_metadata_array *request_metadata,
331 grpc_completion_queue *cq_bound_to_call,
332 grpc_completion_queue *cq_for_notification, void *tag_new);
Craig Tiller034929c2015-02-02 16:56:15 -0800333
Craig Tiller06cb1a92016-04-04 08:10:47 -0700334/** How to handle payloads for a registered method */
335typedef enum {
336 /** Don't try to read the payload */
337 GRPC_SRM_PAYLOAD_NONE,
338 /** Read the initial payload as a byte buffer */
339 GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER
340} grpc_server_register_method_payload_handling;
341
Craig Tiller2d984bf2015-07-20 15:01:38 -0700342/** Registers a method in the server.
343 Methods to this (host, method) pair will not be reported by
344 grpc_server_request_call, but instead be reported by
345 grpc_server_request_registered_call when passed the appropriate
346 registered_method (as returned by this function).
347 Must be called before grpc_server_start.
348 Returns NULL on failure. */
Craig Tiller06cb1a92016-04-04 08:10:47 -0700349GRPCAPI void *grpc_server_register_method(
350 grpc_server *server, const char *method, const char *host,
351 grpc_server_register_method_payload_handling payload_handling,
352 uint32_t flags);
Craig Tiller24be0f72015-02-10 14:04:22 -0800353
Alistair Veitchff32faf2015-07-30 09:54:15 -0700354/** Request notification of a new pre-registered call. 'cq_for_notification'
355 must have been registered to the server via
Craig Tiller2d984bf2015-07-20 15:01:38 -0700356 grpc_server_register_completion_queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100357GRPCAPI grpc_call_error grpc_server_request_registered_call(
Craig Tiller24be0f72015-02-10 14:04:22 -0800358 grpc_server *server, void *registered_method, grpc_call **call,
359 gpr_timespec *deadline, grpc_metadata_array *request_metadata,
360 grpc_byte_buffer **optional_payload,
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700361 grpc_completion_queue *cq_bound_to_call,
362 grpc_completion_queue *cq_for_notification, void *tag_new);
Craig Tiller24be0f72015-02-10 14:04:22 -0800363
Craig Tiller2d984bf2015-07-20 15:01:38 -0700364/** Create a server. Additional configuration for each incoming channel can
365 be specified with args. If no additional configuration is needed, args can
366 be NULL. See grpc_channel_args for more. The data in 'args' need only live
367 through the invocation of this function. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100368GRPCAPI grpc_server *grpc_server_create(const grpc_channel_args *args,
369 void *reserved);
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700370
Craig Tiller2d984bf2015-07-20 15:01:38 -0700371/** Register a completion queue with the server. Must be done for any
372 notification completion queue that is passed to grpc_server_request_*_call
373 and to grpc_server_shutdown_and_notify. Must be performed prior to
374 grpc_server_start. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100375GRPCAPI void grpc_server_register_completion_queue(grpc_server *server,
376 grpc_completion_queue *cq,
377 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800378
Craig Tiller2d984bf2015-07-20 15:01:38 -0700379/** Add a HTTP2 over plaintext over tcp listener.
380 Returns bound port number on success, 0 on failure.
381 REQUIRES: server not started */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100382GRPCAPI int grpc_server_add_insecure_http2_port(grpc_server *server,
383 const char *addr);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800384
Craig Tiller2d984bf2015-07-20 15:01:38 -0700385/** Start a server - tells all listeners to start listening */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100386GRPCAPI void grpc_server_start(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800387
Craig Tiller2d984bf2015-07-20 15:01:38 -0700388/** Begin shutting down a server.
389 After completion, no new calls or connections will be admitted.
390 Existing calls will be allowed to complete.
391 Send a GRPC_OP_COMPLETE event when there are no more calls being serviced.
392 Shutdown is idempotent, and all tags will be notified at once if multiple
393 grpc_server_shutdown_and_notify calls are made. 'cq' must have been
394 registered to this server via grpc_server_register_completion_queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100395GRPCAPI void grpc_server_shutdown_and_notify(grpc_server *server,
396 grpc_completion_queue *cq,
397 void *tag);
Craig Tiller4ffdcd52015-01-16 11:34:55 -0800398
Craig Tiller2d984bf2015-07-20 15:01:38 -0700399/** Cancel all in-progress calls.
400 Only usable after shutdown. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100401GRPCAPI void grpc_server_cancel_all_calls(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800402
Craig Tiller2d984bf2015-07-20 15:01:38 -0700403/** Destroy a server.
404 Shutdown must have completed beforehand (i.e. all tags generated by
405 grpc_server_shutdown_and_notify must have been received, and at least
406 one call to grpc_server_shutdown_and_notify must have been made). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100407GRPCAPI void grpc_server_destroy(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800408
Craig Tilleraf7abf92015-06-03 17:18:58 -0700409/** Enable or disable a tracer.
410
411 Tracers (usually controlled by the environment variable GRPC_TRACE)
412 allow printf-style debugging on GRPC internals, and are useful for
Craig Tiller9a576332015-06-17 10:21:49 -0700413 tracking down problems in the field.
Craig Tilleraf7abf92015-06-03 17:18:58 -0700414
Craig Tiller9a576332015-06-17 10:21:49 -0700415 Use of this function is not strictly thread-safe, but the
Craig Tilleraf7abf92015-06-03 17:18:58 -0700416 thread-safety issues raised by it should not be of concern. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100417GRPCAPI int grpc_tracer_set_enabled(const char *name, int enabled);
Craig Tilleraf7abf92015-06-03 17:18:58 -0700418
murgatroid99c3910ca2016-01-06 13:14:23 -0800419/** Check whether a metadata key is legal (will be accepted by core) */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800420GRPCAPI int grpc_header_key_is_legal(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800421
422/** Check whether a non-binary metadata value is legal (will be accepted by
423 core) */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800424GRPCAPI int grpc_header_nonbin_value_is_legal(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800425
426/** Check whether a metadata key corresponds to a binary value */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800427GRPCAPI int grpc_is_binary_header(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800428
Yuchen Zeng2e7d9572016-04-15 17:29:57 -0700429/** Convert grpc_call_error values to a string */
430GRPCAPI const char *grpc_call_error_to_string(grpc_call_error error);
431
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700432/** Create a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700433GRPCAPI grpc_resource_quota *grpc_resource_quota_create(const char *trace_name);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700434
435/** Add a reference to a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700436GRPCAPI void grpc_resource_quota_ref(grpc_resource_quota *resource_quota);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700437
438/** Drop a reference to a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700439GRPCAPI void grpc_resource_quota_unref(grpc_resource_quota *resource_quota);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700440
441/** Update the size of a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700442GRPCAPI void grpc_resource_quota_resize(grpc_resource_quota *resource_quota,
443 size_t new_size);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700444
Craig Tiller20afa3d2016-10-17 14:52:14 -0700445/** Fetch a vtable for a grpc_channel_arg that points to a grpc_resource_quota
446 */
447GRPCAPI const grpc_arg_pointer_vtable *grpc_resource_quota_arg_vtable(void);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700448
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800449#ifdef __cplusplus
450}
451#endif
452
Craig Tillerb20111c2015-04-10 23:27:11 +0000453#endif /* GRPC_GRPC_H */