GRPC C++  1.46.2
Data Structures | Public Member Functions | Static Public Member Functions | Friends
grpc::ClientContext Class Reference

A ClientContext allows the person implementing a service client to: More...

#include <client_context.h>

Data Structures

class  GlobalCallbacks
 Global Callbacks. More...
 

Public Member Functions

 ClientContext ()
 
 ~ClientContext ()
 
void AddMetadata (const std::string &meta_key, const std::string &meta_value)
 Add the (meta_key, meta_value) pair to the metadata associated with a client call. More...
 
const std::multimap< grpc::string_ref, grpc::string_ref > & GetServerInitialMetadata () const
 Return a collection of initial metadata key-value pairs. More...
 
const std::multimap< grpc::string_ref, grpc::string_ref > & GetServerTrailingMetadata () const
 Return a collection of trailing metadata key-value pairs. More...
 
template<typename T >
void set_deadline (const T &deadline)
 Set the deadline for the client call. More...
 
void set_wait_for_ready (bool wait_for_ready)
 Trigger wait-for-ready or not on this request. More...
 
void set_fail_fast (bool fail_fast)
 DEPRECATED: Use set_wait_for_ready() instead. More...
 
std::chrono::system_clock::time_point deadline () const
 Return the deadline for the client call. More...
 
gpr_timespec raw_deadline () const
 Return a gpr_timespec representation of the client call's deadline. More...
 
