GRPC Core
0.10.0.0
|
#include <grpc/status.h>
#include <stddef.h>
#include <grpc/byte_buffer.h>
#include <grpc/support/slice.h>
#include <grpc/support/time.h>
Go to the source code of this file.
Data Structures | |
struct | grpc_arg |
A single argument... More... | |
struct | grpc_channel_args |
An array of arguments that can be passed around. More... | |
struct | grpc_metadata |
A single metadata element. More... | |
struct | grpc_event |
The result of an operation. More... | |
struct | grpc_metadata_array |
struct | grpc_call_details |
struct | grpc_op |
Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments) More... | |
Macros | |
#define | GRPC_ARG_ENABLE_CENSUS "grpc.census" |
Enable census for tracing and stats collection. More... | |
#define | GRPC_ARG_MAX_CONCURRENT_STREAMS "grpc.max_concurrent_streams" |
Maximum number of concurrent incoming streams to allow on a http2 connection. More... | |
#define | GRPC_ARG_MAX_MESSAGE_LENGTH "grpc.max_message_length" |
Maximum message length that the channel can receive. More... | |
#define | GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER "grpc.http2.initial_sequence_number" |
Initial sequence number for http2 transports. More... | |
#define | GRPC_ARG_DEFAULT_AUTHORITY "grpc.default_authority" |
Default authority to pass if none specified on call construction. More... | |
#define | GRPC_ARG_PRIMARY_USER_AGENT_STRING "grpc.primary_user_agent" |
Primary user agent: goes at the start of the user-agent metadata sent on each request. More... | |
#define | GRPC_ARG_SECONDARY_USER_AGENT_STRING "grpc.secondary_user_agent" |
Secondary user agent: goes at the end of the user-agent metadata sent on each request. More... | |
#define | GRPC_WRITE_BUFFER_HINT (0x00000001u) |
Hint that the write may be buffered and need not go out on the wire immediately. More... | |
#define | GRPC_WRITE_NO_COMPRESS (0x00000002u) |
Force compression to be disabled for a particular write (start_write/add_metadata). More... | |
#define | GRPC_WRITE_USED_MASK (GRPC_WRITE_BUFFER_HINT | GRPC_WRITE_NO_COMPRESS) |
Mask of all valid flags. More... | |
Typedefs | |
typedef struct grpc_completion_queue | grpc_completion_queue |
Completion Queues enable notification of the completion of asynchronous actions. More... | |
typedef struct grpc_channel | grpc_channel |
The Channel interface allows creation of Call objects. More... | |
typedef struct grpc_server | grpc_server |
A server listens to some port and responds to request calls. More... | |
typedef struct grpc_call | grpc_call |
A Call represents an RPC. More... | |
typedef enum grpc_call_error | grpc_call_error |
Result of a grpc call. More... | |
typedef struct grpc_metadata | grpc_metadata |
A single metadata element. More... | |
typedef enum grpc_completion_type | grpc_completion_type |
The type of completion (for grpc_event) More... | |
typedef struct grpc_event | grpc_event |
The result of an operation. More... | |
typedef struct grpc_op | grpc_op |
Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments) More... | |
Functions | |
void | grpc_metadata_array_init (grpc_metadata_array *array) |
void | grpc_metadata_array_destroy (grpc_metadata_array *array) |
void | grpc_call_details_init (grpc_call_details *details) |
void | grpc_call_details_destroy (grpc_call_details *details) |
void | grpc_init (void) |
Initialize the grpc library. More... | |
void | grpc_shutdown (void) |
Shut down the grpc library. More... | |
const char * | grpc_version_string (void) |
Return a string representing the current version of grpc. More... | |
grpc_completion_queue * | grpc_completion_queue_create (void) |
Create a completion queue. More... | |
grpc_event | grpc_completion_queue_next (grpc_completion_queue *cq, gpr_timespec deadline) |
Blocks until an event is available, the completion queue is being shut down, or deadline is reached. More... | |
grpc_event | grpc_completion_queue_pluck (grpc_completion_queue *cq, void *tag, gpr_timespec deadline) |
Blocks until an event with tag 'tag' is available, the completion queue is being shutdown or deadline is reached. More... | |
void | grpc_completion_queue_shutdown (grpc_completion_queue *cq) |
Begin destruction of a completion queue. More... | |
void | grpc_completion_queue_destroy (grpc_completion_queue *cq) |
Destroy a completion queue. More... | |
grpc_connectivity_state | grpc_channel_check_connectivity_state (grpc_channel *channel, int try_to_connect) |
Check the connectivity state of a channel. More... | |
void | grpc_channel_watch_connectivity_state (grpc_channel *channel, grpc_connectivity_state last_observed_state, gpr_timespec deadline, grpc_completion_queue *cq, void *tag) |
Watch for a change in connectivity state. More... | |
grpc_call * | grpc_channel_create_call (grpc_channel *channel, grpc_completion_queue *completion_queue, const char *method, const char *host, gpr_timespec deadline) |
Create a call given a grpc_channel, in order to call 'method'. More... | |
void * | grpc_channel_register_call (grpc_channel *channel, const char *method, const char *host) |
Pre-register a method/host pair on a channel. More... | |
grpc_call * | grpc_channel_create_registered_call (grpc_channel *channel, grpc_completion_queue *completion_queue, void *registered_call_handle, gpr_timespec deadline) |
Create a call given a handle returned from grpc_channel_register_call. More... | |
grpc_call_error | grpc_call_start_batch (grpc_call *call, const grpc_op *ops, size_t nops, void *tag) |
Start a batch of operations defined in the array ops; when complete, post a completion of type 'tag' to the completion queue bound to the call. More... | |
char * | grpc_call_get_peer (grpc_call *call) |
Returns a newly allocated string representing the endpoint to which this call is communicating with. More... | |
void | grpc_census_call_set_context (grpc_call *call, struct census_context *context) |
struct census_context * | grpc_census_call_get_context (grpc_call *call) |
char * | grpc_channel_get_target (grpc_channel *channel) |
Return a newly allocated string representing the target a channel was created for. More... | |
grpc_channel * | grpc_insecure_channel_create (const char *target, const grpc_channel_args *args) |
Create a client channel to 'target'. More... | |
grpc_channel * | grpc_lame_client_channel_create (const char *target) |
Create a lame client: this client fails every operation attempted on it. More... | |
void | grpc_channel_destroy (grpc_channel *channel) |
Close and destroy a grpc channel. More... | |
grpc_call_error | grpc_call_cancel (grpc_call *call) |
Called by clients to cancel an RPC on the server. More... | |
grpc_call_error | grpc_call_cancel_with_status (grpc_call *call, grpc_status_code status, const char *description) |
Called by clients to cancel an RPC on the server. More... | |
void | grpc_call_destroy (grpc_call *call) |
Destroy a call. More... | |
grpc_call_error | grpc_server_request_call (grpc_server *server, grpc_call **call, grpc_call_details *details, grpc_metadata_array *request_metadata, grpc_completion_queue *cq_bound_to_call, grpc_completion_queue *cq_for_notification, void *tag_new) |
Request notification of a new call. More... | |
void * | grpc_server_register_method (grpc_server *server, const char *method, const char *host) |
Registers a method in the server. More... | |
grpc_call_error | grpc_server_request_registered_call (grpc_server *server, void *registered_method, grpc_call **call, gpr_timespec *deadline, grpc_metadata_array *request_metadata, grpc_byte_buffer **optional_payload, grpc_completion_queue *cq_bound_to_call, grpc_completion_queue *cq_for_notification, void *tag_new) |
Request notification of a new pre-registered call. More... | |
grpc_server * | grpc_server_create (const grpc_channel_args *args) |
Create a server. More... | |
void | grpc_server_register_completion_queue (grpc_server *server, grpc_completion_queue *cq) |
Register a completion queue with the server. More... | |
int | grpc_server_add_http2_port (grpc_server *server, const char *addr) |
Add a HTTP2 over plaintext over tcp listener. More... | |
void | grpc_server_start (grpc_server *server) |
Start a server - tells all listeners to start listening. More... | |
void | grpc_server_shutdown_and_notify (grpc_server *server, grpc_completion_queue *cq, void *tag) |
Begin shutting down a server. More... | |
void | grpc_server_cancel_all_calls (grpc_server *server) |
Cancel all in-progress calls. More... | |
void | grpc_server_destroy (grpc_server *server) |
Destroy a server. More... | |
int | grpc_tracer_set_enabled (const char *name, int enabled) |
Enable or disable a tracer. More... | |
#define GRPC_ARG_DEFAULT_AUTHORITY "grpc.default_authority" |
Default authority to pass if none specified on call construction.
#define GRPC_ARG_ENABLE_CENSUS "grpc.census" |
Enable census for tracing and stats collection.
#define GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER "grpc.http2.initial_sequence_number" |
Initial sequence number for http2 transports.
#define GRPC_ARG_MAX_CONCURRENT_STREAMS "grpc.max_concurrent_streams" |
Maximum number of concurrent incoming streams to allow on a http2 connection.
#define GRPC_ARG_MAX_MESSAGE_LENGTH "grpc.max_message_length" |
Maximum message length that the channel can receive.
#define GRPC_ARG_PRIMARY_USER_AGENT_STRING "grpc.primary_user_agent" |
Primary user agent: goes at the start of the user-agent metadata sent on each request.
#define GRPC_ARG_SECONDARY_USER_AGENT_STRING "grpc.secondary_user_agent" |
Secondary user agent: goes at the end of the user-agent metadata sent on each request.
#define GRPC_WRITE_BUFFER_HINT (0x00000001u) |
Hint that the write may be buffered and need not go out on the wire immediately.
GRPC is free to buffer the message until the next non-buffered write, or until writes_done, but it need not buffer completely or at all.
#define GRPC_WRITE_NO_COMPRESS (0x00000002u) |
Force compression to be disabled for a particular write (start_write/add_metadata).
Illegal on invoke/accept.
#define GRPC_WRITE_USED_MASK (GRPC_WRITE_BUFFER_HINT | GRPC_WRITE_NO_COMPRESS) |
Mask of all valid flags.
A Call represents an RPC.
When created, it is in a configuration state allowing properties to be set until it is invoked. After invoke, the Call can have messages written to it and read from it.
typedef enum grpc_call_error grpc_call_error |
Result of a grpc call.
If the caller satisfies the prerequisites of a particular operation, the grpc_call_error returned will be GRPC_CALL_OK. Receiving any other value listed here is an indication of a bug in the caller.
typedef struct grpc_channel grpc_channel |
The Channel interface allows creation of Call objects.
typedef struct grpc_completion_queue grpc_completion_queue |
Completion Queues enable notification of the completion of asynchronous actions.
typedef enum grpc_completion_type grpc_completion_type |
The type of completion (for grpc_event)
typedef struct grpc_event grpc_event |
The result of an operation.
Returned by a completion queue when the operation started with tag.
typedef struct grpc_metadata grpc_metadata |
A single metadata element.
Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments)
typedef struct grpc_server grpc_server |
A server listens to some port and responds to request calls.
enum grpc_arg_type |
Type specifier for grpc_arg.
Enumerator | |
---|---|
GRPC_ARG_STRING | |
GRPC_ARG_INTEGER | |
GRPC_ARG_POINTER |
enum grpc_call_error |
Result of a grpc call.
If the caller satisfies the prerequisites of a particular operation, the grpc_call_error returned will be GRPC_CALL_OK. Receiving any other value listed here is an indication of a bug in the caller.
enum grpc_completion_type |
The type of completion (for grpc_event)
Enumerator | |
---|---|
GRPC_QUEUE_SHUTDOWN |
Shutting down. |
GRPC_QUEUE_TIMEOUT |
No event before timeout. |
GRPC_OP_COMPLETE |
Operation completion. |
Connectivity state of a channel.
enum grpc_op_type |
grpc_call_error grpc_call_cancel | ( | grpc_call * | call | ) |
Called by clients to cancel an RPC on the server.
Can be called multiple times, from any thread. THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status are thread-safe, and can be called at any point before grpc_call_destroy is called.
grpc_call_error grpc_call_cancel_with_status | ( | grpc_call * | call, |
grpc_status_code | status, | ||
const char * | description | ||
) |
Called by clients to cancel an RPC on the server.
Can be called multiple times, from any thread. If a status has not been received for the call, set it to the status code and description passed in. Importantly, this function does not send status nor description to the remote endpoint.
void grpc_call_destroy | ( | grpc_call * | call | ) |
Destroy a call.
THREAD SAFETY: grpc_call_destroy is thread-compatible
void grpc_call_details_destroy | ( | grpc_call_details * | details | ) |
void grpc_call_details_init | ( | grpc_call_details * | details | ) |
char* grpc_call_get_peer | ( | grpc_call * | call | ) |
Returns a newly allocated string representing the endpoint to which this call is communicating with.
The string is in the uri format accepted by grpc_channel_create. The returned string should be disposed of with gpr_free().
WARNING: this value is never authenticated or subject to any security related code. It must not be used for any authentication related functionality. Instead, use grpc_auth_context.
grpc_call_error grpc_call_start_batch | ( | grpc_call * | call, |
const grpc_op * | ops, | ||
size_t | nops, | ||
void * | tag | ||
) |
Start a batch of operations defined in the array ops; when complete, post a completion of type 'tag' to the completion queue bound to the call.
The order of ops specified in the batch has no significance. Only one operation of each type can be active at once in any given batch. You must call grpc_completion_queue_next or grpc_completion_queue_pluck on the completion queue associated with 'call' for work to be performed. THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment needs to be synchronized. As an optimization, you may synchronize batches containing just send operations independently from batches containing just receive operations.
struct census_context* grpc_census_call_get_context | ( | grpc_call * | call | ) |
void grpc_census_call_set_context | ( | grpc_call * | call, |
struct census_context * | context | ||
) |
grpc_connectivity_state grpc_channel_check_connectivity_state | ( | grpc_channel * | channel, |
int | try_to_connect | ||
) |
Check the connectivity state of a channel.
grpc_call* grpc_channel_create_call | ( | grpc_channel * | channel, |
grpc_completion_queue * | completion_queue, | ||
const char * | method, | ||
const char * | host, | ||
gpr_timespec | deadline | ||
) |
Create a call given a grpc_channel, in order to call 'method'.
All completions are sent to 'completion_queue'. 'method' and 'host' need only live through the invocation of this function.
grpc_call* grpc_channel_create_registered_call | ( | grpc_channel * | channel, |
grpc_completion_queue * | completion_queue, | ||
void * | registered_call_handle, | ||
gpr_timespec | deadline | ||
) |
Create a call given a handle returned from grpc_channel_register_call.
void grpc_channel_destroy | ( | grpc_channel * | channel | ) |
Close and destroy a grpc channel.
char* grpc_channel_get_target | ( | grpc_channel * | channel | ) |
Return a newly allocated string representing the target a channel was created for.
void* grpc_channel_register_call | ( | grpc_channel * | channel, |
const char * | method, | ||
const char * | host | ||
) |
Pre-register a method/host pair on a channel.
void grpc_channel_watch_connectivity_state | ( | grpc_channel * | channel, |
grpc_connectivity_state | last_observed_state, | ||
gpr_timespec | deadline, | ||
grpc_completion_queue * | cq, | ||
void * | tag | ||
) |
Watch for a change in connectivity state.
Once the channel connectivity state is different from last_observed_state, tag will be enqueued on cq with success=1. If deadline expires BEFORE the state is changed, tag will be enqueued on cq with success=0.
grpc_completion_queue* grpc_completion_queue_create | ( | void | ) |
Create a completion queue.
void grpc_completion_queue_destroy | ( | grpc_completion_queue * | cq | ) |
Destroy a completion queue.
The caller must ensure that the queue is drained and no threads are executing grpc_completion_queue_next
grpc_event grpc_completion_queue_next | ( | grpc_completion_queue * | cq, |
gpr_timespec | deadline | ||
) |
Blocks until an event is available, the completion queue is being shut down, or deadline is reached.
Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout, otherwise a grpc_event describing the event that occurred.
Callers must not call grpc_completion_queue_next and grpc_completion_queue_pluck simultaneously on the same completion queue.
grpc_event grpc_completion_queue_pluck | ( | grpc_completion_queue * | cq, |
void * | tag, | ||
gpr_timespec | deadline | ||
) |
Blocks until an event with tag 'tag' is available, the completion queue is being shutdown or deadline is reached.
Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout, otherwise a grpc_event describing the event that occurred.
Callers must not call grpc_completion_queue_next and grpc_completion_queue_pluck simultaneously on the same completion queue.
void grpc_completion_queue_shutdown | ( | grpc_completion_queue * | cq | ) |
Begin destruction of a completion queue.
Once all possible events are drained then grpc_completion_queue_next will start to produce GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call grpc_completion_queue_destroy.
After calling this function applications should ensure that no NEW work is added to be published on this completion queue.
void grpc_init | ( | void | ) |
Initialize the grpc library.
It is not safe to call any other grpc functions before calling this. (To avoid overhead, little checking is done, and some things may work. We do not warrant that they will continue to do so in future revisions of this library).
grpc_channel* grpc_insecure_channel_create | ( | const char * | target, |
const grpc_channel_args * | args | ||
) |
Create a client channel to 'target'.
Additional channel level configuration MAY be provided by grpc_channel_args, though the expectation is that most clients will want to simply pass NULL. See grpc_channel_args definition for more on this. The data in 'args' need only live through the invocation of this function.
grpc_channel* grpc_lame_client_channel_create | ( | const char * | target | ) |
Create a lame client: this client fails every operation attempted on it.
void grpc_metadata_array_destroy | ( | grpc_metadata_array * | array | ) |
void grpc_metadata_array_init | ( | grpc_metadata_array * | array | ) |
int grpc_server_add_http2_port | ( | grpc_server * | server, |
const char * | addr | ||
) |
Add a HTTP2 over plaintext over tcp listener.
Returns bound port number on success, 0 on failure. REQUIRES: server not started
void grpc_server_cancel_all_calls | ( | grpc_server * | server | ) |
Cancel all in-progress calls.
Only usable after shutdown.
grpc_server* grpc_server_create | ( | const grpc_channel_args * | args | ) |
Create a server.
Additional configuration for each incoming channel can be specified with args. If no additional configuration is needed, args can be NULL. See grpc_channel_args for more. The data in 'args' need only live through the invocation of this function.
void grpc_server_destroy | ( | grpc_server * | server | ) |
Destroy a server.
Shutdown must have completed beforehand (i.e. all tags generated by grpc_server_shutdown_and_notify must have been received, and at least one call to grpc_server_shutdown_and_notify must have been made).
void grpc_server_register_completion_queue | ( | grpc_server * | server, |
grpc_completion_queue * | cq | ||
) |
Register a completion queue with the server.
Must be done for any notification completion queue that is passed to grpc_server_request_*_call and to grpc_server_shutdown_and_notify. Must be performed prior to grpc_server_start.
void* grpc_server_register_method | ( | grpc_server * | server, |
const char * | method, | ||
const char * | host | ||
) |
Registers a method in the server.
Methods to this (host, method) pair will not be reported by grpc_server_request_call, but instead be reported by grpc_server_request_registered_call when passed the appropriate registered_method (as returned by this function). Must be called before grpc_server_start. Returns NULL on failure.
grpc_call_error grpc_server_request_call | ( | grpc_server * | server, |
grpc_call ** | call, | ||
grpc_call_details * | details, | ||
grpc_metadata_array * | request_metadata, | ||
grpc_completion_queue * | cq_bound_to_call, | ||
grpc_completion_queue * | cq_for_notification, | ||
void * | tag_new | ||
) |
Request notification of a new call.
'cq_for_notification' must have been registered to the server via grpc_server_register_completion_queue.
grpc_call_error grpc_server_request_registered_call | ( | grpc_server * | server, |
void * | registered_method, | ||
grpc_call ** | call, | ||
gpr_timespec * | deadline, | ||
grpc_metadata_array * | request_metadata, | ||
grpc_byte_buffer ** | optional_payload, | ||
grpc_completion_queue * | cq_bound_to_call, | ||
grpc_completion_queue * | cq_for_notification, | ||
void * | tag_new | ||
) |
Request notification of a new pre-registered call.
'cq_for_notification' must have been registered to the server via grpc_server_register_completion_queue.
void grpc_server_shutdown_and_notify | ( | grpc_server * | server, |
grpc_completion_queue * | cq, | ||
void * | tag | ||
) |
Begin shutting down a server.
After completion, no new calls or connections will be admitted. Existing calls will be allowed to complete. Send a GRPC_OP_COMPLETE event when there are no more calls being serviced. Shutdown is idempotent, and all tags will be notified at once if multiple grpc_server_shutdown_and_notify calls are made. 'cq' must have been registered to this server via grpc_server_register_completion_queue.
void grpc_server_start | ( | grpc_server * | server | ) |
Start a server - tells all listeners to start listening.
void grpc_shutdown | ( | void | ) |
Shut down the grpc library.
No memory is used by grpc after this call returns, nor are any instructions executing within the grpc library. Prior to calling, all application owned grpc objects must have been destroyed.
int grpc_tracer_set_enabled | ( | const char * | name, |
int | enabled | ||
) |
Enable or disable a tracer.
Tracers (usually controlled by the environment variable GRPC_TRACE) allow printf-style debugging on GRPC internals, and are useful for tracking down problems in the field.
Use of this function is not strictly thread-safe, but the thread-safety issues raised by it should not be of concern.
const char* grpc_version_string | ( | void | ) |
Return a string representing the current version of grpc.