From de3daf5d630fdd4396ed37b59d9550d5665b1e58 Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Thu, 13 Oct 2016 17:26:26 -0700 Subject: More interfaces for grpc_socket_mutator --- src/cpp/common/channel_arguments.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/cpp/common') diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index f297ae8587..ae56409a54 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -37,7 +37,7 @@ #include #include #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, -- cgit v1.2.3