|
| ServerContext () |
|
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...
|
|
std::shared_ptr< const grpc::AuthContext > | auth_context () const |
| Return the authentication context for this server call. More...
|
|
grpc_call * | c_call () |
| Should be used for framework-level extensions only. More...
|
|
const struct census_context * | census_context () const |
| Get the census context associated with this server call. 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_algorithm | compression_algorithm () const |
| Return the compression algorithm the server call will request be used. More...
|
|
grpc_compression_level | compression_level () const |
| Return the compression algorithm to be used by 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...
|
|
std::chrono::system_clock::time_point | deadline () const |
| Return the deadline for the server call. More...
|
|
bool | IsCancelled () const |
| Return whether this RPC failed before the server could provide its status back to the client. More...
|
|
std::string | peer () const |
| Return the peer uri in a string. More...
|
|
gpr_timespec | raw_deadline () const |
| Return a gpr_timespec representation of the server call's deadline. More...
|
|
void | set_compression_algorithm (grpc_compression_algorithm algorithm) |
| Set algorithm to be the compression algorithm used for 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...
|
|
void | SetLoadReportingCosts (const std::vector< std::string > &cost_data) |
| Set the serialized load reporting costs in cost_data for the call. More...
|
|
void | TryCancel () const |
| Cancel the Call from the server. More...
|
|
void | AsyncNotifyWhenDone (void *tag) |
| Async only. More...
|
|
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::AuthContext > | auth_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_context * | census_context () const |
| Get the census context associated with this server call. More...
|
|
grpc_call * | c_call () |
| Should be used for framework-level extensions only. More...
|
|
experimental::CallMetricRecorder * | ExperimentalGetCallMetricRecorder () |
| Get the CallMetricRecorder object for the current RPC. More...
|
|
grpc::string_ref | ExperimentalGetAuthority () const |
| EXPERIMENTAL API Returns the call's authority. More...
|
|
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
- Add custom initial and trailing metadata key-value pairs that will propagated to the client side.
- Control call settings such as compression and authentication.
- Access metadata coming from the client.
- Get performance metrics (ie, census).
Context settings are only relevant to the call handler they are supplied to, that is to say, they aren't sticky across multiple calls. Some of these settings, such as the compression options, can be made persistent at server construction time by specifying the appropriate ChannelArguments to a grpc::ServerBuilder, via ServerBuilder::AddChannelArgument.
- Warning
- ServerContext instances should not be reused across rpcs.
bool grpc::ServerContextBase::IsCancelled |
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.
void grpc::ServerContextBase::TryCancel |
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).