aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2015-08-09 13:52:19 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2015-08-10 09:12:20 -0700
commitb58b346fbebab3feb6ffa0122aca223bc2f63952 (patch)
tree3d80a17d94f41a2c53de5c9ab6682fa0691ec257
parent49a513031880a6303273f3fe3cec837225a5ad78 (diff)
wip. we need a way to pass args to server construction
-rw-r--r--include/grpc/compression.h1
-rw-r--r--src/core/channel/channel_args.c42
-rw-r--r--src/core/channel/channel_args.h14
-rw-r--r--test/cpp/interop/server.cc2
4 files changed, 57 insertions, 2 deletions
diff --git a/include/grpc/compression.h b/include/grpc/compression.h
index e35fb03eb2..a1a3236d3b 100644
--- a/include/grpc/compression.h
+++ b/include/grpc/compression.h
@@ -42,6 +42,7 @@ extern "C" {
/** To be used in channel arguments */
#define GRPC_COMPRESSION_ALGORITHM_ARG "grpc.compression_algorithm"
+#define GRPC_COMPRESSION_ALGORITHM_STATE_ARG "grpc.compression_algorithm_state"
/* The various compression algorithms supported by GRPC */
typedef enum {
diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c
index c430b56fa2..10199f7719 100644
--- a/src/core/channel/channel_args.c
+++ b/src/core/channel/channel_args.c
@@ -37,6 +37,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
+#include <grpc/support/useful.h>
#include <string.h>
@@ -146,3 +147,44 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm(
tmp.value.integer = algorithm;
return grpc_channel_args_copy_and_add(a, &tmp, 1);
}
+
+static gpr_uint32 find_compression_algorithm_states_bitset(
+ const grpc_channel_args *a) {
+ size_t i;
+ gpr_uint32 states_bitset = 0;
+ if (a == NULL) return 0;
+ for (i = 0; i < a->num_args; ++i) {
+ if (a->args[i].type == GRPC_ARG_INTEGER &&
+ !strcmp(GRPC_COMPRESSION_ALGORITHM_STATE_ARG, a->args[i].key)) {
+ states_bitset = a->args[i].value.integer;
+ break;
+ }
+ }
+ return states_bitset;
+}
+
+grpc_channel_args *grpc_channel_args_compression_algorithm_set_state(
+ grpc_channel_args *a,
+ grpc_compression_algorithm algorithm,
+ int state) {
+ gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a);
+ grpc_arg tmp;
+
+ if (state != 0) {
+ GPR_BITSET(&states_bitset, algorithm);
+ } else {
+ GPR_BITCLEAR(&states_bitset, algorithm);
+ }
+
+ tmp.type = GRPC_ARG_INTEGER;
+ tmp.key = GRPC_COMPRESSION_ALGORITHM_STATE_ARG;
+ tmp.value.integer = states_bitset;
+ return grpc_channel_args_copy_and_add(a, &tmp, 1);
+}
+
+int grpc_channel_args_compression_algorithm_get_state(
+ grpc_channel_args *a,
+ grpc_compression_algorithm algorithm) {
+ const gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a);
+ return GPR_BITGET(states_bitset, algorithm);
+}
diff --git a/src/core/channel/channel_args.h b/src/core/channel/channel_args.h
index 7e6ddd3997..f1a75117af 100644
--- a/src/core/channel/channel_args.h
+++ b/src/core/channel/channel_args.h
@@ -67,4 +67,18 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm(
grpc_channel_args *grpc_channel_args_set_compression_algorithm(
grpc_channel_args *a, grpc_compression_algorithm algorithm);
+/** Sets the support for the given compression algorithm. By default, all
+ * compression algorithms are enabled. Disabling an algorithm set by
+ * grpc_channel_args_set_compression_algorithm disables compression altogether
+ * */
+grpc_channel_args *grpc_channel_args_compression_algorithm_set_state(
+ grpc_channel_args *a,
+ grpc_compression_algorithm algorithm,
+ int enabled);
+
+/** Returns the state (true for enabled, false for disabled) for \a algorithm */
+int grpc_channel_args_compression_algorithm_get_state(
+ grpc_channel_args *a,
+ grpc_compression_algorithm algorithm);
+
#endif /* GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_ARGS_H */
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc
index 0097d1678c..0485e447e5 100644
--- a/test/cpp/interop/server.cc
+++ b/test/cpp/interop/server.cc
@@ -148,8 +148,6 @@ class TestServiceImpl : public TestService::Service {
return Status(grpc::StatusCode::INTERNAL, "Error creating payload.");
}
}
- const gpr_uint32 client_accept_encodings_bitset =
- inspector.GetEncodingsAcceptedByClient();
if (request->has_response_status()) {
return Status(static_cast<grpc::StatusCode>