blob: f083bc591e671bdd8272e1959272a0099fa8fb93 [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
Craig Tillerbaa14a92017-11-03 09:09:36 -070043GRPCAPI 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
Craig Tillerbaa14a92017-11-03 09:09:36 -070046GRPCAPI 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 */
Craig Tillerbaa14a92017-11-03 09:09:36 -070076GRPCAPI 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 */
Craig Tillerbaa14a92017-11-03 09:09:36 -070079GRPCAPI const char* grpc_g_stands_for(void);
Craig Tiller8dfdb7e2016-08-29 11:25:56 -070080
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 */
Craig Tillerbaa14a92017-11-03 09:09:36 -070083GRPCAPI const grpc_completion_queue_factory*
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070084grpc_completion_queue_factory_lookup(
Craig Tillerbaa14a92017-11-03 09:09:36 -070085 const grpc_completion_queue_attributes* attributes);
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070086
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 */
Craig Tillerbaa14a92017-11-03 09:09:36 -070089GRPCAPI grpc_completion_queue* grpc_completion_queue_create_for_next(
90 void* reserved);
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070091
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 */
Craig Tillerbaa14a92017-11-03 09:09:36 -070094GRPCAPI grpc_completion_queue* grpc_completion_queue_create_for_pluck(
95 void* reserved);
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070096
Sree Kuchibhotla7a4e5b42017-02-17 09:28:46 -080097/** Create a completion queue */
Craig Tillerbaa14a92017-11-03 09:09:36 -070098GRPCAPI grpc_completion_queue* grpc_completion_queue_create(
99 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. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700110GRPCAPI grpc_event grpc_completion_queue_next(grpc_completion_queue* cq,
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100111 gpr_timespec deadline,
Craig Tillerbaa14a92017-11-03 09:09:36 -0700112 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. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700125GRPCAPI 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. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700140GRPCAPI 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 */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700144GRPCAPI void grpc_completion_queue_destroy(grpc_completion_queue* cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800145
Ken Payson42bd87e2017-10-20 10:32:30 -0700146/*********** EXPERIMENTAL API ************/
147/** Initializes a thread local cache for \a cq.
Craig Tillerbaa14a92017-11-03 09:09:36 -0700148 * grpc_flush_cq_tls_cache() MUST be called on the same thread,
149 * with the same cq.
150 */
Ken Payson42bd87e2017-10-20 10:32:30 -0700151GRPCAPI void grpc_completion_queue_thread_local_cache_init(
Craig Tillerbaa14a92017-11-03 09:09:36 -0700152 grpc_completion_queue* cq);
Ken Payson42bd87e2017-10-20 10:32:30 -0700153
154/*********** EXPERIMENTAL API ************/
155/** Flushes the thread local cache for \a cq.
Craig Tillerbaa14a92017-11-03 09:09:36 -0700156 * Returns 1 if there was contents in the cache. If there was an event
157 * in \a cq tls cache, its tag is placed in tag, and ok is set to the
158 * event success.
159 */
Ken Payson42bd87e2017-10-20 10:32:30 -0700160GRPCAPI int grpc_completion_queue_thread_local_cache_flush(
Craig Tillerbaa14a92017-11-03 09:09:36 -0700161 grpc_completion_queue* cq, void** tag, int* ok);
Ken Payson42bd87e2017-10-20 10:32:30 -0700162
Vijay Pai58c33ba2017-09-01 14:08:42 -0700163/** Create a completion queue alarm instance */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700164GRPCAPI grpc_alarm* grpc_alarm_create(void* reserved);
Vijay Pai58c33ba2017-09-01 14:08:42 -0700165
166/** Set a completion queue alarm instance associated to \a cq.
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700167 *
David Garcia Quintas7fd0fd52015-10-07 17:41:08 -0700168 * Once the alarm expires (at \a deadline) or it's cancelled (see \a
169 * grpc_alarm_cancel), an event with tag \a tag will be added to \a cq. If the
170 * alarm expired, the event's success bit will be true, false otherwise (ie,
171 * upon cancellation). */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700172GRPCAPI void grpc_alarm_set(grpc_alarm* alarm, grpc_completion_queue* cq,
173 gpr_timespec deadline, void* tag, void* reserved);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700174
David Garcia Quintas7fd0fd52015-10-07 17:41:08 -0700175/** Cancel a completion queue alarm. Calling this function over an alarm that
176 * has already fired has no effect. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700177GRPCAPI void grpc_alarm_cancel(grpc_alarm* alarm, void* reserved);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700178
179/** Destroy the given completion queue alarm, cancelling it in the process. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700180GRPCAPI void grpc_alarm_destroy(grpc_alarm* alarm, void* reserved);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700181
Craig Tiller48cb07c2015-07-15 16:16:15 -0700182/** Check the connectivity state of a channel. */
Craig Tillerf40df232016-03-25 13:38:14 -0700183GRPCAPI grpc_connectivity_state grpc_channel_check_connectivity_state(
Craig Tillerbaa14a92017-11-03 09:09:36 -0700184 grpc_channel* channel, int try_to_connect);
Craig Tiller48cb07c2015-07-15 16:16:15 -0700185
Alexander Polcync3b1f182017-04-18 13:51:36 -0700186/** Number of active "external connectivity state watchers" attached to a
187 * channel.
188 * Useful for testing. **/
189GRPCAPI int grpc_channel_num_external_connectivity_watchers(
Craig Tillerbaa14a92017-11-03 09:09:36 -0700190 grpc_channel* channel);
Alexander Polcync3b1f182017-04-18 13:51:36 -0700191
Craig Tiller48cb07c2015-07-15 16:16:15 -0700192/** Watch for a change in connectivity state.
193 Once the channel connectivity state is different from last_observed_state,
194 tag will be enqueued on cq with success=1.
195 If deadline expires BEFORE the state is changed, tag will be enqueued on cq
Craig Tiller2cd9dd92015-07-31 16:34:37 -0700196 with success=0. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100197GRPCAPI void grpc_channel_watch_connectivity_state(
Craig Tillerbaa14a92017-11-03 09:09:36 -0700198 grpc_channel* channel, grpc_connectivity_state last_observed_state,
199 gpr_timespec deadline, grpc_completion_queue* cq, void* tag);
Craig Tiller48cb07c2015-07-15 16:16:15 -0700200
Yuchen Zenga2e506e2017-08-22 16:45:44 -0700201/** Check whether a grpc channel supports connectivity watcher */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700202GRPCAPI int grpc_channel_support_connectivity_watcher(grpc_channel* channel);
Yuchen Zeng6a6d6182017-08-22 13:43:38 -0700203
Craig Tiller2d984bf2015-07-20 15:01:38 -0700204/** Create a call given a grpc_channel, in order to call 'method'. All
205 completions are sent to 'completion_queue'. 'method' and 'host' need only
Craig Tiller58471772015-07-31 17:12:34 -0700206 live through the invocation of this function.
207 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 -0700208 to propagate properties from the server call to this new client call,
209 depending on the value of \a propagation_mask (see propagation_bits.h for
210 possible values). */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700211GRPCAPI grpc_call* grpc_channel_create_call(
212 grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask,
213 grpc_completion_queue* completion_queue, grpc_slice method,
214 const grpc_slice* host, gpr_timespec deadline, void* reserved);
Craig Tiller034929c2015-02-02 16:56:15 -0800215
Craig Tillere2c62372015-12-07 16:11:03 -0800216/** Ping the channels peer (load balanced channels will select one sub-channel
Craig Tiller26dab312015-12-07 14:43:47 -0800217 to ping); if the channel is not connected, posts a failed. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700218GRPCAPI void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq,
219 void* tag, void* reserved);
Craig Tiller26dab312015-12-07 14:43:47 -0800220
Craig Tiller2d984bf2015-07-20 15:01:38 -0700221/** Pre-register a method/host pair on a channel. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700222GRPCAPI void* grpc_channel_register_call(grpc_channel* channel,
223 const char* method, const char* host,
224 void* reserved);
Craig Tiller08453372015-04-10 16:05:38 -0700225
David Garcia Quintas15eba132016-08-09 15:20:48 -0700226/** Create a call given a handle returned from grpc_channel_register_call.
227 \sa grpc_channel_create_call. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700228GRPCAPI grpc_call* grpc_channel_create_registered_call(
229 grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask,
230 grpc_completion_queue* completion_queue, void* registered_call_handle,
231 gpr_timespec deadline, void* reserved);
Craig Tiller08453372015-04-10 16:05:38 -0700232
Craig Tiller58450912017-03-16 09:42:43 -0700233/** Allocate memory in the grpc_call arena: this memory is automatically
234 discarded at call completion */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700235GRPCAPI void* grpc_call_arena_alloc(grpc_call* call, size_t size);
Craig Tiller58450912017-03-16 09:42:43 -0700236
Craig Tiller2d984bf2015-07-20 15:01:38 -0700237/** Start a batch of operations defined in the array ops; when complete, post a
238 completion of type 'tag' to the completion queue bound to the call.
239 The order of ops specified in the batch has no significance.
240 Only one operation of each type can be active at once in any given
Nathaniel Manistac00d0f72016-11-30 23:16:42 +0000241 batch.
242 If a call to grpc_call_start_batch returns GRPC_CALL_OK you must call
243 grpc_completion_queue_next or grpc_completion_queue_pluck on the completion
244 queue associated with 'call' for work to be performed. If a call to
245 grpc_call_start_batch returns any value other than GRPC_CALL_OK it is
246 guaranteed that no state associated with 'call' is changed and it is not
247 appropriate to call grpc_completion_queue_next or
248 grpc_completion_queue_pluck consequent to the failed grpc_call_start_batch
249 call.
Craig Tiller2d984bf2015-07-20 15:01:38 -0700250 THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment
251 needs to be synchronized. As an optimization, you may synchronize batches
252 containing just send operations independently from batches containing just
253 receive operations. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700254GRPCAPI grpc_call_error grpc_call_start_batch(grpc_call* call,
255 const grpc_op* ops, size_t nops,
256 void* tag, void* reserved);
Craig Tillerfef76692015-02-02 16:44:26 -0800257
Craig Tiller45249422015-07-20 16:16:35 -0700258/** Returns a newly allocated string representing the endpoint to which this
259 call is communicating with. The string is in the uri format accepted by
260 grpc_channel_create.
Alistair Veitchff32faf2015-07-30 09:54:15 -0700261 The returned string should be disposed of with gpr_free().
Craig Tiller45249422015-07-20 16:16:35 -0700262
263 WARNING: this value is never authenticated or subject to any security
264 related code. It must not be used for any authentication related
265 functionality. Instead, use grpc_auth_context. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700266GRPCAPI char* grpc_call_get_peer(grpc_call* call);
Craig Tiller1b22b9d2015-07-20 13:42:22 -0700267
Alistair Veitchff32faf2015-07-30 09:54:15 -0700268struct census_context;
269
David Garcia Quintasf31f0962017-02-10 14:53:58 -0800270/** Set census context for a call; Must be called before first call to
Alistair Veitchff32faf2015-07-30 09:54:15 -0700271 grpc_call_start_batch(). */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700272GRPCAPI void grpc_census_call_set_context(grpc_call* call,
273 struct census_context* context);
Alistair Veitchff32faf2015-07-30 09:54:15 -0700274
David Garcia Quintasf31f0962017-02-10 14:53:58 -0800275/** Retrieve the calls current census context. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700276GRPCAPI struct census_context* grpc_census_call_get_context(grpc_call* call);
Alistair Veitchff32faf2015-07-30 09:54:15 -0700277
Craig Tiller45249422015-07-20 16:16:35 -0700278/** Return a newly allocated string representing the target a channel was
279 created for. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700280GRPCAPI char* grpc_channel_get_target(grpc_channel* channel);
Craig Tiller45249422015-07-20 16:16:35 -0700281
Mark D. Rothf79ce7d2016-11-04 08:43:36 -0700282/** Request info about the channel.
283 \a channel_info indicates what information is being requested and
284 how that information will be returned.
285 \a channel_info is owned by the caller. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700286GRPCAPI void grpc_channel_get_info(grpc_channel* channel,
287 const grpc_channel_info* channel_info);
Mark D. Rothb2d24882016-10-27 15:44:07 -0700288
Craig Tiller2d984bf2015-07-20 15:01:38 -0700289/** Create a client channel to 'target'. Additional channel level configuration
290 MAY be provided by grpc_channel_args, though the expectation is that most
291 clients will want to simply pass NULL. See grpc_channel_args definition for
292 more on this. The data in 'args' need only live through the invocation of
293 this function. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700294GRPCAPI grpc_channel* grpc_insecure_channel_create(
295 const char* target, const grpc_channel_args* args, void* reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800296
Craig Tiller2d984bf2015-07-20 15:01:38 -0700297/** Create a lame client: this client fails every operation attempted on it. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700298GRPCAPI grpc_channel* grpc_lame_client_channel_create(
299 const char* target, grpc_status_code error_code, const char* error_message);
Craig Tiller42bc87c2015-02-23 08:50:19 -0800300
Craig Tiller2d984bf2015-07-20 15:01:38 -0700301/** Close and destroy a grpc channel */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700302GRPCAPI void grpc_channel_destroy(grpc_channel* channel);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800303
Alexander Polcynd809a152017-05-03 14:49:41 -0700304/** Error handling for grpc_call
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800305 Most grpc_call functions return a grpc_error. If the error is not GRPC_OK
306 then the operation failed due to some unsatisfied precondition.
307 If a grpc_call fails, it's guaranteed that no change to the call state
308 has been made. */
309
Craig Tiller2d984bf2015-07-20 15:01:38 -0700310/** Called by clients to cancel an RPC on the server.
311 Can be called multiple times, from any thread.
312 THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status
Craig Tillerdd36b152017-03-31 08:27:28 -0700313 are thread-safe, and can be called at any point before grpc_call_unref
Craig Tiller2d984bf2015-07-20 15:01:38 -0700314 is called.*/
Craig Tillerbaa14a92017-11-03 09:09:36 -0700315GRPCAPI grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800316
Craig Tiller2d984bf2015-07-20 15:01:38 -0700317/** Called by clients to cancel an RPC on the server.
318 Can be called multiple times, from any thread.
319 If a status has not been received for the call, set it to the status code
320 and description passed in.
321 Importantly, this function does not send status nor description to the
Alexander Polcyn088e85c2017-07-28 14:53:20 -0700322 remote endpoint.
323 Note that \a description doesn't need be a static string.
324 It doesn't need to be alive after the call to
325 grpc_call_cancel_with_status completes.
326 */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700327GRPCAPI grpc_call_error grpc_call_cancel_with_status(grpc_call* call,
Craig Tillerf40df232016-03-25 13:38:14 -0700328 grpc_status_code status,
Craig Tillerbaa14a92017-11-03 09:09:36 -0700329 const char* description,
330 void* reserved);
Craig Tillerd248c242015-01-14 11:49:12 -0800331
Craig Tillerdd36b152017-03-31 08:27:28 -0700332/** Ref a call.
Eric Dobson60092b02017-09-24 11:09:05 -0700333 THREAD SAFETY: grpc_call_ref is thread-compatible */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700334GRPCAPI void grpc_call_ref(grpc_call* call);
Craig Tillerdd36b152017-03-31 08:27:28 -0700335
336/** Unref a call.
337 THREAD SAFETY: grpc_call_unref is thread-compatible */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700338GRPCAPI void grpc_call_unref(grpc_call* call);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800339
David G. Quintasb2a1c592015-08-20 14:44:27 -0700340/** Request notification of a new call.
Craig Tillerddf3a512015-09-24 13:03:44 -0700341 Once a call is received, a notification tagged with \a tag_new is added to
342 \a cq_for_notification. \a call, \a details and \a request_metadata are
Craig Tiller1359a122015-08-24 14:43:32 -0700343 updated with the appropriate call information. \a cq_bound_to_call is bound
344 to \a call, and batch operation notifications for that call will be posted
345 to \a cq_bound_to_call.
David G. Quintasb2a1c592015-08-20 14:44:27 -0700346 Note that \a cq_for_notification must have been registered to the server via
347 \a grpc_server_register_completion_queue. */
Craig Tillerf40df232016-03-25 13:38:14 -0700348GRPCAPI grpc_call_error grpc_server_request_call(
Craig Tillerbaa14a92017-11-03 09:09:36 -0700349 grpc_server* server, grpc_call** call, grpc_call_details* details,
350 grpc_metadata_array* request_metadata,
351 grpc_completion_queue* cq_bound_to_call,
352 grpc_completion_queue* cq_for_notification, void* tag_new);
Craig Tiller034929c2015-02-02 16:56:15 -0800353
Craig Tiller06cb1a92016-04-04 08:10:47 -0700354/** How to handle payloads for a registered method */
355typedef enum {
356 /** Don't try to read the payload */
357 GRPC_SRM_PAYLOAD_NONE,
358 /** Read the initial payload as a byte buffer */
359 GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER
360} grpc_server_register_method_payload_handling;
361
Craig Tiller2d984bf2015-07-20 15:01:38 -0700362/** Registers a method in the server.
363 Methods to this (host, method) pair will not be reported by
364 grpc_server_request_call, but instead be reported by
365 grpc_server_request_registered_call when passed the appropriate
366 registered_method (as returned by this function).
367 Must be called before grpc_server_start.
368 Returns NULL on failure. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700369GRPCAPI void* grpc_server_register_method(
370 grpc_server* server, const char* method, const char* host,
Craig Tiller06cb1a92016-04-04 08:10:47 -0700371 grpc_server_register_method_payload_handling payload_handling,
372 uint32_t flags);
Craig Tiller24be0f72015-02-10 14:04:22 -0800373
Alistair Veitchff32faf2015-07-30 09:54:15 -0700374/** Request notification of a new pre-registered call. 'cq_for_notification'
375 must have been registered to the server via
Craig Tiller2d984bf2015-07-20 15:01:38 -0700376 grpc_server_register_completion_queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100377GRPCAPI grpc_call_error grpc_server_request_registered_call(
Craig Tillerbaa14a92017-11-03 09:09:36 -0700378 grpc_server* server, void* registered_method, grpc_call** call,
379 gpr_timespec* deadline, grpc_metadata_array* request_metadata,
380 grpc_byte_buffer** optional_payload,
381 grpc_completion_queue* cq_bound_to_call,
382 grpc_completion_queue* cq_for_notification, void* tag_new);
Craig Tiller24be0f72015-02-10 14:04:22 -0800383
Craig Tiller2d984bf2015-07-20 15:01:38 -0700384/** Create a server. Additional configuration for each incoming channel can
385 be specified with args. If no additional configuration is needed, args can
386 be NULL. See grpc_channel_args for more. The data in 'args' need only live
387 through the invocation of this function. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700388GRPCAPI grpc_server* grpc_server_create(const grpc_channel_args* args,
389 void* reserved);
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700390
Craig Tiller2d984bf2015-07-20 15:01:38 -0700391/** Register a completion queue with the server. Must be done for any
392 notification completion queue that is passed to grpc_server_request_*_call
393 and to grpc_server_shutdown_and_notify. Must be performed prior to
394 grpc_server_start. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700395GRPCAPI void grpc_server_register_completion_queue(grpc_server* server,
396 grpc_completion_queue* cq,
397 void* reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800398
Craig Tiller2d984bf2015-07-20 15:01:38 -0700399/** Add a HTTP2 over plaintext over tcp listener.
400 Returns bound port number on success, 0 on failure.
401 REQUIRES: server not started */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700402GRPCAPI int grpc_server_add_insecure_http2_port(grpc_server* server,
403 const char* addr);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800404
Craig Tiller2d984bf2015-07-20 15:01:38 -0700405/** Start a server - tells all listeners to start listening */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700406GRPCAPI void grpc_server_start(grpc_server* server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800407
Craig Tiller2d984bf2015-07-20 15:01:38 -0700408/** Begin shutting down a server.
409 After completion, no new calls or connections will be admitted.
410 Existing calls will be allowed to complete.
411 Send a GRPC_OP_COMPLETE event when there are no more calls being serviced.
412 Shutdown is idempotent, and all tags will be notified at once if multiple
413 grpc_server_shutdown_and_notify calls are made. 'cq' must have been
414 registered to this server via grpc_server_register_completion_queue. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700415GRPCAPI void grpc_server_shutdown_and_notify(grpc_server* server,
416 grpc_completion_queue* cq,
417 void* tag);
Craig Tiller4ffdcd52015-01-16 11:34:55 -0800418
Craig Tiller2d984bf2015-07-20 15:01:38 -0700419/** Cancel all in-progress calls.
420 Only usable after shutdown. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700421GRPCAPI void grpc_server_cancel_all_calls(grpc_server* server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800422
Craig Tiller2d984bf2015-07-20 15:01:38 -0700423/** Destroy a server.
424 Shutdown must have completed beforehand (i.e. all tags generated by
425 grpc_server_shutdown_and_notify must have been received, and at least
426 one call to grpc_server_shutdown_and_notify must have been made). */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700427GRPCAPI void grpc_server_destroy(grpc_server* server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800428
Craig Tilleraf7abf92015-06-03 17:18:58 -0700429/** Enable or disable a tracer.
430
431 Tracers (usually controlled by the environment variable GRPC_TRACE)
432 allow printf-style debugging on GRPC internals, and are useful for
Craig Tiller9a576332015-06-17 10:21:49 -0700433 tracking down problems in the field.
Craig Tilleraf7abf92015-06-03 17:18:58 -0700434
Craig Tiller9a576332015-06-17 10:21:49 -0700435 Use of this function is not strictly thread-safe, but the
Craig Tilleraf7abf92015-06-03 17:18:58 -0700436 thread-safety issues raised by it should not be of concern. */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700437GRPCAPI int grpc_tracer_set_enabled(const char* name, int enabled);
Craig Tilleraf7abf92015-06-03 17:18:58 -0700438
murgatroid99c3910ca2016-01-06 13:14:23 -0800439/** Check whether a metadata key is legal (will be accepted by core) */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800440GRPCAPI int grpc_header_key_is_legal(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800441
442/** Check whether a non-binary metadata value is legal (will be accepted by
443 core) */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800444GRPCAPI int grpc_header_nonbin_value_is_legal(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800445
446/** Check whether a metadata key corresponds to a binary value */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800447GRPCAPI int grpc_is_binary_header(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800448
Yuchen Zeng2e7d9572016-04-15 17:29:57 -0700449/** Convert grpc_call_error values to a string */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700450GRPCAPI const char* grpc_call_error_to_string(grpc_call_error error);
Yuchen Zeng2e7d9572016-04-15 17:29:57 -0700451
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700452/** Create a buffer pool */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700453GRPCAPI grpc_resource_quota* grpc_resource_quota_create(const char* trace_name);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700454
455/** Add a reference to a buffer pool */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700456GRPCAPI void grpc_resource_quota_ref(grpc_resource_quota* resource_quota);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700457
458/** Drop a reference to a buffer pool */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700459GRPCAPI void grpc_resource_quota_unref(grpc_resource_quota* resource_quota);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700460
461/** Update the size of a buffer pool */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700462GRPCAPI void grpc_resource_quota_resize(grpc_resource_quota* resource_quota,
Craig Tiller20afa3d2016-10-17 14:52:14 -0700463 size_t new_size);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700464
Craig Tiller20afa3d2016-10-17 14:52:14 -0700465/** Fetch a vtable for a grpc_channel_arg that points to a grpc_resource_quota
466 */
Craig Tillerbaa14a92017-11-03 09:09:36 -0700467GRPCAPI const grpc_arg_pointer_vtable* grpc_resource_quota_arg_vtable(void);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700468
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800469#ifdef __cplusplus
470}
471#endif
472
Craig Tillerb20111c2015-04-10 23:27:11 +0000473#endif /* GRPC_GRPC_H */