GRPC C++  1.39.1
Data Structures | Macros | Functions | Variables
call.cc File Reference
#include <grpc/support/port_platform.h>
#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include <grpc/compression.h>
#include <grpc/grpc.h>
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/compression/algorithm_metadata.h"
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/alloc.h"
#include "src/core/lib/gpr/time_precise.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/arena.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/ref_counted.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/slice/slice_utils.h"
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/call_test_only.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/completion_queue.h"
#include "src/core/lib/surface/server.h"
#include "src/core/lib/surface/validate_metadata.h"
#include "src/core/lib/transport/error_utils.h"
#include "src/core/lib/transport/metadata.h"
#include "src/core/lib/transport/static_metadata.h"
#include "src/core/lib/transport/status_metadata.h"
#include "src/core/lib/transport/transport.h"

Data Structures

struct  batch_control
 
struct  parent_call
 
struct  child_call
 
struct  grpc_call
 
struct  cancel_state
 

Macros

#define MAX_CONCURRENT_BATCHES   6
 The maximum number of concurrent batches possible. More...
 
#define MAX_SEND_EXTRA_METADATA_COUNT   3
 
#define ESTIMATED_MDELEM_COUNT   16
 
#define RECV_NONE   ((gpr_atm)0)
 
#define RECV_INITIAL_METADATA_FIRST   ((gpr_atm)1)
 
#define CALL_STACK_FROM_CALL(call)
 
#define CALL_FROM_CALL_STACK(call_stack)
 
#define CALL_ELEM_FROM_CALL(call, idx)    grpc_call_stack_element(CALL_STACK_FROM_CALL(call), idx)
 
#define CALL_FROM_TOP_ELEM(top_elem)    CALL_FROM_CALL_STACK(grpc_call_stack_from_top_element(top_elem))
 
#define REF_REASON   reason
 
#define REF_ARG   , const char* reason
 

Functions

void * grpc_call_arena_alloc (grpc_call *call, size_t size)
 Allocate memory in the grpc_call arena: this memory is automatically discarded at call completion. More...
 
size_t grpc_call_get_initial_size_estimate ()
 
grpc_error_handle grpc_call_create (const grpc_call_create_args *args, grpc_call **out_call)
 
void grpc_call_set_completion_queue (grpc_call *call, grpc_completion_queue *cq)
 
void grpc_call_internal_ref (grpc_call *c, const char *reason)
 
void grpc_call_internal_unref (grpc_call *c, const char *reason)
 
void grpc_call_ref (grpc_call *c)
 Ref a call. More...
 
void grpc_call_unref (grpc_call *c)
 Unref a call. More...
 
grpc_call_error grpc_call_cancel (grpc_call *call, void *reserved)
 Error handling for grpc_call Most grpc_call functions return a grpc_error. 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...
 
grpc_callgrpc_call_from_top_element (grpc_call_element *surface_element)
 
grpc_call_error grpc_call_cancel_with_status (grpc_call *c, grpc_status_code status, const char *description, void *reserved)
 Cancel an RPC. More...
 
void grpc_call_cancel_internal (grpc_call *call)
 
grpc_compression_algorithm grpc_call_test_only_get_compression_algorithm (grpc_call *call)
 Return the message compression algorithm from call. More...
 
uint32_t grpc_call_test_only_get_message_flags (grpc_call *call)
 Return the message flags from call. More...
 
uint32_t grpc_call_test_only_get_encodings_accepted_by_peer (grpc_call *call)
 Returns a bitset for the encodings (compression algorithms) supported by call's peer. More...
 
grpc_stream_compression_algorithm grpc_call_test_only_get_incoming_stream_encodings (grpc_call *call)
 
grpc_core::Arenagrpc_call_get_arena (grpc_call *call)
 
grpc_call_stackgrpc_call_get_call_stack (grpc_call *call)
 
grpc_call_error grpc_call_start_batch (grpc_call *call, const grpc_op *ops, size_t nops, void *tag, void *reserved)
 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...
 
grpc_call_error grpc_call_start_batch_and_execute (grpc_call *call, const grpc_op *ops, size_t nops, grpc_closure *closure)
 
