diff options
author | Yuchen Zeng <zyc@google.com> | 2016-10-13 17:26:26 -0700 |
---|---|---|
committer | Yuchen Zeng <zyc@google.com> | 2016-10-13 17:26:26 -0700 |
commit | de3daf5d630fdd4396ed37b59d9550d5665b1e58 (patch) | |
tree | 11e9d9061f1739de16341636118c209ffdfb5336 /src/cpp/common | |
parent | a4f708a4c4af88e114209eb29f625c4d4d935bb4 (diff) |
More interfaces for 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 f297ae8587..ae56409a54 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -37,7 +37,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, |