diff options
author | Yuchen Zeng <y-zeng@users.noreply.github.com> | 2016-11-11 15:05:14 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-11 15:05:14 -0800 |
commit | 5c1f55af232ef50f690d5e9c12fee21f635f0952 (patch) | |
tree | d43c94450b62ebcfe98a3f307994608118f8cb35 /src/cpp/common | |
parent | aaefa958d796e8f9ec1fe48df61ca0fd9425be48 (diff) | |
parent | 67ffe3f82de4d860f1d39f9ace55a6731e82a69c (diff) |
Merge pull request #8335 from y-zeng/tos
Add grpc_socket_mutator
Diffstat (limited to 'src/cpp/common')
-rw-r--r-- | src/cpp/common/channel_arguments.cc | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index d86ba9dd4e..0067d6c5e1 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -39,7 +39,7 @@ #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() { @@ -88,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, |