void grpc_call_context_set (grpc_call *call, grpc_context_index elem, void *value, void(*destroy)(void *value))
 
void * grpc_call_context_get (grpc_call *call, grpc_context_index elem)
 
uint8_t grpc_call_is_client (grpc_call *call)
 
grpc_compression_algorithm grpc_call_compression_for_level (grpc_call *call, grpc_compression_level level)
 
bool grpc_call_is_trailers_only (const grpc_call *call)
 
bool grpc_call_failed_before_recv_message (const grpc_call *c)
 
const char * grpc_call_error_to_string (grpc_call_error error)
 Convert grpc_call_error values to a string. More...
 

Variables

grpc_core::TraceFlag grpc_call_error_trace (false, "call_error")
 
grpc_core::TraceFlag grpc_compression_trace (false, "compression")
 

Macro Definition Documentation

◆ CALL_ELEM_FROM_CALL

#define CALL_ELEM_FROM_CALL (   call,
  idx 
)     grpc_call_stack_element(CALL_STACK_FROM_CALL(call), idx)

◆ CALL_FROM_CALL_STACK

#define CALL_FROM_CALL_STACK (   call_stack)
Value:
(grpc_call*)(((char*)(call_stack)) - \
GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_call)))
Definition: call.cc:139

◆ CALL_FROM_TOP_ELEM

#define CALL_FROM_TOP_ELEM (   top_elem)     CALL_FROM_CALL_STACK(grpc_call_stack_from_top_element(top_elem))

◆ CALL_STACK_FROM_CALL

