Pass NULL as host by default. Use context.authority() or channel.SslNameOverride() when set.

pull/2749/head
yang-g 9 years ago
parent 5f8d05bb9c
commit d556da9f28
  1. 12
      src/cpp/client/channel.cc
  2. 5
      src/cpp/client/channel.h
  3. 4
      src/cpp/client/create_channel.cc
  4. 2
      src/cpp/client/insecure_credentials.cc
  5. 3
      src/cpp/client/secure_credentials.cc

@ -51,13 +51,16 @@
namespace grpc {
Channel::Channel(const grpc::string& target, grpc_channel* channel)
: target_(target), c_channel_(channel) {}
Channel::Channel(grpc_channel* channel) : c_channel_(channel) {}
Channel::Channel(const grpc::string& host, grpc_channel* channel)
: host_(host), c_channel_(channel) {}
Channel::~Channel() { grpc_channel_destroy(c_channel_); }
Call Channel::CreateCall(const RpcMethod& method, ClientContext* context,
CompletionQueue* cq) {
const char* host_str = host_.empty() ? NULL : host_.c_str();
auto c_call =
method.channel_tag() && context->authority().empty()
? grpc_channel_create_registered_call(c_channel_, cq->cq(),
@ -65,7 +68,7 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context,
context->raw_deadline())
: grpc_channel_create_call(c_channel_, cq->cq(), method.name(),
context->authority().empty()
? target_.c_str()
? host_str
: context->authority().c_str(),
context->raw_deadline());
grpc_census_call_set_context(c_call, context->census_context());
@ -86,7 +89,8 @@ void Channel::PerformOpsOnCall(CallOpSetInterface* ops, Call* call) {
}
void* Channel::RegisterMethod(const char* method) {
return grpc_channel_register_call(c_channel_, method, target_.c_str());
return grpc_channel_register_call(c_channel_, method,
host_.empty() ? NULL : host_.c_str());
}
} // namespace grpc

@ -52,7 +52,8 @@ class StreamContextInterface;
class Channel GRPC_FINAL : public GrpcLibrary, public ChannelInterface {
public:
Channel(const grpc::string& target, grpc_channel* c_channel);
explicit Channel(grpc_channel* c_channel);
Channel(const grpc::string& host, grpc_channel* c_channel);
~Channel() GRPC_OVERRIDE;
virtual void* RegisterMethod(const char* method) GRPC_OVERRIDE;
@ -62,7 +63,7 @@ class Channel GRPC_FINAL : public GrpcLibrary, public ChannelInterface {
Call* call) GRPC_OVERRIDE;
private:
const grpc::string target_;
const grpc::string host_;
grpc_channel* const c_channel_; // owned
};

@ -51,7 +51,7 @@ std::shared_ptr<ChannelInterface> CreateChannel(
cp_args.SetString(GRPC_ARG_PRIMARY_USER_AGENT_STRING,
user_agent_prefix.str());
return creds ? creds->CreateChannel(target, cp_args)
: std::shared_ptr<ChannelInterface>(new Channel(
target, grpc_lame_client_channel_create(NULL)));
: std::shared_ptr<ChannelInterface>(
new Channel(grpc_lame_client_channel_create(NULL)));
}
} // namespace grpc

@ -49,7 +49,7 @@ class InsecureCredentialsImpl GRPC_FINAL : public Credentials {
grpc_channel_args channel_args;
args.SetChannelArgs(&channel_args);
return std::shared_ptr<ChannelInterface>(new Channel(
target, grpc_insecure_channel_create(target.c_str(), &channel_args)));
grpc_insecure_channel_create(target.c_str(), &channel_args)));
}
// InsecureCredentials should not be applied to a call.

@ -44,8 +44,7 @@ std::shared_ptr<grpc::ChannelInterface> SecureCredentials::CreateChannel(
grpc_channel_args channel_args;
args.SetChannelArgs(&channel_args);
return std::shared_ptr<ChannelInterface>(new Channel(
args.GetSslTargetNameOverride().empty() ? target
: args.GetSslTargetNameOverride(),
args.GetSslTargetNameOverride(),
grpc_secure_channel_create(c_creds_, target.c_str(), &channel_args)));
}

Loading…
Cancel
Save