diff options
author | David Garcia Quintas <dgq@google.com> | 2016-11-14 17:55:13 -0800 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2016-11-14 17:55:13 -0800 |
commit | d03afbdeba47c15b00916ecf62e53192e1f8412b (patch) | |
tree | e41f441085bb8a983d7bddb4d3f99dbb55f40187 /src/cpp/common/channel_arguments.cc | |
parent | 5f50a1baaa92eb6b361a8e5f4cf0b3b31623380d (diff) | |
parent | b794a9687587bc5ede33e60aea140b3283dc8915 (diff) |
Merge branch 'master' of github.com:grpc/grpc into rr_fixall
Diffstat (limited to 'src/cpp/common/channel_arguments.cc')
-rw-r--r-- | src/cpp/common/channel_arguments.cc | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index c6cad8eeae..0067d6c5e1 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -34,18 +34,17 @@ #include <sstream> +#include <grpc++/grpc++.h> #include <grpc++/resource_quota.h> #include <grpc/impl/codegen/grpc_types.h> #include <grpc/support/log.h> #include "src/core/lib/channel/channel_args.h" - +#include "src/core/lib/iomgr/socket_mutator.h" namespace grpc { ChannelArguments::ChannelArguments() { - std::ostringstream user_agent_prefix; - user_agent_prefix << "grpc-c++/" << grpc_version_string(); // This will be ignored if used on the server side. - SetString(GRPC_ARG_PRIMARY_USER_AGENT_STRING, user_agent_prefix.str()); + SetString(GRPC_ARG_PRIMARY_USER_AGENT_STRING, "grpc-c++/" + Version()); } ChannelArguments::ChannelArguments(const ChannelArguments& other) @@ -89,6 +88,24 @@ void ChannelArguments::SetCompressionAlgorithm( SetInt(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, algorithm); } +void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { + if (!mutator) { + return; + } + grpc_arg mutator_arg = grpc_socket_mutator_to_arg(mutator); + bool replaced = false; + for (auto it = args_.begin(); it != args_.end(); ++it) { + if (it->type == mutator_arg.type && + grpc::string(it->key) == grpc::string(mutator_arg.key)) { + it->value.pointer.vtable->destroy(it->value.pointer.p); + it->value.pointer = mutator_arg.value.pointer; + } + } + if (!replaced) { + args_.push_back(mutator_arg); + } +} + // Note: a second call to this will add in front the result of the first call. // An example is calling this on a copy of ChannelArguments which already has a // prefix. The user can build up a prefix string by calling this multiple times, |