#define CALL_STACK_FROM_CALL (   call)
Value:
(grpc_call_stack*)((char*)(call) + \
#define GPR_ROUND_UP_TO_ALIGNMENT_SIZE(x)
Given a size, round up to the next multiple of sizeof(void*).
Definition: alloc.h:25
Definition: channel_stack.h:192

◆ ESTIMATED_MDELEM_COUNT

#define ESTIMATED_MDELEM_COUNT   16

◆ MAX_CONCURRENT_BATCHES

#define MAX_CONCURRENT_BATCHES   6

The maximum number of concurrent batches possible.

Based upon the maximum number of individually queueable ops in the batch api:

  • initial metadata send
  • message send
  • status/close send (depending on client/server)
  • initial metadata recv
  • message recv
  • status/close recv (depending on client/server)

◆ MAX_SEND_EXTRA_METADATA_COUNT

#define MAX_SEND_EXTRA_METADATA_COUNT   3

◆ RECV_INITIAL_METADATA_FIRST

#define RECV_INITIAL_METADATA_FIRST   ((gpr_atm)1)

◆ RECV_NONE

#define RECV_NONE   ((gpr_atm)0)

◆ REF_ARG

#define REF_ARG   , const char* reason

◆ REF_REASON

#define REF_REASON   reason

Function Documentation

◆ grpc_call_arena_alloc()

void* grpc_call_arena_alloc ( grpc_call call,
size_t  size 
)

Allocate memory in the grpc_call arena: this memory is automatically discarded at call completion.

◆ grpc_call_cancel()

grpc_call_error grpc_call_cancel ( grpc_call call,
void *  reserved 
)

Error handling for grpc_call Most grpc_call functions return a grpc_error.

If the error is not GRPC_OK then the operation failed due to some unsatisfied precondition. If a grpc_call fails, it's guaranteed that no change to the call state has been made. Cancel an RPC. 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_unref is called.

◆ grpc_call_cancel_internal()

void grpc_call_cancel_internal ( grpc_call call)

◆ grpc_call_cancel_with_status()

grpc_call_error grpc_call_cancel_with_status ( grpc_call call,
grpc_status_code  status,
const char *  description,
void *  reserved 
)

Cancel an RPC.

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. Note that description doesn't need be a static string. It doesn't need to be alive after the call to grpc_call_cancel_with_status completes.

◆ grpc_call_compression_for_level()

grpc_compression_algorithm grpc_call_compression_for_level ( grpc_call call,
grpc_compression_level  level 
)

◆ grpc_call_context_get()

void* grpc_call_context_get ( grpc_call call,
grpc_context_index  elem 
)

◆ grpc_call_context_set()

void grpc_call_context_set ( grpc_call call,
grpc_context_index  elem,
void *  value,
void(*)(void *value)  destroy 
)

◆ grpc_call_create()

grpc_error_handle grpc_call_create ( const grpc_call_create_args args,
grpc_call **  out_call 
)

◆ grpc_call_error_to_string()

const char* grpc_call_error_to_string ( grpc_call_error  error)

Convert grpc_call_error values to a string.

◆ grpc_call_failed_before_recv_message()

bool grpc_call_failed_before_recv_message ( const grpc_call c)

◆ grpc_call_from_top_element()

grpc_call* grpc_call_from_top_element ( grpc_call_element surface_element)

◆ grpc_call_get_arena()

grpc_core::Arena* grpc_call_get_arena ( grpc_call call)

◆ grpc_call_get_call_stack()

grpc_call_stack* grpc_call_get_call_stack ( grpc_call call)

◆ grpc_call_get_initial_size_estimate()

size_t grpc_call_get_initial_size_estimate ( )

◆ grpc_call_get_peer()

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_internal_ref()

void grpc_call_internal_ref ( grpc_call c,
const char *  reason 
)

◆ grpc_call_internal_unref()

void grpc_call_internal_unref ( grpc_call c,
const char *  reason 
)

◆ grpc_call_is_client()

uint8_t grpc_call_is_client ( grpc_call call)

◆ grpc_call_is_trailers_only()

bool grpc_call_is_trailers_only ( const grpc_call call)

◆ grpc_call_ref()

void grpc_call_ref ( grpc_call call)

Ref a call.

THREAD SAFETY: grpc_call_ref is thread-compatible

◆ grpc_call_set_completion_queue()

void grpc_call_set_completion_queue ( grpc_call call,
grpc_completion_queue cq 
)

◆ grpc_call_start_batch()

grpc_call_error grpc_call_start_batch ( grpc_call call,
const grpc_op ops,
size_t  nops,
void *  tag,
void *  reserved 
)

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. If a call to grpc_call_start_batch returns GRPC_CALL_OK you must call grpc_completion_queue_next or grpc_completion_queue_pluck on the completion queue associated with 'call' for work to be performed. If a call to grpc_call_start_batch returns any value other than GRPC_CALL_OK it is guaranteed that no state associated with 'call' is changed and it is not appropriate to call grpc_completion_queue_next or grpc_completion_queue_pluck consequent to the failed grpc_call_start_batch call. If a call to grpc_call_start_batch with an empty batch returns GRPC_CALL_OK, the tag is put in the completion queue immediately. 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. Access to grpc_call_start_batch with an empty batch is thread-compatible.

◆ grpc_call_start_batch_and_execute()

grpc_call_error grpc_call_start_batch_and_execute ( grpc_call call,
const grpc_op ops,
size_t  nops,
grpc_closure closure 
)

◆ grpc_call_test_only_get_compression_algorithm()

grpc_compression_algorithm grpc_call_test_only_get_compression_algorithm ( grpc_call call)

Return the message compression algorithm from call.

Warning
This function should only be used in test code.

◆ grpc_call_test_only_get_encodings_accepted_by_peer()

uint32_t grpc_call_test_only_get_encodings_accepted_by_peer ( grpc_call call)

Returns a bitset for the encodings (compression algorithms) supported by call's peer.

To be indexed by grpc_compression_algorithm enum values.

◆ grpc_call_test_only_get_incoming_stream_encodings()

grpc_stream_compression_algorithm grpc_call_test_only_get_incoming_stream_encodings ( grpc_call call)

◆ grpc_call_test_only_get_message_flags()

uint32_t grpc_call_test_only_get_message_flags ( grpc_call call)

Return the message flags from call.

Warning
This function should only be used in test code.

◆ grpc_call_unref()

void grpc_call_unref ( grpc_call call)

Unref a call.

THREAD SAFETY: grpc_call_unref is thread-compatible

Variable Documentation

◆ grpc_call_error_trace

grpc_core::TraceFlag grpc_call_error_trace(false, "call_error") ( false  ,
"call_error"   
)

◆ grpc_compression_trace

grpc_core::TraceFlag grpc_compression_trace(false, "compression") ( false  ,
"compression"   
)