aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp
diff options
context:
space:
mode:
authorGravatar Hongwei Wang <hongweiw@google.com>2015-08-05 11:21:15 -0700
committerGravatar Hongwei Wang <hongweiw@google.com>2015-08-05 11:21:15 -0700
commit4346e53be633898d60c0bea2d674de11cf69a8e3 (patch)
treeb6aa06e4dc4488945a5f1299985ef9f3ac9e053e /src/cpp
parent00e9c60c87d3d9351759551ce662c1b9572f7ced (diff)
parent183c9f77a7506b4eeebc58ca5a98069d9617eced (diff)
Merge branch 'master' of https://github.com/grpc/grpc into zookeeper
Diffstat (limited to 'src/cpp')
-rw-r--r--src/cpp/client/channel.cc12
-rw-r--r--src/cpp/client/channel.h5
-rw-r--r--src/cpp/client/create_channel.cc4
-rw-r--r--src/cpp/client/insecure_credentials.cc2
-rw-r--r--src/cpp/client/secure_credentials.cc3
-rw-r--r--src/cpp/server/insecure_server_credentials.cc2
-rw-r--r--src/cpp/server/server_context.cc23
7 files changed, 37 insertions, 14 deletions
diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc
index 5df81e641e..ee143d68a0 100644
--- a/src/cpp/client/channel.cc
+++ b/src/cpp/client/channel.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
diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h
index 9108713c58..8660146856 100644
--- a/src/cpp/client/channel.h
+++ b/src/cpp/client/channel.h
@@ -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
};
diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc
index dbe2694a78..21d01b739d 100644
--- a/src/cpp/client/create_channel.cc
+++ b/src/cpp/client/create_channel.cc
@@ -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
diff --git a/src/cpp/client/insecure_credentials.cc b/src/cpp/client/insecure_credentials.cc
index e802fa8034..d8dcaa1436 100644
--- a/src/cpp/client/insecure_credentials.cc
+++ b/src/cpp/client/insecure_credentials.cc
@@ -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.
diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc
index abf0cb387e..2d6114e06b 100644
--- a/src/cpp/client/secure_credentials.cc
+++ b/src/cpp/client/secure_credentials.cc
@@ -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)));
}
diff --git a/src/cpp/server/insecure_server_credentials.cc b/src/cpp/server/insecure_server_credentials.cc
index aca3568e59..800cd36caa 100644
--- a/src/cpp/server/insecure_server_credentials.cc
+++ b/src/cpp/server/insecure_server_credentials.cc
@@ -41,7 +41,7 @@ class InsecureServerCredentialsImpl GRPC_FINAL : public ServerCredentials {
public:
int AddPortToServer(const grpc::string& addr,
grpc_server* server) GRPC_OVERRIDE {
- return grpc_server_add_http2_port(server, addr.c_str());
+ return grpc_server_add_insecure_http2_port(server, addr.c_str());
}
};
} // namespace
diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc
index cf19556e7a..04373397f9 100644
--- a/src/cpp/server/server_context.cc
+++ b/src/cpp/server/server_context.cc
@@ -50,16 +50,23 @@ namespace grpc {
class ServerContext::CompletionOp GRPC_FINAL : public CallOpSetInterface {
public:
// initial refs: one in the server context, one in the cq
- CompletionOp() : refs_(2), finalized_(false), cancelled_(0) {}
+ CompletionOp() : has_tag_(false), tag_(nullptr), refs_(2), finalized_(false), cancelled_(0) {}
void FillOps(grpc_op* ops, size_t* nops) GRPC_OVERRIDE;
bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE;
bool CheckCancelled(CompletionQueue* cq);
+ void set_tag(void* tag) {
+ has_tag_ = true;
+ tag_ = tag;
+ }
+
void Unref();
private:
+ bool has_tag_;
+ void* tag_;
grpc::mutex mu_;
int refs_;
bool finalized_;
@@ -90,18 +97,25 @@ void ServerContext::CompletionOp::FillOps(grpc_op* ops, size_t* nops) {
bool ServerContext::CompletionOp::FinalizeResult(void** tag, bool* status) {
grpc::unique_lock<grpc::mutex> lock(mu_);
finalized_ = true;
+ bool ret = false;
+ if (has_tag_) {
+ *tag = tag_;
+ ret = true;
+ }
if (!*status) cancelled_ = 1;
if (--refs_ == 0) {
lock.unlock();
delete this;
}
- return false;
+ return ret;
}
// ServerContext body
ServerContext::ServerContext()
: completion_op_(nullptr),
+ has_notify_when_done_tag_(false),
+ async_notify_when_done_tag_(nullptr),
call_(nullptr),
cq_(nullptr),
sent_initial_metadata_(false) {}
@@ -109,6 +123,8 @@ ServerContext::ServerContext()
ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata,
size_t metadata_count)
: completion_op_(nullptr),
+ has_notify_when_done_tag_(false),
+ async_notify_when_done_tag_(nullptr),
deadline_(deadline),
call_(nullptr),
cq_(nullptr),
@@ -133,6 +149,9 @@ ServerContext::~ServerContext() {
void ServerContext::BeginCompletionOp(Call* call) {
GPR_ASSERT(!completion_op_);
completion_op_ = new CompletionOp();
+ if (has_notify_when_done_tag_) {
+ completion_op_->set_tag(async_notify_when_done_tag_);
+ }
call->PerformOps(completion_op_);
}