wip. we need a way to pass args to server construction

pull/2533/head
David Garcia Quintas 9 years ago
parent 49a5130318
commit 87b4f2b23f
  1. 1
      include/grpc/compression.h
  2. 42
      src/core/channel/channel_args.c
  3. 14
      src/core/channel/channel_args.h
  4. 2
      test/cpp/interop/server.cc

@ -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 {

@ -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);
}

@ -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 */

@ -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>

Loading…
Cancel
Save