void set_authority (const std::string &authority)
 Set the per call authority header (see https://tools.ietf.org/html/rfc7540#section-8.1.2.3). More...
 
std::shared_ptr< const grpc::AuthContextauth_context () const
 Return the authentication context for the associated client call. More...
 
void set_credentials (const std::shared_ptr< grpc::CallCredentials > &creds)
 Set credentials for the client call. More...
 
std::shared_ptr< grpc::CallCredentialscredentials ()
 EXPERIMENTAL debugging API. More...
 
grpc_compression_algorithm compression_algorithm () const
 Return the compression algorithm the client call will request be used. More...
 
void set_compression_algorithm (grpc_compression_algorithm algorithm)
 Set algorithm to be the compression algorithm used for the client call. More...
 
void set_initial_metadata_corked (bool corked)
 Flag whether the initial metadata should be corked. More...
 
std::string peer () const
 Return the peer uri in a string. More...
 
void set_census_context (struct census_context *ccp)
 Sets the census context. More...
 
struct census_contextcensus_context () const
 Returns the census context that has been set, or nullptr if not set. More...
 
void TryCancel ()
 Send a best-effort out-of-band cancel on the call associated with this client context. More...
 
grpc_callc_call ()
 Should be used for framework-level extensions only. More...
 
std::string debug_error_string () const
 EXPERIMENTAL debugging API. More...
 

Static Public Member Functions

static std::unique_ptr< ClientContextFromServerContext (const grpc::ServerContextBase &server_context, PropagationOptions options=PropagationOptions())
 Create a new ClientContext as a child of an incoming server call, according to options (. More...
 
static std::unique_ptr< ClientContextFromCallbackServerContext (const grpc::CallbackServerContext &server_context, PropagationOptions options=PropagationOptions())
 
static void SetGlobalCallbacks (GlobalCallbacks *callbacks)
 

Friends

class grpc::testing::InteropClientContextInspector
 
class grpc::testing::ClientContextTestPeer
 
class grpc::internal::CallOpClientRecvStatus
 
class grpc::internal::CallOpRecvInitialMetadata
 
class grpc::Channel
 
template<class R >
class grpc::ClientReader
 
template<class W >
class grpc::ClientWriter
 
template<class W , class R >
class grpc::ClientReaderWriter
 
template<class R >
class grpc::ClientAsyncReader
 
template<class W >
class grpc::ClientAsyncWriter
 
template<class W , class R >
class grpc::ClientAsyncReaderWriter
 
template<class R >
class grpc::ClientAsyncResponseReader
 
class grpc::internal::ClientAsyncResponseReaderHelper
 
template<class InputMessage , class OutputMessage >
class grpc::internal::BlockingUnaryCallImpl
 
template<class InputMessage , class OutputMessage >
class grpc::internal::CallbackUnaryCallImpl
 
template<class Request , class Response >
class grpc::internal::ClientCallbackReaderWriterImpl
 
template<class Response >
class grpc::internal::ClientCallbackReaderImpl
 
template<class Request >
class grpc::internal::ClientCallbackWriterImpl
 
class grpc::internal::ClientCallbackUnaryImpl
 
class grpc::internal::ClientContextAccessor
 

Detailed Description

A ClientContext allows the person implementing a service client to:

Context settings are only relevant to the call they are invoked with, that is to say, they aren't sticky. Some of these settings, such as the compression options, can be made persistent at channel construction time (see grpc::CreateCustomChannel).

Warning
ClientContext instances should not be reused across rpcs.
The ClientContext instance used for creating an rpc must remain alive and valid for the lifetime of the rpc.

Constructor & Destructor Documentation

◆ ClientContext()

grpc::ClientContext::ClientContext ( )

◆ ~ClientContext()

grpc::ClientContext::~ClientContext ( )

Member Function Documentation

◆ AddMetadata()

void grpc::ClientContext::AddMetadata ( const std::string &  meta_key,
const std::string &  meta_value 
)

Add the (meta_key, meta_value) pair to the metadata associated with a client call.

These are made available at the server side by the grpc::ServerContext::client_metadata() method.

Warning
This method should only be called before invoking the rpc.
Parameters
meta_keyThe metadata key. If meta_value is binary data, it must end in "-bin".
meta_valueThe metadata value. If its value is binary, the key name must end in "-bin".

Metadata must conform to the following format:

Custom-Metadata -> Binary-Header / ASCII-Header
Binary-Header -> {Header-Name "-bin" } {binary value}
ASCII-Header -> Header-Name ASCII-Value
Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
Custom-Metadata -> Binary-Header / ASCII-Header

◆ auth_context()

std::shared_ptr<const grpc::AuthContext> grpc::ClientContext::auth_context ( ) const
inline

Return the authentication context for the associated client call.

It is only valid to call this during the lifetime of the client call.

See also
grpc::AuthContext.

◆ c_call()

grpc_call* grpc::ClientContext::c_call ( )
inline

Should be used for framework-level extensions only.

Applications never need to call this method.

◆ census_context()

struct census_context* grpc::ClientContext::census_context ( ) const
inline

Returns the census context that has been set, or nullptr if not set.

◆ compression_algorithm()

grpc_compression_algorithm grpc::ClientContext::compression_algorithm ( ) const
inline

Return the compression algorithm the client call will request be used.

Note that the gRPC runtime may decide to ignore this request, for example, due to resource constraints.

◆ credentials()

std::shared_ptr<grpc::CallCredentials> grpc::ClientContext::credentials ( )
inline

EXPERIMENTAL debugging API.

Returns the credentials for the client call. This should be used only in tests and for diagnostic purposes, and should not be used by application logic.

◆ deadline()

std::chrono::system_clock::time_point grpc::ClientContext::deadline ( ) const
inline

Return the deadline for the client call.

◆ debug_error_string()

std::string grpc::ClientContext::debug_error_string ( ) const
inline

EXPERIMENTAL debugging API.

if status is not ok() for an RPC, this will return a detailed string of the gRPC Core error that led to the failure. It should not be relied upon for anything other than gaining more debug data in failure cases.

◆ FromCallbackServerContext()

static std::unique_ptr<ClientContext> grpc::ClientContext::FromCallbackServerContext ( const grpc::CallbackServerContext server_context,
PropagationOptions  options = PropagationOptions() 
)
static

◆ FromServerContext()

static std::unique_ptr<ClientContext> grpc::ClientContext::FromServerContext ( const grpc::ServerContextBase server_context,
PropagationOptions  options = PropagationOptions() 
)
static

Create a new ClientContext as a child of an incoming server call, according to options (.

See also
PropagationOptions).
Parameters
server_contextThe source server context to use as the basis for constructing the client context.
optionsThe options controlling what to copy from the server_context.
Returns
A newly constructed ClientContext instance based on server_context, with traits propagated (copied) according to options.

◆ GetServerInitialMetadata()

const std::multimap<grpc::string_ref, grpc::string_ref>& grpc::ClientContext::GetServerInitialMetadata ( ) const
inline

Return a collection of initial metadata key-value pairs.

Note that keys may happen more than once (ie, a std::multimap is returned).

Warning
This method should only be called after initial metadata has been received. For streaming calls, see ClientReaderInterface::WaitForInitialMetadata().
Returns
A multimap of initial metadata key-value pairs from the server.

◆ GetServerTrailingMetadata()

const std::multimap<grpc::string_ref, grpc::string_ref>& grpc::ClientContext::GetServerTrailingMetadata ( ) const
inline

Return a collection of trailing metadata key-value pairs.

Note that keys may happen more than once (ie, a std::multimap is returned).

Warning
This method is only callable once the stream has finished.
Returns
A multimap of metadata trailing key-value pairs from the server.

◆ peer()

std::string grpc::ClientContext::peer ( ) const

Return the peer uri in a string.

It is only valid to call this during the lifetime of the client call.

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 auth_context.
Returns
The call's peer URI.

◆ raw_deadline()

gpr_timespec grpc::ClientContext::raw_deadline ( ) const
inline

Return a gpr_timespec representation of the client call's deadline.

◆ set_authority()

void grpc::ClientContext::set_authority ( const std::string &  authority)
inline

Set the per call authority header (see https://tools.ietf.org/html/rfc7540#section-8.1.2.3).

◆ set_census_context()

void grpc::ClientContext::set_census_context ( struct census_context ccp)
inline

Sets the census context.

It is only valid to call this before the client call is created. A common place of setting census context is from within the DefaultConstructor method of GlobalCallbacks.

◆ set_compression_algorithm()

void grpc::ClientContext::set_compression_algorithm ( grpc_compression_algorithm  algorithm)

Set algorithm to be the compression algorithm used for the client call.

Parameters
algorithmThe compression algorithm used for the client call.

◆ set_credentials()

void grpc::ClientContext::set_credentials ( const std::shared_ptr< grpc::CallCredentials > &  creds)

Set credentials for the client call.

A credentials object encapsulates all the state needed by a client to authenticate with a server and make various assertions, e.g., about the client’s identity, role, or whether it is authorized to make a particular call.

It is legal to call this only before initial metadata is sent.

See also
https://grpc.io/docs/guides/auth.html

◆ set_deadline()

template<typename T >
void grpc::ClientContext::set_deadline ( const T &  deadline)
inline

Set the deadline for the client call.

Warning
This method should only be called before invoking the rpc.
Parameters
deadlinethe deadline for the client call. Units are determined by the type used. The deadline is an absolute (not relative) time.

◆ set_fail_fast()

void grpc::ClientContext::set_fail_fast ( bool  fail_fast)
inline

DEPRECATED: Use set_wait_for_ready() instead.

◆ set_initial_metadata_corked()

void grpc::ClientContext::set_initial_metadata_corked ( bool  corked)
inline

Flag whether the initial metadata should be corked.

If corked is true, then the initial metadata will be coalesced with the write of first message in the stream. As a result, any tag set for the initial metadata operation (starting a client-streaming or bidi-streaming RPC) will not actually be sent to the completion queue or delivered via Next.

Parameters
corkedThe flag indicating whether the initial metadata is to be corked or not.

◆ set_wait_for_ready()

void grpc::ClientContext::set_wait_for_ready ( bool  wait_for_ready)
inline

Trigger wait-for-ready or not on this request.

See https://github.com/grpc/grpc/blob/master/doc/wait-for-ready.md. If set, if an RPC is made when a channel's connectivity state is TRANSIENT_FAILURE or CONNECTING, the call will not "fail fast", and the channel will wait until the channel is READY before making the call.

◆ SetGlobalCallbacks()

static void grpc::ClientContext::SetGlobalCallbacks ( GlobalCallbacks callbacks)
static

◆ TryCancel()

void grpc::ClientContext::TryCancel ( )

Send a best-effort out-of-band cancel on the call associated with this client context.

The call could be in any stage; e.g., if it is already finished, it may still return success.

There is no guarantee the call will be cancelled.

Note that TryCancel() does not change any of the tags that are pending on the completion queue. All pending tags will still be delivered (though their ok result may reflect the effect of cancellation).

Friends And Related Function Documentation

◆ grpc::Channel

friend class grpc::Channel
friend

◆ grpc::ClientAsyncReader

template<class R >
friend class grpc::ClientAsyncReader
friend

◆ grpc::ClientAsyncReaderWriter

template<class W , class R >
friend class grpc::ClientAsyncReaderWriter
friend

◆ grpc::ClientAsyncResponseReader

template<class R >
friend class grpc::ClientAsyncResponseReader
friend

◆ grpc::ClientAsyncWriter

template<class W >
friend class grpc::ClientAsyncWriter
friend

◆ grpc::ClientReader

template<class R >
friend class grpc::ClientReader
friend

◆ grpc::ClientReaderWriter

template<class W , class R >
friend class grpc::ClientReaderWriter
friend

◆ grpc::ClientWriter

template<class W >
friend class grpc::ClientWriter
friend

◆ grpc::internal::BlockingUnaryCallImpl

template<class InputMessage , class OutputMessage >
friend class grpc::internal::BlockingUnaryCallImpl
friend

◆ grpc::internal::CallbackUnaryCallImpl

template<class InputMessage , class OutputMessage >
friend class grpc::internal::CallbackUnaryCallImpl
friend

◆ grpc::internal::CallOpClientRecvStatus

◆ grpc::internal::CallOpRecvInitialMetadata

◆ grpc::internal::ClientAsyncResponseReaderHelper

◆ grpc::internal::ClientCallbackReaderImpl

template<class Response >
friend class grpc::internal::ClientCallbackReaderImpl
friend

◆ grpc::internal::ClientCallbackReaderWriterImpl

template<class Request , class Response >
friend class grpc::internal::ClientCallbackReaderWriterImpl
friend

◆ grpc::internal::ClientCallbackUnaryImpl

◆ grpc::internal::ClientCallbackWriterImpl

template<class Request >
friend class grpc::internal::ClientCallbackWriterImpl
friend

◆ grpc::internal::ClientContextAccessor

friend class grpc::internal::ClientContextAccessor
friend

◆ grpc::testing::ClientContextTestPeer

friend class grpc::testing::ClientContextTestPeer
friend

◆ grpc::testing::InteropClientContextInspector

friend class grpc::testing::InteropClientContextInspector
friend

The documentation for this class was generated from the following file: