TryCancel() on ServerContext()

pull/4958/head
Sree Kuchibhotla 9 years ago
parent 7fbc0acf4a
commit 7fa9d6f4c8
  1. 3
      include/grpc++/impl/codegen/server_context.h
  2. 16
      src/cpp/server/server_context.cc

@ -105,6 +105,9 @@ class ServerContext {
bool IsCancelled() const;
// Best-effort API to cancel the call from the server.
void TryCancel() const;
const std::multimap<grpc::string_ref, grpc::string_ref>& client_metadata() {
return client_metadata_;
}

@ -33,14 +33,14 @@
#include <grpc++/server_context.h>
#include <grpc/compression.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc++/completion_queue.h>
#include <grpc++/impl/call.h>
#include <grpc++/impl/sync.h>
#include <grpc++/support/time.h>
#include <grpc/compression.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/channel/compress_filter.h"
#include "src/cpp/common/create_auth_context.h"
@ -173,6 +173,14 @@ void ServerContext::AddTrailingMetadata(const grpc::string& key,
trailing_metadata_.insert(std::make_pair(key, value));
}
void ServerContext::TryCancel() const {
grpc_call_error err = grpc_call_cancel_with_status(
call_, GRPC_STATUS_CANCELLED, "Cancelled on the server side", NULL);
if (err != GRPC_CALL_OK) {
gpr_log(GPR_INFO, "TryCancel failed with: %d", err);
}
}
bool ServerContext::IsCancelled() const {
return completion_op_ && completion_op_->CheckCancelled(cq_);
}

Loading…
Cancel
Save