Add function to create channel arg for client channel factory.

pull/8795/head
Mark D. Roth 8 years ago
parent 389f272b49
commit c217e490b1
  1. 32
      src/core/ext/client_channel/client_channel_factory.c
  2. 3
      src/core/ext/client_channel/client_channel_factory.h
  3. 18
      src/core/ext/transport/chttp2/client/insecure/channel_create.c
  4. 27
      src/core/ext/transport/chttp2/client/secure/secure_channel_create.c

@ -55,3 +55,35 @@ grpc_channel* grpc_client_channel_factory_create_channel(
return factory->vtable->create_client_channel(exec_ctx, factory, target, type,
args);
}
static void *factory_arg_copy(void *factory) {
grpc_client_channel_factory_ref(factory);
return factory;
}
static void factory_arg_destroy(void *factory) {
// TODO(roth): Remove local exec_ctx when
// https://github.com/grpc/grpc/pull/8705 is merged.
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_client_channel_factory_unref(&exec_ctx, factory);
grpc_exec_ctx_finish(&exec_ctx);
}
static int factory_arg_cmp(void *factory1, void *factory2) {
if (factory1 < factory2) return -1;
if (factory1 > factory2) return 1;
return 0;
}
static const grpc_arg_pointer_vtable factory_arg_vtable = {
factory_arg_copy, factory_arg_destroy, factory_arg_cmp};
grpc_arg grpc_client_channel_factory_create_channel_arg(
grpc_client_channel_factory *factory) {
grpc_arg arg;
arg.type = GRPC_ARG_POINTER;
arg.key = GRPC_ARG_CLIENT_CHANNEL_FACTORY;
arg.value.pointer.p = factory;
arg.value.pointer.vtable = &factory_arg_vtable;
return arg;
}

@ -83,4 +83,7 @@ grpc_channel *grpc_client_channel_factory_create_channel(
const char *target, grpc_client_channel_type type,
const grpc_channel_args *args);
grpc_arg grpc_client_channel_factory_create_channel_arg(
grpc_client_channel_factory *factory);
#endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_CLIENT_CHANNEL_FACTORY_H */

@ -76,19 +76,6 @@ static const grpc_client_channel_factory_vtable client_channel_factory_vtable =
static grpc_client_channel_factory client_channel_factory = {
&client_channel_factory_vtable};
static void *cc_factory_arg_copy(void *cc_factory) { return cc_factory; }
static void cc_factory_arg_destroy(void *cc_factory) {}
static int cc_factory_arg_cmp(void *cc_factory1, void *cc_factory2) {
if (cc_factory1 < cc_factory2) return -1;
if (cc_factory1 > cc_factory2) return 1;
return 0;
}
static const grpc_arg_pointer_vtable cc_factory_arg_vtable = {
cc_factory_arg_copy, cc_factory_arg_destroy, cc_factory_arg_cmp};
/* Create a client channel:
Asynchronously: - resolve target
- connect to it (trying alternatives as presented)
@ -108,10 +95,7 @@ grpc_channel *grpc_insecure_channel_create(const char *target,
new_args[0].type = GRPC_ARG_STRING;
new_args[0].key = GRPC_ARG_SERVER_URI;
new_args[0].value.string = (char *)target;
new_args[1].type = GRPC_ARG_POINTER;
new_args[1].key = GRPC_ARG_CLIENT_CHANNEL_FACTORY;
new_args[1].value.pointer.p = factory;
new_args[1].value.pointer.vtable = &cc_factory_arg_vtable;
new_args[1] = grpc_client_channel_factory_create_channel_arg(factory);
grpc_channel_args *args_copy =
grpc_channel_args_copy_and_add(args, new_args, GPR_ARRAY_SIZE(new_args));
// Create channel.

@ -97,28 +97,6 @@ static const grpc_client_channel_factory_vtable client_channel_factory_vtable =
client_channel_factory_create_subchannel,
client_channel_factory_create_channel};
static void *cc_factory_arg_copy(void *cc_factory) {
client_channel_factory_ref(cc_factory);
return cc_factory;
}
static void cc_factory_arg_destroy(void *cc_factory) {
// TODO(roth): remove local exec_ctx when
// https://github.com/grpc/grpc/pull/8705 is merged
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
client_channel_factory_unref(&exec_ctx, cc_factory);
grpc_exec_ctx_finish(&exec_ctx);
}
static int cc_factory_arg_cmp(void *cc_factory1, void *cc_factory2) {
if (cc_factory1 < cc_factory2) return -1;
if (cc_factory1 > cc_factory2) return 1;
return 0;
}
static const grpc_arg_pointer_vtable cc_factory_arg_vtable = {
cc_factory_arg_copy, cc_factory_arg_destroy, cc_factory_arg_cmp};
/* Create a secure client channel:
Asynchronously: - resolve target
- connect to it (trying alternatives as presented)
@ -165,10 +143,7 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds,
new_args[0].type = GRPC_ARG_STRING;
new_args[0].key = GRPC_ARG_SERVER_URI;
new_args[0].value.string = (char *)target;
new_args[1].type = GRPC_ARG_POINTER;
new_args[1].key = GRPC_ARG_CLIENT_CHANNEL_FACTORY;
new_args[1].value.pointer.p = f;
new_args[1].value.pointer.vtable = &cc_factory_arg_vtable;
new_args[1] = grpc_client_channel_factory_create_channel_arg(&f->base);
new_args[2] = grpc_security_connector_to_arg(&security_connector->base);
grpc_channel_args *args_copy = grpc_channel_args_copy_and_add(
new_args_from_connector != NULL ? new_args_from_connector : args,

Loading…
Cancel
Save