aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/common/channel_arguments.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpp/common/channel_arguments.cc')
-rw-r--r--src/cpp/common/channel_arguments.cc25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc
index d86ba9dd4e..bc0b68b3e0 100644
--- a/src/cpp/common/channel_arguments.cc
+++ b/src/cpp/common/channel_arguments.cc
@@ -38,8 +38,11 @@
#include <grpc++/resource_quota.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/support/log.h>
+extern "C" {
#include "src/core/lib/channel/channel_args.h"
-
+#include "src/core/lib/iomgr/exec_ctx.h"
+#include "src/core/lib/iomgr/socket_mutator.h"
+}
namespace grpc {
ChannelArguments::ChannelArguments() {
@@ -88,6 +91,26 @@ 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;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ 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(&exec_ctx, it->value.pointer.p);
+ it->value.pointer = mutator_arg.value.pointer;
+ }
+ }
+ grpc_exec_ctx_finish(&exec_ctx);
+ 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,