aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/client
diff options
context:
space:
mode:
authorGravatar jboeuf <jboeuf@users.noreply.github.com>2015-08-03 15:29:49 -0700
committerGravatar jboeuf <jboeuf@users.noreply.github.com>2015-08-03 15:29:49 -0700
commit0945420b348176fa176f2fd544e430ecedaa182c (patch)
treebc4091d4fafc5421ac3f2799621b1dda29394ce6 /src/cpp/client
parenta87d6c2af6a8bbad50d9ad639873357fd824b791 (diff)
parent45ce927c7cf7abbdb452989d6d58c875a800e4ea (diff)
Merge pull request #2 from ctiller/complain-with-both-passion-and-meaning
Fixes for sending status from the server
Diffstat (limited to 'src/cpp/client')
-rw-r--r--src/cpp/client/channel.cc3
-rw-r--r--src/cpp/client/channel_arguments.cc43
-rw-r--r--src/cpp/client/client_context.cc21
-rw-r--r--src/cpp/client/create_channel.cc13
-rw-r--r--src/cpp/client/insecure_credentials.cc2
-rw-r--r--src/cpp/client/secure_credentials.cc14
6 files changed, 79 insertions, 17 deletions
diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc
index da31d000b3..5df81e641e 100644
--- a/src/cpp/client/channel.cc
+++ b/src/cpp/client/channel.cc
@@ -39,7 +39,6 @@
#include <grpc/support/log.h>
#include <grpc/support/slice.h>
-#include "src/core/census/grpc_context.h"
#include "src/core/profiling/timers.h"
#include <grpc++/channel_arguments.h>
#include <grpc++/client_context.h>
@@ -69,7 +68,7 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context,
? target_.c_str()
: context->authority().c_str(),
context->raw_deadline());
- grpc_census_call_set_context(c_call, context->get_census_context());
+ grpc_census_call_set_context(c_call, context->census_context());
GRPC_TIMER_MARK(GRPC_PTAG_CPP_CALL_CREATED, c_call);
context->set_call(c_call, shared_from_this());
return Call(c_call, this, cq);
diff --git a/src/cpp/client/channel_arguments.cc b/src/cpp/client/channel_arguments.cc
index b271650673..da6602e7af 100644
--- a/src/cpp/client/channel_arguments.cc
+++ b/src/cpp/client/channel_arguments.cc
@@ -33,12 +33,51 @@
#include <grpc++/channel_arguments.h>
+#include <grpc/support/log.h>
+
#include "src/core/channel/channel_args.h"
namespace grpc {
-void ChannelArguments::SetCompressionLevel(grpc_compression_level level) {
- SetInt(GRPC_COMPRESSION_LEVEL_ARG, level);
+ChannelArguments::ChannelArguments(const ChannelArguments& other)
+ : strings_(other.strings_) {
+ args_.reserve(other.args_.size());
+ auto list_it_dst = strings_.begin();
+ auto list_it_src = other.strings_.begin();
+ for (auto a = other.args_.begin(); a != other.args_.end(); ++a) {
+ grpc_arg ap;
+ ap.type = a->type;
+ GPR_ASSERT(list_it_src->c_str() == a->key);
+ ap.key = const_cast<char*>(list_it_dst->c_str());
+ ++list_it_src;
+ ++list_it_dst;
+ switch (a->type) {
+ case GRPC_ARG_INTEGER:
+ ap.value.integer = a->value.integer;
+ break;
+ case GRPC_ARG_STRING:
+ GPR_ASSERT(list_it_src->c_str() == a->value.string);
+ ap.value.string = const_cast<char*>(list_it_dst->c_str());
+ ++list_it_src;
+ ++list_it_dst;
+ break;
+ case GRPC_ARG_POINTER:
+ ap.value.pointer = a->value.pointer;
+ ap.value.pointer.p = a->value.pointer.copy(ap.value.pointer.p);
+ break;
+ }
+ args_.push_back(ap);
+ }
+}
+
+void ChannelArguments::Swap(ChannelArguments& other) {
+ args_.swap(other.args_);
+ strings_.swap(other.strings_);
+}
+
+void ChannelArguments::SetCompressionAlgorithm(
+ grpc_compression_algorithm algorithm) {
+ SetInt(GRPC_COMPRESSION_ALGORITHM_ARG, algorithm);
}
void ChannelArguments::SetInt(const grpc::string& key, int value) {
diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc
index c68f6dd9f8..14ab772e50 100644
--- a/src/cpp/client/client_context.cc
+++ b/src/cpp/client/client_context.cc
@@ -34,8 +34,11 @@
#include <grpc++/client_context.h>
#include <grpc/grpc.h>
+#include <grpc/support/string_util.h>
#include <grpc++/credentials.h>
#include <grpc++/time.h>
+
+#include "src/core/channel/compress_filter.h"
#include "src/cpp/common/create_auth_context.h"
namespace grpc {
@@ -44,7 +47,7 @@ ClientContext::ClientContext()
: initial_metadata_received_(false),
call_(nullptr),
cq_(nullptr),
- deadline_(gpr_inf_future) {}
+ deadline_(gpr_inf_future(GPR_CLOCK_REALTIME)) {}
ClientContext::~ClientContext() {
if (call_) {
@@ -53,8 +56,8 @@ ClientContext::~ClientContext() {
if (cq_) {
// Drain cq_.
grpc_completion_queue_shutdown(cq_);
- while (grpc_completion_queue_next(cq_, gpr_inf_future).type !=
- GRPC_QUEUE_SHUTDOWN)
+ while (grpc_completion_queue_next(cq_, gpr_inf_future(GPR_CLOCK_REALTIME))
+ .type != GRPC_QUEUE_SHUTDOWN)
;
grpc_completion_queue_destroy(cq_);
}
@@ -76,6 +79,18 @@ void ClientContext::set_call(grpc_call* call,
}
}
+void ClientContext::set_compression_algorithm(
+ grpc_compression_algorithm algorithm) {
+ char* algorithm_name = NULL;
+ if (!grpc_compression_algorithm_name(algorithm, &algorithm_name)) {
+ gpr_log(GPR_ERROR, "Name for compression algorithm '%d' unknown.",
+ algorithm);
+ abort();
+ }
+ GPR_ASSERT(algorithm_name != NULL);
+ AddMetadata(GRPC_COMPRESS_REQUEST_ALGORITHM_KEY, algorithm_name);
+}
+
std::shared_ptr<const AuthContext> ClientContext::auth_context() const {
if (auth_context_.get() == nullptr) {
auth_context_ = CreateAuthContext(call_);
diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc
index 510af2bb00..dbe2694a78 100644
--- a/src/cpp/client/create_channel.cc
+++ b/src/cpp/client/create_channel.cc
@@ -32,9 +32,11 @@
*/
#include <memory>
+#include <sstream>
#include "src/cpp/client/channel.h"
#include <grpc++/channel_interface.h>
+#include <grpc++/channel_arguments.h>
#include <grpc++/create_channel.h>
namespace grpc {
@@ -43,8 +45,13 @@ class ChannelArguments;
std::shared_ptr<ChannelInterface> CreateChannel(
const grpc::string& target, const std::shared_ptr<Credentials>& creds,
const ChannelArguments& args) {
- return creds ? creds->CreateChannel(target, args)
- : std::shared_ptr<ChannelInterface>(
- new Channel(target, grpc_lame_client_channel_create()));
+ ChannelArguments cp_args = args;
+ std::ostringstream user_agent_prefix;
+ user_agent_prefix << "grpc-c++/" << grpc_version_string();
+ 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)));
}
} // namespace grpc
diff --git a/src/cpp/client/insecure_credentials.cc b/src/cpp/client/insecure_credentials.cc
index 5ad8784567..e802fa8034 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_channel_create(target.c_str(), &channel_args)));
+ target, 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 4d200908fb..abf0cb387e 100644
--- a/src/cpp/client/secure_credentials.cc
+++ b/src/cpp/client/secure_credentials.cc
@@ -92,22 +92,24 @@ std::shared_ptr<Credentials> ServiceAccountCredentials(
"with non-positive lifetime");
return WrapCredentials(nullptr);
}
- gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime_seconds);
+ gpr_timespec lifetime =
+ gpr_time_from_seconds(token_lifetime_seconds, GPR_TIMESPAN);
return WrapCredentials(grpc_service_account_credentials_create(
json_key.c_str(), scope.c_str(), lifetime));
}
// Builds JWT credentials.
-std::shared_ptr<Credentials> JWTCredentials(const grpc::string& json_key,
- long token_lifetime_seconds) {
+std::shared_ptr<Credentials> ServiceAccountJWTAccessCredentials(
+ const grpc::string& json_key, long token_lifetime_seconds) {
if (token_lifetime_seconds <= 0) {
gpr_log(GPR_ERROR,
"Trying to create JWTCredentials with non-positive lifetime");
return WrapCredentials(nullptr);
}
- gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime_seconds);
- return WrapCredentials(
- grpc_jwt_credentials_create(json_key.c_str(), lifetime));
+ gpr_timespec lifetime =
+ gpr_time_from_seconds(token_lifetime_seconds, GPR_TIMESPAN);
+ return WrapCredentials(grpc_service_account_jwt_access_credentials_create(
+ json_key.c_str(), lifetime));
}
// Builds refresh token credentials.