Merge pull request #2890 from yang-g/client_context

client code clean up
pull/2917/head
David G. Quintas 9 years ago
commit edb1d616dc
  1. 4
      include/grpc++/client_context.h
  2. 32
      src/cpp/client/channel.cc
  3. 9
      src/cpp/client/client_context.cc

@ -218,15 +218,11 @@ class ClientContext {
void set_call(grpc_call* call, void set_call(grpc_call* call,
const std::shared_ptr<ChannelInterface>& channel); const std::shared_ptr<ChannelInterface>& channel);
grpc_completion_queue* cq() { return cq_; }
void set_cq(grpc_completion_queue* cq) { cq_ = cq; }
grpc::string authority() { return authority_; } grpc::string authority() { return authority_; }
bool initial_metadata_received_; bool initial_metadata_received_;
std::shared_ptr<ChannelInterface> channel_; std::shared_ptr<ChannelInterface> channel_;
grpc_call* call_; grpc_call* call_;
grpc_completion_queue* cq_;
gpr_timespec deadline_; gpr_timespec deadline_;
grpc::string authority_; grpc::string authority_;
std::shared_ptr<Credentials> creds_; std::shared_ptr<Credentials> creds_;

@ -61,19 +61,25 @@ Channel::~Channel() { grpc_channel_destroy(c_channel_); }
Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, Call Channel::CreateCall(const RpcMethod& method, ClientContext* context,
CompletionQueue* cq) { CompletionQueue* cq) {
const char* host_str = host_.empty() ? NULL : host_.c_str(); const bool kRegistered = method.channel_tag() && context->authority().empty();
auto c_call = method.channel_tag() && context->authority().empty() grpc_call* c_call = NULL;
? grpc_channel_create_registered_call( if (kRegistered) {
c_channel_, context->propagate_from_call_, c_call = grpc_channel_create_registered_call(
context->propagation_options_.c_bitmask(), cq->cq(), c_channel_, context->propagate_from_call_,
method.channel_tag(), context->raw_deadline()) context->propagation_options_.c_bitmask(), cq->cq(),
: grpc_channel_create_call( method.channel_tag(), context->raw_deadline());
c_channel_, context->propagate_from_call_, } else {
context->propagation_options_.c_bitmask(), cq->cq(), const char* host_str = NULL;
method.name(), context->authority().empty() if (!context->authority().empty()) {
? host_str host_str = context->authority().c_str();
: context->authority().c_str(), } else if (!host_.empty()) {
context->raw_deadline()); host_str = host_.c_str();
}
c_call = grpc_channel_create_call(c_channel_, context->propagate_from_call_,
context->propagation_options_.c_bitmask(),
cq->cq(), method.name(), host_str,
context->raw_deadline());
}
grpc_census_call_set_context(c_call, context->census_context()); grpc_census_call_set_context(c_call, context->census_context());
GRPC_TIMER_MARK(GRPC_PTAG_CPP_CALL_CREATED, c_call); GRPC_TIMER_MARK(GRPC_PTAG_CPP_CALL_CREATED, c_call);
context->set_call(c_call, shared_from_this()); context->set_call(c_call, shared_from_this());

@ -48,7 +48,6 @@ namespace grpc {
ClientContext::ClientContext() ClientContext::ClientContext()
: initial_metadata_received_(false), : initial_metadata_received_(false),
call_(nullptr), call_(nullptr),
cq_(nullptr),
deadline_(gpr_inf_future(GPR_CLOCK_REALTIME)), deadline_(gpr_inf_future(GPR_CLOCK_REALTIME)),
propagate_from_call_(nullptr) {} propagate_from_call_(nullptr) {}
@ -56,14 +55,6 @@ ClientContext::~ClientContext() {
if (call_) { if (call_) {
grpc_call_destroy(call_); grpc_call_destroy(call_);
} }
if (cq_) {
// Drain cq_.
grpc_completion_queue_shutdown(cq_);
while (grpc_completion_queue_next(cq_, gpr_inf_future(GPR_CLOCK_REALTIME))
.type != GRPC_QUEUE_SHUTDOWN)
;
grpc_completion_queue_destroy(cq_);
}
} }
std::unique_ptr<ClientContext> ClientContext::FromServerContext( std::unique_ptr<ClientContext> ClientContext::FromServerContext(

Loading…
Cancel
Save