blob: 1de289fba45d0aac4e5d30f91fd137a65ee8a2b7 [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
Yuchen Zenga2e506e2017-08-22 16:45:44 -0700184/** Check whether a grpc channel supports connectivity watcher */
Yuchen Zeng6a6d6182017-08-22 13:43:38 -0700185GRPCAPI int grpc_channel_support_connectivity_watcher(grpc_channel *channel);
186
Craig Tiller2d984bf2015-07-20 15:01:38 -0700187/** Create a call given a grpc_channel, in order to call 'method'. All
188 completions are sent to 'completion_queue'. 'method' and 'host' need only
Craig Tiller58471772015-07-31 17:12:34 -0700189 live through the invocation of this function.
190 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 -0700191 to propagate properties from the server call to this new client call,
192 depending on the value of \a propagation_mask (see propagation_bits.h for
193 possible values). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100194GRPCAPI grpc_call *grpc_channel_create_call(
Craig Tillerd6546c92016-01-29 07:59:35 -0800195 grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800196 grpc_completion_queue *completion_queue, grpc_slice method,
197 const grpc_slice *host, gpr_timespec deadline, void *reserved);
Craig Tiller034929c2015-02-02 16:56:15 -0800198
Craig Tillere2c62372015-12-07 16:11:03 -0800199/** Ping the channels peer (load balanced channels will select one sub-channel
Craig Tiller26dab312015-12-07 14:43:47 -0800200 to ping); if the channel is not connected, posts a failed. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100201GRPCAPI void grpc_channel_ping(grpc_channel *channel, grpc_completion_queue *cq,
202 void *tag, void *reserved);
Craig Tiller26dab312015-12-07 14:43:47 -0800203
Craig Tiller2d984bf2015-07-20 15:01:38 -0700204/** Pre-register a method/host pair on a channel. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100205GRPCAPI void *grpc_channel_register_call(grpc_channel *channel,
206 const char *method, const char *host,
207 void *reserved);
Craig Tiller08453372015-04-10 16:05:38 -0700208
David Garcia Quintas15eba132016-08-09 15:20:48 -0700209/** Create a call given a handle returned from grpc_channel_register_call.
210 \sa grpc_channel_create_call. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100211GRPCAPI grpc_call *grpc_channel_create_registered_call(
Craig Tiller7536af02015-12-22 13:49:30 -0800212 grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
Craig Tiller3e7c6a72015-07-31 16:17:04 -0700213 grpc_completion_queue *completion_queue, void *registered_call_handle,
Nicolas "Pixel" Noble9d72b142015-08-08 01:45:38 +0200214 gpr_timespec deadline, void *reserved);
Craig Tiller08453372015-04-10 16:05:38 -0700215
Craig Tiller58450912017-03-16 09:42:43 -0700216/** Allocate memory in the grpc_call arena: this memory is automatically
217 discarded at call completion */
218GRPCAPI void *grpc_call_arena_alloc(grpc_call *call, size_t size);
219
Craig Tiller2d984bf2015-07-20 15:01:38 -0700220/** Start a batch of operations defined in the array ops; when complete, post a
221 completion of type 'tag' to the completion queue bound to the call.
222 The order of ops specified in the batch has no significance.
223 Only one operation of each type can be active at once in any given
Nathaniel Manistac00d0f72016-11-30 23:16:42 +0000224 batch.
225 If a call to grpc_call_start_batch returns GRPC_CALL_OK you must call
226 grpc_completion_queue_next or grpc_completion_queue_pluck on the completion
227 queue associated with 'call' for work to be performed. If a call to
228 grpc_call_start_batch returns any value other than GRPC_CALL_OK it is
229 guaranteed that no state associated with 'call' is changed and it is not
230 appropriate to call grpc_completion_queue_next or
231 grpc_completion_queue_pluck consequent to the failed grpc_call_start_batch
232 call.
Craig Tiller2d984bf2015-07-20 15:01:38 -0700233 THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment
234 needs to be synchronized. As an optimization, you may synchronize batches
235 containing just send operations independently from batches containing just
236 receive operations. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100237GRPCAPI grpc_call_error grpc_call_start_batch(grpc_call *call,
238 const grpc_op *ops, size_t nops,
239 void *tag, void *reserved);
Craig Tillerfef76692015-02-02 16:44:26 -0800240
Craig Tiller45249422015-07-20 16:16:35 -0700241/** Returns a newly allocated string representing the endpoint to which this
242 call is communicating with. The string is in the uri format accepted by
243 grpc_channel_create.
Alistair Veitchff32faf2015-07-30 09:54:15 -0700244 The returned string should be disposed of with gpr_free().
Craig Tiller45249422015-07-20 16:16:35 -0700245
246 WARNING: this value is never authenticated or subject to any security
247 related code. It must not be used for any authentication related
248 functionality. Instead, use grpc_auth_context. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100249GRPCAPI char *grpc_call_get_peer(grpc_call *call);
Craig Tiller1b22b9d2015-07-20 13:42:22 -0700250
Alistair Veitchff32faf2015-07-30 09:54:15 -0700251struct census_context;
252
David Garcia Quintasf31f0962017-02-10 14:53:58 -0800253/** Set census context for a call; Must be called before first call to
Alistair Veitchff32faf2015-07-30 09:54:15 -0700254 grpc_call_start_batch(). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100255GRPCAPI void grpc_census_call_set_context(grpc_call *call,
256 struct census_context *context);
Alistair Veitchff32faf2015-07-30 09:54:15 -0700257
David Garcia Quintasf31f0962017-02-10 14:53:58 -0800258/** Retrieve the calls current census context. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100259GRPCAPI struct census_context *grpc_census_call_get_context(grpc_call *call);
Alistair Veitchff32faf2015-07-30 09:54:15 -0700260
Craig Tiller45249422015-07-20 16:16:35 -0700261/** Return a newly allocated string representing the target a channel was
262 created for. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100263GRPCAPI char *grpc_channel_get_target(grpc_channel *channel);
Craig Tiller45249422015-07-20 16:16:35 -0700264
Mark D. Rothf79ce7d2016-11-04 08:43:36 -0700265/** Request info about the channel.
266 \a channel_info indicates what information is being requested and
267 how that information will be returned.
268 \a channel_info is owned by the caller. */
Mark D. Rothb2d24882016-10-27 15:44:07 -0700269GRPCAPI void grpc_channel_get_info(grpc_channel *channel,
Mark D. Rothf79ce7d2016-11-04 08:43:36 -0700270 const grpc_channel_info *channel_info);
Mark D. Rothb2d24882016-10-27 15:44:07 -0700271
Craig Tiller2d984bf2015-07-20 15:01:38 -0700272/** Create a client channel to 'target'. Additional channel level configuration
273 MAY be provided by grpc_channel_args, though the expectation is that most
274 clients will want to simply pass NULL. See grpc_channel_args definition for
275 more on this. The data in 'args' need only live through the invocation of
276 this function. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100277GRPCAPI grpc_channel *grpc_insecure_channel_create(
Craig Tillerd6546c92016-01-29 07:59:35 -0800278 const char *target, const grpc_channel_args *args, void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800279
Craig Tiller2d984bf2015-07-20 15:01:38 -0700280/** Create a lame client: this client fails every operation attempted on it. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100281GRPCAPI grpc_channel *grpc_lame_client_channel_create(
Craig Tillerd6546c92016-01-29 07:59:35 -0800282 const char *target, grpc_status_code error_code, const char *error_message);
Craig Tiller42bc87c2015-02-23 08:50:19 -0800283
Craig Tiller2d984bf2015-07-20 15:01:38 -0700284/** Close and destroy a grpc channel */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100285GRPCAPI void grpc_channel_destroy(grpc_channel *channel);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800286
Alexander Polcynd809a152017-05-03 14:49:41 -0700287/** Error handling for grpc_call
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800288 Most grpc_call functions return a grpc_error. If the error is not GRPC_OK
289 then the operation failed due to some unsatisfied precondition.
290 If a grpc_call fails, it's guaranteed that no change to the call state
291 has been made. */
292
Craig Tiller2d984bf2015-07-20 15:01:38 -0700293/** Called by clients to cancel an RPC on the server.
294 Can be called multiple times, from any thread.
295 THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status
Craig Tillerdd36b152017-03-31 08:27:28 -0700296 are thread-safe, and can be called at any point before grpc_call_unref
Craig Tiller2d984bf2015-07-20 15:01:38 -0700297 is called.*/
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100298GRPCAPI grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800299
Craig Tiller2d984bf2015-07-20 15:01:38 -0700300/** Called by clients to cancel an RPC on the server.
301 Can be called multiple times, from any thread.
302 If a status has not been received for the call, set it to the status code
303 and description passed in.
304 Importantly, this function does not send status nor description to the
Alexander Polcyn088e85c2017-07-28 14:53:20 -0700305 remote endpoint.
306 Note that \a description doesn't need be a static string.
307 It doesn't need to be alive after the call to
308 grpc_call_cancel_with_status completes.
309 */
Craig Tillerf40df232016-03-25 13:38:14 -0700310GRPCAPI grpc_call_error grpc_call_cancel_with_status(grpc_call *call,
311 grpc_status_code status,
312 const char *description,
313 void *reserved);
Craig Tillerd248c242015-01-14 11:49:12 -0800314
Craig Tillerdd36b152017-03-31 08:27:28 -0700315/** Ref a call.
Eric Dobson60092b02017-09-24 11:09:05 -0700316 THREAD SAFETY: grpc_call_ref is thread-compatible */
Craig Tillerdd36b152017-03-31 08:27:28 -0700317GRPCAPI void grpc_call_ref(grpc_call *call);
318
319/** Unref a call.
320 THREAD SAFETY: grpc_call_unref is thread-compatible */
321GRPCAPI void grpc_call_unref(grpc_call *call);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800322
David G. Quintasb2a1c592015-08-20 14:44:27 -0700323/** Request notification of a new call.
Craig Tillerddf3a512015-09-24 13:03:44 -0700324 Once a call is received, a notification tagged with \a tag_new is added to
325 \a cq_for_notification. \a call, \a details and \a request_metadata are
Craig Tiller1359a122015-08-24 14:43:32 -0700326 updated with the appropriate call information. \a cq_bound_to_call is bound
327 to \a call, and batch operation notifications for that call will be posted
328 to \a cq_bound_to_call.
David G. Quintasb2a1c592015-08-20 14:44:27 -0700329 Note that \a cq_for_notification must have been registered to the server via
330 \a grpc_server_register_completion_queue. */
Craig Tillerf40df232016-03-25 13:38:14 -0700331GRPCAPI grpc_call_error grpc_server_request_call(
332 grpc_server *server, grpc_call **call, grpc_call_details *details,
333 grpc_metadata_array *request_metadata,
334 grpc_completion_queue *cq_bound_to_call,
335 grpc_completion_queue *cq_for_notification, void *tag_new);
Craig Tiller034929c2015-02-02 16:56:15 -0800336
Craig Tiller06cb1a92016-04-04 08:10:47 -0700337/** How to handle payloads for a registered method */
338typedef enum {
339 /** Don't try to read the payload */
340 GRPC_SRM_PAYLOAD_NONE,
341 /** Read the initial payload as a byte buffer */
342 GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER
343} grpc_server_register_method_payload_handling;
344
Craig Tiller2d984bf2015-07-20 15:01:38 -0700345/** Registers a method in the server.
346 Methods to this (host, method) pair will not be reported by
347 grpc_server_request_call, but instead be reported by
348 grpc_server_request_registered_call when passed the appropriate
349 registered_method (as returned by this function).
350 Must be called before grpc_server_start.
351 Returns NULL on failure. */
Craig Tiller06cb1a92016-04-04 08:10:47 -0700352GRPCAPI void *grpc_server_register_method(
353 grpc_server *server, const char *method, const char *host,
354 grpc_server_register_method_payload_handling payload_handling,
355 uint32_t flags);
Craig Tiller24be0f72015-02-10 14:04:22 -0800356
Alistair Veitchff32faf2015-07-30 09:54:15 -0700357/** Request notification of a new pre-registered call. 'cq_for_notification'
358 must have been registered to the server via
Craig Tiller2d984bf2015-07-20 15:01:38 -0700359 grpc_server_register_completion_queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100360GRPCAPI grpc_call_error grpc_server_request_registered_call(
Craig Tiller24be0f72015-02-10 14:04:22 -0800361 grpc_server *server, void *registered_method, grpc_call **call,
362 gpr_timespec *deadline, grpc_metadata_array *request_metadata,
363 grpc_byte_buffer **optional_payload,
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700364 grpc_completion_queue *cq_bound_to_call,
365 grpc_completion_queue *cq_for_notification, void *tag_new);
Craig Tiller24be0f72015-02-10 14:04:22 -0800366
Craig Tiller2d984bf2015-07-20 15:01:38 -0700367/** Create a server. Additional configuration for each incoming channel can
368 be specified with args. If no additional configuration is needed, args can
369 be NULL. See grpc_channel_args for more. The data in 'args' need only live
370 through the invocation of this function. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100371GRPCAPI grpc_server *grpc_server_create(const grpc_channel_args *args,
372 void *reserved);
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700373
Craig Tiller2d984bf2015-07-20 15:01:38 -0700374/** Register a completion queue with the server. Must be done for any
375 notification completion queue that is passed to grpc_server_request_*_call
376 and to grpc_server_shutdown_and_notify. Must be performed prior to
377 grpc_server_start. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100378GRPCAPI void grpc_server_register_completion_queue(grpc_server *server,
379 grpc_completion_queue *cq,
380 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800381
Craig Tiller2d984bf2015-07-20 15:01:38 -0700382/** Add a HTTP2 over plaintext over tcp listener.
383 Returns bound port number on success, 0 on failure.
384 REQUIRES: server not started */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100385GRPCAPI int grpc_server_add_insecure_http2_port(grpc_server *server,
386 const char *addr);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800387
Craig Tiller2d984bf2015-07-20 15:01:38 -0700388/** Start a server - tells all listeners to start listening */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100389GRPCAPI void grpc_server_start(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800390
Craig Tiller2d984bf2015-07-20 15:01:38 -0700391/** Begin shutting down a server.
392 After completion, no new calls or connections will be admitted.
393 Existing calls will be allowed to complete.
394 Send a GRPC_OP_COMPLETE event when there are no more calls being serviced.
395 Shutdown is idempotent, and all tags will be notified at once if multiple
396 grpc_server_shutdown_and_notify calls are made. 'cq' must have been
397 registered to this server via grpc_server_register_completion_queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100398GRPCAPI void grpc_server_shutdown_and_notify(grpc_server *server,
399 grpc_completion_queue *cq,
400 void *tag);
Craig Tiller4ffdcd52015-01-16 11:34:55 -0800401
Craig Tiller2d984bf2015-07-20 15:01:38 -0700402/** Cancel all in-progress calls.
403 Only usable after shutdown. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100404GRPCAPI void grpc_server_cancel_all_calls(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800405
Craig Tiller2d984bf2015-07-20 15:01:38 -0700406/** Destroy a server.
407 Shutdown must have completed beforehand (i.e. all tags generated by
408 grpc_server_shutdown_and_notify must have been received, and at least
409 one call to grpc_server_shutdown_and_notify must have been made). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100410GRPCAPI void grpc_server_destroy(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800411
Craig Tilleraf7abf92015-06-03 17:18:58 -0700412/** Enable or disable a tracer.
413
414 Tracers (usually controlled by the environment variable GRPC_TRACE)
415 allow printf-style debugging on GRPC internals, and are useful for
Craig Tiller9a576332015-06-17 10:21:49 -0700416 tracking down problems in the field.
Craig Tilleraf7abf92015-06-03 17:18:58 -0700417
Craig Tiller9a576332015-06-17 10:21:49 -0700418 Use of this function is not strictly thread-safe, but the
Craig Tilleraf7abf92015-06-03 17:18:58 -0700419 thread-safety issues raised by it should not be of concern. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100420GRPCAPI int grpc_tracer_set_enabled(const char *name, int enabled);
Craig Tilleraf7abf92015-06-03 17:18:58 -0700421
murgatroid99c3910ca2016-01-06 13:14:23 -0800422/** Check whether a metadata key is legal (will be accepted by core) */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800423GRPCAPI int grpc_header_key_is_legal(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800424
425/** Check whether a non-binary metadata value is legal (will be accepted by
426 core) */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800427GRPCAPI int grpc_header_nonbin_value_is_legal(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800428
429/** Check whether a metadata key corresponds to a binary value */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800430GRPCAPI int grpc_is_binary_header(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800431
Yuchen Zeng2e7d9572016-04-15 17:29:57 -0700432/** Convert grpc_call_error values to a string */
433GRPCAPI const char *grpc_call_error_to_string(grpc_call_error error);
434
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700435/** Create a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700436GRPCAPI grpc_resource_quota *grpc_resource_quota_create(const char *trace_name);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700437
438/** Add a reference to a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700439GRPCAPI void grpc_resource_quota_ref(grpc_resource_quota *resource_quota);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700440
441/** Drop a reference to a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700442GRPCAPI void grpc_resource_quota_unref(grpc_resource_quota *resource_quota);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700443
444/** Update the size of a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700445GRPCAPI void grpc_resource_quota_resize(grpc_resource_quota *resource_quota,
446 size_t new_size);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700447
Craig Tiller20afa3d2016-10-17 14:52:14 -0700448/** Fetch a vtable for a grpc_channel_arg that points to a grpc_resource_quota
449 */
450GRPCAPI const grpc_arg_pointer_vtable *grpc_resource_quota_arg_vtable(void);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700451
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800452#ifdef __cplusplus
453}
454#endif
455
Craig Tillerb20111c2015-04-10 23:27:11 +0000456#endif /* GRPC_GRPC_H */