blob: 47d1ea6238085abd8d912d56f3a2262793015a1c [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Sree Kuchibhotla01907122016-04-21 15:09:13 -07003 * Copyright 2015-2016, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
Nicolas "Pixel" Noble1ff52d52015-03-01 05:24:36 +010034#ifndef GRPC_GRPC_H
35#define GRPC_GRPC_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
37#include <grpc/status.h>
38
David Garcia Quintas25d02d52015-06-04 17:40:54 -070039#include <grpc/byte_buffer.h>
Craig Tillerf40df232016-03-25 13:38:14 -070040#include <grpc/impl/codegen/connectivity_state.h>
41#include <grpc/impl/codegen/grpc_types.h>
42#include <grpc/impl/codegen/propagation_bits.h>
Craig Tillerb37d53e2016-10-26 16:16:35 -070043#include <grpc/slice.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080044#include <grpc/support/time.h>
Craig Tillerf40df232016-03-25 13:38:14 -070045#include <stddef.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080046
47#ifdef __cplusplus
48extern "C" {
49#endif
50
Craig Tiller2d984bf2015-07-20 15:01:38 -070051/*! \mainpage GRPC Core
52 *
Craig Tillerd6599a32015-09-03 09:37:02 -070053 * The GRPC Core library is a low-level library designed to be wrapped by higher
54 * level libraries. The top-level API is provided in grpc.h. Security related
55 * functionality lives in grpc_security.h.
Craig Tiller2d984bf2015-07-20 15:01:38 -070056 */
57
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010058GRPCAPI void grpc_metadata_array_init(grpc_metadata_array *array);
59GRPCAPI void grpc_metadata_array_destroy(grpc_metadata_array *array);
Craig Tillerea61b072015-02-03 19:19:27 -080060
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010061GRPCAPI void grpc_call_details_init(grpc_call_details *details);
62GRPCAPI void grpc_call_details_destroy(grpc_call_details *details);
Craig Tillerea61b072015-02-03 19:19:27 -080063
Hongwei Wang85ad6852015-08-13 16:13:10 -070064/** Registers a plugin to be initialized and destroyed with the library.
Hongwei Wanga83d1b32015-08-06 12:52:18 -070065
Craig Tillerd6c98df2015-08-18 09:33:44 -070066 The \a init and \a destroy functions will be invoked as part of
67 \a grpc_init() and \a grpc_shutdown(), respectively.
Hongwei Wang85ad6852015-08-13 16:13:10 -070068 Note that these functions can be invoked an arbitrary number of times
69 (and hence so will \a init and \a destroy).
Craig Tillerd6c98df2015-08-18 09:33:44 -070070 It is safe to pass NULL to either argument. Plugins are destroyed in
Hongwei Wang85ad6852015-08-13 16:13:10 -070071 the reverse order they were initialized. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010072GRPCAPI void grpc_register_plugin(void (*init)(void), void (*destroy)(void));
Hongwei Wanga3780a82015-07-17 15:27:18 -070073
Craig Tillere793ba12015-05-18 09:37:22 -070074/** Initialize the grpc library.
Craig Tiller8674cb12015-06-05 07:09:25 -070075
Craig Tillere793ba12015-05-18 09:37:22 -070076 It is not safe to call any other grpc functions before calling this.
77 (To avoid overhead, little checking is done, and some things may work. We
78 do not warrant that they will continue to do so in future revisions of this
79 library). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010080GRPCAPI void grpc_init(void);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080081
Craig Tillere793ba12015-05-18 09:37:22 -070082/** Shut down the grpc library.
Craig Tiller8674cb12015-06-05 07:09:25 -070083
Craig Tillere793ba12015-05-18 09:37:22 -070084 No memory is used by grpc after this call returns, nor are any instructions
85 executing within the grpc library.
86 Prior to calling, all application owned grpc objects must have been
87 destroyed. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010088GRPCAPI void grpc_shutdown(void);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080089
Craig Tiller2e622bc2015-07-10 07:46:03 -070090/** Return a string representing the current version of grpc */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +010091GRPCAPI const char *grpc_version_string(void);
Craig Tiller2e622bc2015-07-10 07:46:03 -070092
Craig Tiller8dfdb7e2016-08-29 11:25:56 -070093/** Return a string specifying what the 'g' in gRPC stands for */
94GRPCAPI const char *grpc_g_stands_for(void);
95
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070096/** Returns the completion queue factory based on the attributes. MAY return a
97 NULL if no factory can be found */
98GRPCAPI const grpc_completion_queue_factory *
99grpc_completion_queue_factory_lookup(
100 const grpc_completion_queue_attributes *attributes);
101
102/** Helper function to create a completion queue with grpc_cq_completion_type
103 of GRPC_CQ_NEXT and grpc_cq_polling_type of GRPC_CQ_DEFAULT_POLLING */
104GRPCAPI grpc_completion_queue *grpc_completion_queue_create_for_next(
105 void *reserved);
106
107/** Helper function to create a completion queue with grpc_cq_completion_type
108 of GRPC_CQ_PLUCK and grpc_cq_polling_type of GRPC_CQ_DEFAULT_POLLING */
109GRPCAPI grpc_completion_queue *grpc_completion_queue_create_for_pluck(
110 void *reserved);
111
Sree Kuchibhotla7a4e5b42017-02-17 09:28:46 -0800112/** Create a completion queue */
Sree Kuchibhotla321881d2017-02-27 11:25:28 -0800113GRPCAPI grpc_completion_queue *grpc_completion_queue_create(
Sree Kuchibhotla2abbf8a2017-03-21 17:31:03 -0700114 const grpc_completion_queue_factory *factory,
115 const grpc_completion_queue_attributes *attributes, void *reserved);
Sree Kuchibhotla7a4e5b42017-02-17 09:28:46 -0800116
Craig Tillere793ba12015-05-18 09:37:22 -0700117/** Blocks until an event is available, the completion queue is being shut down,
Craig Tiller8674cb12015-06-05 07:09:25 -0700118 or deadline is reached.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800119
vjpai1854d772015-06-08 01:12:29 -0700120 Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout,
121 otherwise a grpc_event describing the event that occurred.
Craig Tillere793ba12015-05-18 09:37:22 -0700122
123 Callers must not call grpc_completion_queue_next and
124 grpc_completion_queue_pluck simultaneously on the same completion queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100125GRPCAPI grpc_event grpc_completion_queue_next(grpc_completion_queue *cq,
126 gpr_timespec deadline,
127 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800128
Craig Tillere793ba12015-05-18 09:37:22 -0700129/** Blocks until an event with tag 'tag' is available, the completion queue is
Craig Tiller8674cb12015-06-05 07:09:25 -0700130 being shutdown or deadline is reached.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800131
vjpai1854d772015-06-08 01:12:29 -0700132 Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout,
133 otherwise a grpc_event describing the event that occurred.
Craig Tillere793ba12015-05-18 09:37:22 -0700134
135 Callers must not call grpc_completion_queue_next and
Hongwei Wang85ad6852015-08-13 16:13:10 -0700136 grpc_completion_queue_pluck simultaneously on the same completion queue.
137
Craig Tiller489df072015-08-01 16:15:45 -0700138 Completion queues support a maximum of GRPC_MAX_COMPLETION_QUEUE_PLUCKERS
139 concurrently executing plucks at any time. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100140GRPCAPI grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq,
141 void *tag, gpr_timespec deadline,
142 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800143
Craig Tiller489df072015-08-01 16:15:45 -0700144/** Maximum number of outstanding grpc_completion_queue_pluck executions per
145 completion queue */
146#define GRPC_MAX_COMPLETION_QUEUE_PLUCKERS 6
147
Craig Tiller2d984bf2015-07-20 15:01:38 -0700148/** Begin destruction of a completion queue. Once all possible events are
149 drained then grpc_completion_queue_next will start to produce
150 GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call
151 grpc_completion_queue_destroy.
Craig Tillerb20111c2015-04-10 23:27:11 +0000152
Craig Tiller2d984bf2015-07-20 15:01:38 -0700153 After calling this function applications should ensure that no
154 NEW work is added to be published on this completion queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100155GRPCAPI void grpc_completion_queue_shutdown(grpc_completion_queue *cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800156
Craig Tiller2d984bf2015-07-20 15:01:38 -0700157/** Destroy a completion queue. The caller must ensure that the queue is
158 drained and no threads are executing grpc_completion_queue_next */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100159GRPCAPI void grpc_completion_queue_destroy(grpc_completion_queue *cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800160
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700161/** Create a completion queue alarm instance associated to \a cq.
162 *
David Garcia Quintas7fd0fd52015-10-07 17:41:08 -0700163 * Once the alarm expires (at \a deadline) or it's cancelled (see \a
164 * grpc_alarm_cancel), an event with tag \a tag will be added to \a cq. If the
165 * alarm expired, the event's success bit will be true, false otherwise (ie,
166 * upon cancellation). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100167GRPCAPI grpc_alarm *grpc_alarm_create(grpc_completion_queue *cq,
168 gpr_timespec deadline, void *tag);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700169
David Garcia Quintas7fd0fd52015-10-07 17:41:08 -0700170/** Cancel a completion queue alarm. Calling this function over an alarm that
171 * has already fired has no effect. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100172GRPCAPI void grpc_alarm_cancel(grpc_alarm *alarm);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700173
174/** Destroy the given completion queue alarm, cancelling it in the process. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100175GRPCAPI void grpc_alarm_destroy(grpc_alarm *alarm);
David Garcia Quintasf747bbc2015-10-04 23:09:47 -0700176
Craig Tiller48cb07c2015-07-15 16:16:15 -0700177/** Check the connectivity state of a channel. */
Craig Tillerf40df232016-03-25 13:38:14 -0700178GRPCAPI grpc_connectivity_state grpc_channel_check_connectivity_state(
179 grpc_channel *channel, int try_to_connect);
Craig Tiller48cb07c2015-07-15 16:16:15 -0700180
Alexander Polcync3b1f182017-04-18 13:51:36 -0700181/** Number of active "external connectivity state watchers" attached to a
182 * channel.
183 * Useful for testing. **/
184GRPCAPI int grpc_channel_num_external_connectivity_watchers(
185 grpc_channel *channel);
186
Craig Tiller48cb07c2015-07-15 16:16:15 -0700187/** Watch for a change in connectivity state.
188 Once the channel connectivity state is different from last_observed_state,
189 tag will be enqueued on cq with success=1.
190 If deadline expires BEFORE the state is changed, tag will be enqueued on cq
Craig Tiller2cd9dd92015-07-31 16:34:37 -0700191 with success=0. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100192GRPCAPI void grpc_channel_watch_connectivity_state(
Craig Tiller48cb07c2015-07-15 16:16:15 -0700193 grpc_channel *channel, grpc_connectivity_state last_observed_state,
Craig Tiller2cd9dd92015-07-31 16:34:37 -0700194 gpr_timespec deadline, grpc_completion_queue *cq, void *tag);
Craig Tiller48cb07c2015-07-15 16:16:15 -0700195
Craig Tiller2d984bf2015-07-20 15:01:38 -0700196/** Create a call given a grpc_channel, in order to call 'method'. All
197 completions are sent to 'completion_queue'. 'method' and 'host' need only
Craig Tiller58471772015-07-31 17:12:34 -0700198 live through the invocation of this function.
199 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 -0700200 to propagate properties from the server call to this new client call,
201 depending on the value of \a propagation_mask (see propagation_bits.h for
202 possible values). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100203GRPCAPI grpc_call *grpc_channel_create_call(
Craig Tillerd6546c92016-01-29 07:59:35 -0800204 grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800205 grpc_completion_queue *completion_queue, grpc_slice method,
206 const grpc_slice *host, gpr_timespec deadline, void *reserved);
Craig Tiller034929c2015-02-02 16:56:15 -0800207
Craig Tillere2c62372015-12-07 16:11:03 -0800208/** Ping the channels peer (load balanced channels will select one sub-channel
Craig Tiller26dab312015-12-07 14:43:47 -0800209 to ping); if the channel is not connected, posts a failed. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100210GRPCAPI void grpc_channel_ping(grpc_channel *channel, grpc_completion_queue *cq,
211 void *tag, void *reserved);
Craig Tiller26dab312015-12-07 14:43:47 -0800212
Craig Tiller2d984bf2015-07-20 15:01:38 -0700213/** Pre-register a method/host pair on a channel. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100214GRPCAPI void *grpc_channel_register_call(grpc_channel *channel,
215 const char *method, const char *host,
216 void *reserved);
Craig Tiller08453372015-04-10 16:05:38 -0700217
David Garcia Quintas15eba132016-08-09 15:20:48 -0700218/** Create a call given a handle returned from grpc_channel_register_call.
219 \sa grpc_channel_create_call. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100220GRPCAPI grpc_call *grpc_channel_create_registered_call(
Craig Tiller7536af02015-12-22 13:49:30 -0800221 grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
Craig Tiller3e7c6a72015-07-31 16:17:04 -0700222 grpc_completion_queue *completion_queue, void *registered_call_handle,
Nicolas "Pixel" Noble9d72b142015-08-08 01:45:38 +0200223 gpr_timespec deadline, void *reserved);
Craig Tiller08453372015-04-10 16:05:38 -0700224
Craig Tiller58450912017-03-16 09:42:43 -0700225/** Allocate memory in the grpc_call arena: this memory is automatically
226 discarded at call completion */
227GRPCAPI void *grpc_call_arena_alloc(grpc_call *call, size_t size);
228
Craig Tiller2d984bf2015-07-20 15:01:38 -0700229/** Start a batch of operations defined in the array ops; when complete, post a
230 completion of type 'tag' to the completion queue bound to the call.
231 The order of ops specified in the batch has no significance.
232 Only one operation of each type can be active at once in any given
Nathaniel Manistac00d0f72016-11-30 23:16:42 +0000233 batch.
234 If a call to grpc_call_start_batch returns GRPC_CALL_OK you must call
235 grpc_completion_queue_next or grpc_completion_queue_pluck on the completion
236 queue associated with 'call' for work to be performed. If a call to
237 grpc_call_start_batch returns any value other than GRPC_CALL_OK it is
238 guaranteed that no state associated with 'call' is changed and it is not
239 appropriate to call grpc_completion_queue_next or
240 grpc_completion_queue_pluck consequent to the failed grpc_call_start_batch
241 call.
Craig Tiller2d984bf2015-07-20 15:01:38 -0700242 THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment
243 needs to be synchronized. As an optimization, you may synchronize batches
244 containing just send operations independently from batches containing just
245 receive operations. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100246GRPCAPI grpc_call_error grpc_call_start_batch(grpc_call *call,
247 const grpc_op *ops, size_t nops,
248 void *tag, void *reserved);
Craig Tillerfef76692015-02-02 16:44:26 -0800249
Craig Tiller45249422015-07-20 16:16:35 -0700250/** Returns a newly allocated string representing the endpoint to which this
251 call is communicating with. The string is in the uri format accepted by
252 grpc_channel_create.
Alistair Veitchff32faf2015-07-30 09:54:15 -0700253 The returned string should be disposed of with gpr_free().
Craig Tiller45249422015-07-20 16:16:35 -0700254
255 WARNING: this value is never authenticated or subject to any security
256 related code. It must not be used for any authentication related
257 functionality. Instead, use grpc_auth_context. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100258GRPCAPI char *grpc_call_get_peer(grpc_call *call);
Craig Tiller1b22b9d2015-07-20 13:42:22 -0700259
Alistair Veitchff32faf2015-07-30 09:54:15 -0700260struct census_context;
261
David Garcia Quintasf31f0962017-02-10 14:53:58 -0800262/** Set census context for a call; Must be called before first call to
Alistair Veitchff32faf2015-07-30 09:54:15 -0700263 grpc_call_start_batch(). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100264GRPCAPI void grpc_census_call_set_context(grpc_call *call,
265 struct census_context *context);
Alistair Veitchff32faf2015-07-30 09:54:15 -0700266
David Garcia Quintasf31f0962017-02-10 14:53:58 -0800267/** Retrieve the calls current census context. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100268GRPCAPI struct census_context *grpc_census_call_get_context(grpc_call *call);
Alistair Veitchff32faf2015-07-30 09:54:15 -0700269
Craig Tiller45249422015-07-20 16:16:35 -0700270/** Return a newly allocated string representing the target a channel was
271 created for. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100272GRPCAPI char *grpc_channel_get_target(grpc_channel *channel);
Craig Tiller45249422015-07-20 16:16:35 -0700273
Mark D. Rothf79ce7d2016-11-04 08:43:36 -0700274/** Request info about the channel.
275 \a channel_info indicates what information is being requested and
276 how that information will be returned.
277 \a channel_info is owned by the caller. */
Mark D. Rothb2d24882016-10-27 15:44:07 -0700278GRPCAPI void grpc_channel_get_info(grpc_channel *channel,
Mark D. Rothf79ce7d2016-11-04 08:43:36 -0700279 const grpc_channel_info *channel_info);
Mark D. Rothb2d24882016-10-27 15:44:07 -0700280
Craig Tiller2d984bf2015-07-20 15:01:38 -0700281/** Create a client channel to 'target'. Additional channel level configuration
282 MAY be provided by grpc_channel_args, though the expectation is that most
283 clients will want to simply pass NULL. See grpc_channel_args definition for
284 more on this. The data in 'args' need only live through the invocation of
285 this function. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100286GRPCAPI grpc_channel *grpc_insecure_channel_create(
Craig Tillerd6546c92016-01-29 07:59:35 -0800287 const char *target, const grpc_channel_args *args, void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800288
Craig Tiller2d984bf2015-07-20 15:01:38 -0700289/** Create a lame client: this client fails every operation attempted on it. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100290GRPCAPI grpc_channel *grpc_lame_client_channel_create(
Craig Tillerd6546c92016-01-29 07:59:35 -0800291 const char *target, grpc_status_code error_code, const char *error_message);
Craig Tiller42bc87c2015-02-23 08:50:19 -0800292
Craig Tiller2d984bf2015-07-20 15:01:38 -0700293/** Close and destroy a grpc channel */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100294GRPCAPI void grpc_channel_destroy(grpc_channel *channel);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800295
Alexander Polcynd809a152017-05-03 14:49:41 -0700296/** Error handling for grpc_call
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800297 Most grpc_call functions return a grpc_error. If the error is not GRPC_OK
298 then the operation failed due to some unsatisfied precondition.
299 If a grpc_call fails, it's guaranteed that no change to the call state
300 has been made. */
301
Craig Tiller2d984bf2015-07-20 15:01:38 -0700302/** Called by clients to cancel an RPC on the server.
303 Can be called multiple times, from any thread.
304 THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status
Craig Tillerdd36b152017-03-31 08:27:28 -0700305 are thread-safe, and can be called at any point before grpc_call_unref
Craig Tiller2d984bf2015-07-20 15:01:38 -0700306 is called.*/
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100307GRPCAPI grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800308
Craig Tiller2d984bf2015-07-20 15:01:38 -0700309/** Called by clients to cancel an RPC on the server.
310 Can be called multiple times, from any thread.
311 If a status has not been received for the call, set it to the status code
312 and description passed in.
313 Importantly, this function does not send status nor description to the
314 remote endpoint. */
Craig Tillerf40df232016-03-25 13:38:14 -0700315GRPCAPI grpc_call_error grpc_call_cancel_with_status(grpc_call *call,
316 grpc_status_code status,
317 const char *description,
318 void *reserved);
Craig Tillerd248c242015-01-14 11:49:12 -0800319
Craig Tillerdd36b152017-03-31 08:27:28 -0700320/** Ref a call.
321 THREAD SAFETY: grpc_call_unref is thread-compatible */
322GRPCAPI void grpc_call_ref(grpc_call *call);
323
324/** Unref a call.
325 THREAD SAFETY: grpc_call_unref is thread-compatible */
326GRPCAPI void grpc_call_unref(grpc_call *call);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800327
David G. Quintasb2a1c592015-08-20 14:44:27 -0700328/** Request notification of a new call.
Craig Tillerddf3a512015-09-24 13:03:44 -0700329 Once a call is received, a notification tagged with \a tag_new is added to
330 \a cq_for_notification. \a call, \a details and \a request_metadata are
Craig Tiller1359a122015-08-24 14:43:32 -0700331 updated with the appropriate call information. \a cq_bound_to_call is bound
332 to \a call, and batch operation notifications for that call will be posted
333 to \a cq_bound_to_call.
David G. Quintasb2a1c592015-08-20 14:44:27 -0700334 Note that \a cq_for_notification must have been registered to the server via
335 \a grpc_server_register_completion_queue. */
Craig Tillerf40df232016-03-25 13:38:14 -0700336GRPCAPI grpc_call_error grpc_server_request_call(
337 grpc_server *server, grpc_call **call, grpc_call_details *details,
338 grpc_metadata_array *request_metadata,
339 grpc_completion_queue *cq_bound_to_call,
340 grpc_completion_queue *cq_for_notification, void *tag_new);
Craig Tiller034929c2015-02-02 16:56:15 -0800341
Craig Tiller06cb1a92016-04-04 08:10:47 -0700342/** How to handle payloads for a registered method */
343typedef enum {
344 /** Don't try to read the payload */
345 GRPC_SRM_PAYLOAD_NONE,
346 /** Read the initial payload as a byte buffer */
347 GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER
348} grpc_server_register_method_payload_handling;
349
Craig Tiller2d984bf2015-07-20 15:01:38 -0700350/** Registers a method in the server.
351 Methods to this (host, method) pair will not be reported by
352 grpc_server_request_call, but instead be reported by
353 grpc_server_request_registered_call when passed the appropriate
354 registered_method (as returned by this function).
355 Must be called before grpc_server_start.
356 Returns NULL on failure. */
Craig Tiller06cb1a92016-04-04 08:10:47 -0700357GRPCAPI void *grpc_server_register_method(
358 grpc_server *server, const char *method, const char *host,
359 grpc_server_register_method_payload_handling payload_handling,
360 uint32_t flags);
Craig Tiller24be0f72015-02-10 14:04:22 -0800361
Alistair Veitchff32faf2015-07-30 09:54:15 -0700362/** Request notification of a new pre-registered call. 'cq_for_notification'
363 must have been registered to the server via
Craig Tiller2d984bf2015-07-20 15:01:38 -0700364 grpc_server_register_completion_queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100365GRPCAPI grpc_call_error grpc_server_request_registered_call(
Craig Tiller24be0f72015-02-10 14:04:22 -0800366 grpc_server *server, void *registered_method, grpc_call **call,
367 gpr_timespec *deadline, grpc_metadata_array *request_metadata,
368 grpc_byte_buffer **optional_payload,
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700369 grpc_completion_queue *cq_bound_to_call,
370 grpc_completion_queue *cq_for_notification, void *tag_new);
Craig Tiller24be0f72015-02-10 14:04:22 -0800371
Craig Tiller2d984bf2015-07-20 15:01:38 -0700372/** Create a server. Additional configuration for each incoming channel can
373 be specified with args. If no additional configuration is needed, args can
374 be NULL. See grpc_channel_args for more. The data in 'args' need only live
375 through the invocation of this function. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100376GRPCAPI grpc_server *grpc_server_create(const grpc_channel_args *args,
377 void *reserved);
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700378
Craig Tiller2d984bf2015-07-20 15:01:38 -0700379/** Register a completion queue with the server. Must be done for any
380 notification completion queue that is passed to grpc_server_request_*_call
381 and to grpc_server_shutdown_and_notify. Must be performed prior to
382 grpc_server_start. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100383GRPCAPI void grpc_server_register_completion_queue(grpc_server *server,
384 grpc_completion_queue *cq,
385 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800386
Craig Tiller2d984bf2015-07-20 15:01:38 -0700387/** Add a HTTP2 over plaintext over tcp listener.
388 Returns bound port number on success, 0 on failure.
389 REQUIRES: server not started */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100390GRPCAPI int grpc_server_add_insecure_http2_port(grpc_server *server,
391 const char *addr);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800392
Craig Tiller2d984bf2015-07-20 15:01:38 -0700393/** Start a server - tells all listeners to start listening */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100394GRPCAPI void grpc_server_start(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800395
Craig Tiller2d984bf2015-07-20 15:01:38 -0700396/** Begin shutting down a server.
397 After completion, no new calls or connections will be admitted.
398 Existing calls will be allowed to complete.
399 Send a GRPC_OP_COMPLETE event when there are no more calls being serviced.
400 Shutdown is idempotent, and all tags will be notified at once if multiple
401 grpc_server_shutdown_and_notify calls are made. 'cq' must have been
402 registered to this server via grpc_server_register_completion_queue. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100403GRPCAPI void grpc_server_shutdown_and_notify(grpc_server *server,
404 grpc_completion_queue *cq,
405 void *tag);
Craig Tiller4ffdcd52015-01-16 11:34:55 -0800406
Craig Tiller2d984bf2015-07-20 15:01:38 -0700407/** Cancel all in-progress calls.
408 Only usable after shutdown. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100409GRPCAPI void grpc_server_cancel_all_calls(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800410
Craig Tiller2d984bf2015-07-20 15:01:38 -0700411/** Destroy a server.
412 Shutdown must have completed beforehand (i.e. all tags generated by
413 grpc_server_shutdown_and_notify must have been received, and at least
414 one call to grpc_server_shutdown_and_notify must have been made). */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100415GRPCAPI void grpc_server_destroy(grpc_server *server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800416
Craig Tilleraf7abf92015-06-03 17:18:58 -0700417/** Enable or disable a tracer.
418
419 Tracers (usually controlled by the environment variable GRPC_TRACE)
420 allow printf-style debugging on GRPC internals, and are useful for
Craig Tiller9a576332015-06-17 10:21:49 -0700421 tracking down problems in the field.
Craig Tilleraf7abf92015-06-03 17:18:58 -0700422
Craig Tiller9a576332015-06-17 10:21:49 -0700423 Use of this function is not strictly thread-safe, but the
Craig Tilleraf7abf92015-06-03 17:18:58 -0700424 thread-safety issues raised by it should not be of concern. */
Nicolas "Pixel" Noblecd41a0b2016-02-08 22:53:14 +0100425GRPCAPI int grpc_tracer_set_enabled(const char *name, int enabled);
Craig Tilleraf7abf92015-06-03 17:18:58 -0700426
murgatroid99c3910ca2016-01-06 13:14:23 -0800427/** Check whether a metadata key is legal (will be accepted by core) */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800428GRPCAPI int grpc_header_key_is_legal(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800429
430/** Check whether a non-binary metadata value is legal (will be accepted by
431 core) */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800432GRPCAPI int grpc_header_nonbin_value_is_legal(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800433
434/** Check whether a metadata key corresponds to a binary value */
Craig Tiller7c70b6c2017-01-23 07:48:42 -0800435GRPCAPI int grpc_is_binary_header(grpc_slice slice);
murgatroid99c3910ca2016-01-06 13:14:23 -0800436
Yuchen Zeng2e7d9572016-04-15 17:29:57 -0700437/** Convert grpc_call_error values to a string */
438GRPCAPI const char *grpc_call_error_to_string(grpc_call_error error);
439
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700440/** Create a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700441GRPCAPI grpc_resource_quota *grpc_resource_quota_create(const char *trace_name);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700442
443/** Add a reference to a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700444GRPCAPI void grpc_resource_quota_ref(grpc_resource_quota *resource_quota);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700445
446/** Drop a reference to a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700447GRPCAPI void grpc_resource_quota_unref(grpc_resource_quota *resource_quota);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700448
449/** Update the size of a buffer pool */
Craig Tiller20afa3d2016-10-17 14:52:14 -0700450GRPCAPI void grpc_resource_quota_resize(grpc_resource_quota *resource_quota,
451 size_t new_size);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700452
Craig Tiller20afa3d2016-10-17 14:52:14 -0700453/** Fetch a vtable for a grpc_channel_arg that points to a grpc_resource_quota
454 */
455GRPCAPI const grpc_arg_pointer_vtable *grpc_resource_quota_arg_vtable(void);
Craig Tillerc2ab9ae2016-09-22 09:57:29 -0700456
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800457#ifdef __cplusplus
458}
459#endif
460
Craig Tillerb20111c2015-04-10 23:27:11 +0000461#endif /* GRPC_GRPC_H */