aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext/transport/chttp2/client/insecure/channel_create.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ext/transport/chttp2/client/insecure/channel_create.c')
-rw-r--r--src/core/ext/transport/chttp2/client/insecure/channel_create.c89
1 files changed, 53 insertions, 36 deletions
diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.c b/src/core/ext/transport/chttp2/client/insecure/channel_create.c
index 5ebeed4373..5484438f0a 100644
--- a/src/core/ext/transport/chttp2/client/insecure/channel_create.c
+++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.c
@@ -136,31 +136,35 @@ static const grpc_connector_vtable connector_vtable = {
connector_ref, connector_unref, connector_shutdown, connector_connect};
typedef struct {
- grpc_subchannel_factory base;
+ grpc_client_channel_factory base;
gpr_refcount refs;
grpc_channel_args *merge_args;
grpc_channel *master;
-} subchannel_factory;
+} client_channel_factory;
-static void subchannel_factory_ref(grpc_subchannel_factory *scf) {
- subchannel_factory *f = (subchannel_factory *)scf;
+static void client_channel_factory_ref(
+ grpc_client_channel_factory *cc_factory) {
+ client_channel_factory *f = (client_channel_factory *)cc_factory;
gpr_ref(&f->refs);
}
-static void subchannel_factory_unref(grpc_exec_ctx *exec_ctx,
- grpc_subchannel_factory *scf) {
- subchannel_factory *f = (subchannel_factory *)scf;
+static void client_channel_factory_unref(
+ grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory) {
+ client_channel_factory *f = (client_channel_factory *)cc_factory;
if (gpr_unref(&f->refs)) {
- GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, f->master, "subchannel_factory");
+ if (f->master != NULL) {
+ GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, f->master,
+ "client_channel_factory");
+ }
grpc_channel_args_destroy(f->merge_args);
gpr_free(f);
}
}
-static grpc_subchannel *subchannel_factory_create_subchannel(
- grpc_exec_ctx *exec_ctx, grpc_subchannel_factory *scf,
+static grpc_subchannel *client_channel_factory_create_subchannel(
+ grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
grpc_subchannel_args *args) {
- subchannel_factory *f = (subchannel_factory *)scf;
+ client_channel_factory *f = (client_channel_factory *)cc_factory;
connector *c = gpr_malloc(sizeof(*c));
grpc_channel_args *final_args =
grpc_channel_args_merge(args->args, f->merge_args);
@@ -175,9 +179,33 @@ static grpc_subchannel *subchannel_factory_create_subchannel(
return s;
}
-static const grpc_subchannel_factory_vtable subchannel_factory_vtable = {
- subchannel_factory_ref, subchannel_factory_unref,
- subchannel_factory_create_subchannel};
+static grpc_channel *client_channel_factory_create_channel(
+ grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
+ const char *target, grpc_client_channel_type type,
+ grpc_channel_args *args) {
+ client_channel_factory *f = (client_channel_factory *)cc_factory;
+ grpc_channel_args *final_args = grpc_channel_args_merge(args, f->merge_args);
+ grpc_channel *channel = grpc_channel_create(exec_ctx, target, final_args,
+ GRPC_CLIENT_CHANNEL, NULL);
+ grpc_channel_args_destroy(final_args);
+ grpc_resolver *resolver = grpc_resolver_create(target, &f->base);
+ if (!resolver) {
+ GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel,
+ "client_channel_factory_create_channel");
+ return NULL;
+ }
+
+ grpc_client_channel_set_resolver(
+ exec_ctx, grpc_channel_get_channel_stack(channel), resolver);
+ GRPC_RESOLVER_UNREF(exec_ctx, resolver, "create_channel");
+
+ return channel;
+}
+
+static const grpc_client_channel_factory_vtable client_channel_factory_vtable =
+ {client_channel_factory_ref, client_channel_factory_unref,
+ client_channel_factory_create_subchannel,
+ client_channel_factory_create_channel};
/* Create a client channel:
Asynchronously: - resolve target
@@ -186,38 +214,27 @@ static const grpc_subchannel_factory_vtable subchannel_factory_vtable = {
grpc_channel *grpc_insecure_channel_create(const char *target,
const grpc_channel_args *args,
void *reserved) {
- grpc_channel *channel = NULL;
- grpc_resolver *resolver;
- subchannel_factory *f;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
GRPC_API_TRACE(
"grpc_insecure_channel_create(target=%p, args=%p, reserved=%p)", 3,
(target, args, reserved));
GPR_ASSERT(!reserved);
- channel =
- grpc_channel_create(&exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL);
-
- f = gpr_malloc(sizeof(*f));
- f->base.vtable = &subchannel_factory_vtable;
+ client_channel_factory *f = gpr_malloc(sizeof(*f));
+ memset(f, 0, sizeof(*f));
+ f->base.vtable = &client_channel_factory_vtable;
gpr_ref_init(&f->refs, 1);
f->merge_args = grpc_channel_args_copy(args);
- f->master = channel;
- GRPC_CHANNEL_INTERNAL_REF(f->master, "subchannel_factory");
- resolver = grpc_resolver_create(target, &f->base);
- if (!resolver) {
- GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, f->master, "subchannel_factory");
- grpc_subchannel_factory_unref(&exec_ctx, &f->base);
- grpc_exec_ctx_finish(&exec_ctx);
- return NULL;
- }
- grpc_client_channel_set_resolver(
- &exec_ctx, grpc_channel_get_channel_stack(channel), resolver);
- GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "create");
- grpc_subchannel_factory_unref(&exec_ctx, &f->base);
+ grpc_channel *channel = client_channel_factory_create_channel(
+ &exec_ctx, &f->base, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, NULL);
+ if (channel != NULL) {
+ f->master = channel;
+ GRPC_CHANNEL_INTERNAL_REF(f->master, "grpc_insecure_channel_create");
+ }
+ grpc_client_channel_factory_unref(&exec_ctx, &f->base);
grpc_exec_ctx_finish(&exec_ctx);
- return channel;
+ return channel; /* may be NULL */
}