GRPC C++  1.66.0
Data Structures | Public Member Functions | Protected Member Functions | Friends
grpc::ServerContextBase Class Reference

Base class of ServerContext. More...

#include <server_context.h>

Public Member Functions

virtual ~ServerContextBase ()
 
std::chrono::system_clock::time_point deadline () const
 Return the deadline for the server call. More...
 
gpr_timespec raw_deadline () const
 Return a gpr_timespec representation of the server call's deadline. More...
 
void AddInitialMetadata (const std::string &key, const std::string &value)
 Add the (key, value) pair to the initial metadata associated with a server call. More...
 
void AddTrailingMetadata (const std::string &key, const std::string &value)
 Add the (key, value) pair to the initial metadata associated with a server call. More...
 
bool IsCancelled () const
 Return whether this RPC failed before the server could provide its status back to the client. More...
 
void TryCancel () const
 Cancel the Call from the server. More...
 
const std::multimap< grpc::string_ref, grpc::string_ref > & client_metadata () const
 Return a collection of initial metadata key-value pairs sent from the client. More...
 
grpc_compression_level compression_level () const
 Return the compression algorithm to be used by the server call. More...
 
void set_compression_level (grpc_compression_level level)
 Set level to be the compression level used for the server call. More...
 
bool compression_level_set () const
 Return a bool indicating whether the compression level for this call has been set (either implicitly or through a previous call to set_compression_level. More...
 
grpc_compression_algorithm compression_algorithm () const
 Return the compression algorithm the server call will request be used. More...
 
void set_compression_algorithm (grpc_compression_algorithm algorithm)
 Set algorithm to be the compression algorithm used for the server call. More...
 
void SetLoadReportingCosts (const std::vector< std::string > &cost_data)
 Set the serialized load reporting costs in cost_data for the call. More...
 
std::shared_ptr< const grpc::AuthContextauth_context () const
 Return the authentication context for this server call. More...
 
std::string peer () const
 Return the peer uri in a string. More...
 
const struct census_contextcensus_context () const
 Get the census context associated with this server call. More...
 
grpc_callc_call ()
 Should be used for framework-level extensions only. More...
 
experimental::CallMetricRecorderExperimentalGetCallMetricRecorder ()
 Get the CallMetricRecorder object for the current RPC. More...
 
grpc::string_ref ExperimentalGetAuthority () const
 EXPERIMENTAL API Returns the call's authority. More...
 

Protected Member Functions

void AsyncNotifyWhenDone (void *tag)
 Async only. More...
 
RpcAllocatorStateGetRpcAllocatorState ()
 NOTE: This is an API for advanced users who need custom allocators. More...
 
grpc::ServerUnaryReactorDefaultReactor ()
 Get a library-owned default unary reactor for use in minimal reaction cases. More...
 
 ServerContextBase ()
 Constructors for use by derived classes. More...
 
 ServerContextBase (gpr_timespec deadline, grpc_metadata_array *arr)
 
void set_context_allocator (ContextAllocator *context_allocator)
 
ContextAllocatorcontext_allocator () const
 

Friends

class grpc::testing::InteropServerContextInspector
 
class grpc::testing::ServerContextTestSpouse
 
class grpc::testing::DefaultReactorTestPeer
 
class grpc::ServerInterface
 
class grpc::Server
 
template<class W , class R >
class grpc::ServerAsyncReader
 
template<class W >
class grpc::ServerAsyncWriter
 
template<class W >
class grpc::ServerAsyncResponseWriter
 
template<class W , class R >
class grpc::ServerAsyncReaderWriter
 
template<class R >
class grpc::ServerReader
 
template<class W >
class grpc::ServerWriter
 
template<class W , class R >
class grpc::internal::ServerReaderWriterBody
 
template<class ServiceType , class RequestType , class ResponseType , class BaseRequestType , class BaseResponseType >
class grpc::internal::RpcMethodHandler
 
template<class ServiceType , class RequestType , class ResponseType >
class grpc::internal::ClientStreamingHandler
 
template<class ServiceType , class RequestType , class ResponseType >
class grpc::internal::ServerStreamingHandler
 
template<class Streamer , bool WriteNeeded>
class grpc::internal::TemplatedBidiStreamingHandler
 
template<class RequestType , class ResponseType >
class grpc::internal::CallbackUnaryHandler
 
template<class RequestType , class ResponseType >
class grpc::internal::CallbackClientStreamingHandler
 
template<class RequestType , class ResponseType >
class grpc::internal::CallbackServerStreamingHandler
 
template<class RequestType , class ResponseType >
class grpc::internal::CallbackBidiHandler
 
template<grpc::StatusCode code>
class grpc::internal::ErrorMethodHandler
 
template<class Base >
class grpc::internal::FinishOnlyReactor
 
class grpc::ClientContext
 
class grpc::GenericServerContext
 
class grpc::GenericCallbackServerContext
 
template<class ResponseType >
void grpc::internal::UnaryRunHandlerHelper (const internal::MethodHandler::HandlerParameter &param, ResponseType *rsp, Status &status)
 

Detailed Description

Base class of ServerContext.

Constructor & Destructor Documentation

◆ ~ServerContextBase()

virtual grpc::ServerContextBase::~ServerContextBase ( )
virtual

◆ ServerContextBase() [1/2]

grpc::ServerContextBase::ServerContextBase ( )
protected

Constructors for use by derived classes.

◆ ServerContextBase() [2/2]

grpc::ServerContextBase::ServerContextBase ( gpr_timespec  deadline,
grpc_metadata_array arr 
)
protected

Member Function Documentation

◆ AddInitialMetadata()

void grpc::ServerContextBase::AddInitialMetadata ( const std::string &  key,
const std::string &  value 
)

Add the (key, value) pair to the initial metadata associated with a server call.

These are made available at the client side by the grpc::ClientContext::GetServerInitialMetadata() method.

Warning
This method should only be called before sending initial metadata to the client (which can happen explicitly, or implicitly when sending a a response message or status to the client).
Parameters
keyThe metadata key. If value is binary data, it must end in "-bin".
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
* 

◆ AddTrailingMetadata()

void grpc::ServerContextBase::AddTrailingMetadata ( const std::string &  key,
const std::string &  value 
)

Add the (key, value) pair to the initial metadata associated with a server call.

These are made available at the client side by the grpc::ClientContext::GetServerTrailingMetadata() method.

Warning
This method should only be called before sending trailing metadata to the client (which happens when the call is finished and a status is sent to the client).
Parameters
keyThe metadata key. If value is binary data, it must end in "-bin".
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
* 

◆ AsyncNotifyWhenDone()

void grpc::ServerContextBase::AsyncNotifyWhenDone ( void *  tag)
inlineprotected

Async only.

Has to be called before the rpc starts. Returns the tag in completion queue when the rpc finishes. IsCancelled() can then be called to check whether the rpc was cancelled. Note: the tag will only be returned if call starts. If the call never starts, this tag will not be returned.

◆ auth_context()

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

Return the authentication context for this server call.

See also
grpc::AuthContext.

◆ c_call()

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

Should be used for framework-level extensions only.

Applications never need to call this method.

◆ census_context()

const struct census_context* grpc::ServerContextBase::census_context ( ) const

Get the census context associated with this server call.

◆ client_metadata()

const std::multimap<grpc::string_ref, grpc::string_ref>& grpc::ServerContextBase::client_metadata ( ) const
inline

Return a collection of initial metadata key-value pairs sent from the client.

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

It is safe to use this method after initial metadata has been received, Calls always begin with the client sending initial metadata, so this is safe to access as soon as the call has begun on the server side.

Returns
A multimap of initial metadata key-value pairs from the server.

◆ compression_algorithm()

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

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

Note that the gRPC runtime may decide to ignore this request, for example, due to resource constraints, or if the server is aware the client doesn't support the requested algorithm.

◆ compression_level()

grpc_compression_level grpc::ServerContextBase::compression_level ( ) const
inline

Return the compression algorithm to be used by the server call.

◆ compression_level_set()

bool grpc::ServerContextBase::compression_level_set ( ) const
inline

Return a bool indicating whether the compression level for this call has been set (either implicitly or through a previous call to set_compression_level.

◆ context_allocator()

ContextAllocator* grpc::ServerContextBase::context_allocator ( ) const
inlineprotected

◆ deadline()

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

Return the deadline for the server call.

◆ DefaultReactor()

grpc::ServerUnaryReactor* grpc::ServerContextBase::DefaultReactor ( )
inlineprotected

Get a library-owned default unary reactor for use in minimal reaction cases.

This supports typical unary RPC usage of providing a response and status. It supports immediate Finish (finish from within the method handler) or delayed Finish (finish called after the method handler invocation). It does not support reacting to cancellation or completion, or early sending of initial metadata. Since this is a library-owned reactor, it should not be delete'd or freed in any way. This is more efficient than creating a user-owned reactor both because of avoiding an allocation and because its minimal reactions are optimized using a core surface flag that allows their reactions to run inline without any thread-hop.

This method should not be called more than once or called after return from the method handler.

◆ ExperimentalGetAuthority()

grpc::string_ref grpc::ServerContextBase::ExperimentalGetAuthority ( ) const

EXPERIMENTAL API Returns the call's authority.

◆ ExperimentalGetCallMetricRecorder()

experimental::CallMetricRecorder* grpc::ServerContextBase::ExperimentalGetCallMetricRecorder ( )
inline

Get the CallMetricRecorder object for the current RPC.

Use it to record metrics during your RPC to send back to the client in order to make load balancing decisions. This will return nullptr if the feature hasn't been enabled using EnableCallMetricRecording.

◆ GetRpcAllocatorState()

RpcAllocatorState* grpc::ServerContextBase::GetRpcAllocatorState ( )
inlineprotected

NOTE: This is an API for advanced users who need custom allocators.

Get and maybe mutate the allocator state associated with the current RPC. Currently only applicable for callback unary RPC methods.

◆ IsCancelled()

bool grpc::ServerContextBase::IsCancelled ( ) const

Return whether this RPC failed before the server could provide its status back to the client.

This could be because of explicit API cancellation from the client-side or server-side, because of deadline exceeded, network connection reset, HTTP/2 parameter configuration (e.g., max message size, max connection age), etc. It does NOT include failure due to a non-OK status return from the server application's request handler, including Status::CANCELLED.

IsCancelled is always safe to call when using sync or callback API. When using async API, it is only safe to call IsCancelled after the AsyncNotifyWhenDone tag has been delivered. Thread-safe.

◆ peer()

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

Return the peer uri in a string.

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.

◆ raw_deadline()

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

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

◆ set_compression_algorithm()

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

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

Parameters
algorithmThe compression algorithm used for the server call.

◆ set_compression_level()

void grpc::ServerContextBase::set_compression_level ( grpc_compression_level  level)
inline

Set level to be the compression level used for the server call.

Parameters
levelThe compression level used for the server call.

◆ set_context_allocator()

void grpc::ServerContextBase::set_context_allocator ( ContextAllocator context_allocator)
inlineprotected

◆ SetLoadReportingCosts()

void grpc::ServerContextBase::SetLoadReportingCosts ( const std::vector< std::string > &  cost_data)

Set the serialized load reporting costs in cost_data for the call.

◆ TryCancel()

void grpc::ServerContextBase::TryCancel ( ) const

Cancel the Call from the server.

This is a best-effort API and depending on when it is called, the RPC may still appear successful to the client. For example, if TryCancel() is called on a separate thread, it might race with the server handler which might return success to the client before TryCancel() was even started by the thread.

It is the caller's responsibility to prevent such races and ensure that if TryCancel() is called, the serverhandler must return Status::CANCELLED. The only exception is that if the serverhandler is already returning an error status code, it is ok to not return Status::CANCELLED even if TryCancel() was called. Additionally, it is illegal to invoke TryCancel() before the call has actually begun, i.e., before metadata has been received from the client.

For reasons such as the above, it is generally preferred to explicitly finish an RPC by returning Status::CANCELLED rather than using TryCancel.

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::ClientContext

friend class grpc::ClientContext
friend

◆ grpc::GenericCallbackServerContext

◆ grpc::GenericServerContext

friend class grpc::GenericServerContext
friend

◆ grpc::internal::CallbackBidiHandler

template<class RequestType , class ResponseType >
friend class grpc::internal::CallbackBidiHandler
friend

◆ grpc::internal::CallbackClientStreamingHandler

template<class RequestType , class ResponseType >
friend class grpc::internal::CallbackClientStreamingHandler
friend

◆ grpc::internal::CallbackServerStreamingHandler

template<class RequestType , class ResponseType >
friend class grpc::internal::CallbackServerStreamingHandler
friend

◆ grpc::internal::CallbackUnaryHandler

template<class RequestType , class ResponseType >
friend class grpc::internal::CallbackUnaryHandler
friend

◆ grpc::internal::ClientStreamingHandler

template<class ServiceType , class RequestType , class ResponseType >
friend class grpc::internal::ClientStreamingHandler
friend

◆ grpc::internal::ErrorMethodHandler

template<grpc::StatusCode code>
friend class grpc::internal::ErrorMethodHandler
friend

◆ grpc::internal::FinishOnlyReactor

template<class Base >
friend class grpc::internal::FinishOnlyReactor
friend

◆ grpc::internal::RpcMethodHandler

template<class ServiceType , class RequestType , class ResponseType , class BaseRequestType , class BaseResponseType >
friend class grpc::internal::RpcMethodHandler
friend

◆ grpc::internal::ServerReaderWriterBody

template<class W , class R >
friend class grpc::internal::ServerReaderWriterBody
friend

◆ grpc::internal::ServerStreamingHandler

template<class ServiceType , class RequestType , class ResponseType >
friend class grpc::internal::ServerStreamingHandler
friend

◆ grpc::internal::TemplatedBidiStreamingHandler

template<class Streamer , bool WriteNeeded>
friend class grpc::internal::TemplatedBidiStreamingHandler
friend

◆ grpc::internal::UnaryRunHandlerHelper

template<class ResponseType >
void grpc::internal::UnaryRunHandlerHelper ( const internal::MethodHandler::HandlerParameter param,
ResponseType *  rsp,
Status status 
)
friend

◆ grpc::Server

friend class grpc::Server
friend

◆ grpc::ServerAsyncReader

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

◆ grpc::ServerAsyncReaderWriter

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

◆ grpc::ServerAsyncResponseWriter

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

◆ grpc::ServerAsyncWriter

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

◆ grpc::ServerInterface

friend class grpc::ServerInterface
friend

◆ grpc::ServerReader

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

◆ grpc::ServerWriter

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

◆ grpc::testing::DefaultReactorTestPeer

friend class grpc::testing::DefaultReactorTestPeer
friend

◆ grpc::testing::InteropServerContextInspector

friend class grpc::testing::InteropServerContextInspector
friend

◆ grpc::testing::ServerContextTestSpouse

friend class grpc::testing::ServerContextTestSpouse
friend

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