From f77a8ff47174943960d6d318ea3d9a8d6407953f Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 17 Nov 2016 11:39:46 -0800 Subject: [PATCH] Code cleanup. --- .../chttp2/client/insecure/channel_create.c | 34 +++++++----------- .../client/secure/secure_channel_create.c | 36 ++++++++----------- 2 files changed, 28 insertions(+), 42 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 ec2f7717d61..33a1c49ede6 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.c +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.c @@ -45,9 +45,7 @@ #include "src/core/ext/client_channel/resolver_registry.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/channel/compress_filter.h" #include "src/core/lib/channel/handshaker.h" -#include "src/core/lib/channel/http_client_filter.h" #include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/channel.h" @@ -70,7 +68,7 @@ typedef struct { grpc_closure initial_string_sent; grpc_slice_buffer initial_string_buffer; - grpc_endpoint *tcp; // Non-NULL until handshaking starts. + grpc_endpoint *endpoint; // Non-NULL until handshaking starts. grpc_closure connected; @@ -90,7 +88,7 @@ static void connector_unref(grpc_exec_ctx *exec_ctx, grpc_connector *con) { grpc_handshake_manager_destroy(exec_ctx, c->handshake_mgr); // If handshaking is not yet in progress, destroy the endpoint. // Otherwise, the handshaker will do this for us. - if (c->tcp != NULL) grpc_endpoint_destroy(exec_ctx, c->tcp); + if (c->endpoint != NULL) grpc_endpoint_destroy(exec_ctx, c->endpoint); gpr_free(c); } } @@ -102,7 +100,7 @@ static void connector_shutdown(grpc_exec_ctx *exec_ctx, grpc_connector *con) { grpc_handshake_manager_shutdown(exec_ctx, c->handshake_mgr); // If handshaking is not yet in progress, shutdown the endpoint. // Otherwise, the handshaker will do this for us. - if (c->tcp != NULL) grpc_endpoint_shutdown(exec_ctx, c->tcp); + if (c->endpoint != NULL) grpc_endpoint_shutdown(exec_ctx, c->endpoint); gpr_mu_unlock(&c->mu); } @@ -157,9 +155,9 @@ static void on_initial_connect_string_sent(grpc_exec_ctx *exec_ctx, void *arg, connector_unref(exec_ctx, arg); } else { grpc_handshake_manager_do_handshake( - exec_ctx, c->handshake_mgr, c->tcp, c->args.channel_args, + exec_ctx, c->handshake_mgr, c->endpoint, c->args.channel_args, c->args.deadline, NULL /* acceptor */, on_handshake_done, c); - c->tcp = NULL; // Endpoint handed off to handshake manager. + c->endpoint = NULL; // Endpoint handed off to handshake manager. gpr_mu_unlock(&c->mu); } } @@ -180,20 +178,20 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { gpr_mu_unlock(&c->mu); connector_unref(exec_ctx, arg); } else { - GPR_ASSERT(c->tcp != NULL); + GPR_ASSERT(c->endpoint != NULL); if (!GRPC_SLICE_IS_EMPTY(c->args.initial_connect_string)) { grpc_closure_init(&c->initial_string_sent, on_initial_connect_string_sent, c); grpc_slice_buffer_init(&c->initial_string_buffer); grpc_slice_buffer_add(&c->initial_string_buffer, c->args.initial_connect_string); - grpc_endpoint_write(exec_ctx, c->tcp, &c->initial_string_buffer, + grpc_endpoint_write(exec_ctx, c->endpoint, &c->initial_string_buffer, &c->initial_string_sent); } else { grpc_handshake_manager_do_handshake( - exec_ctx, c->handshake_mgr, c->tcp, c->args.channel_args, + exec_ctx, c->handshake_mgr, c->endpoint, c->args.channel_args, c->args.deadline, NULL /* acceptor */, on_handshake_done, c); - c->tcp = NULL; // Endpoint handed off to handshake manager. + c->endpoint = NULL; // Endpoint handed off to handshake manager. } gpr_mu_unlock(&c->mu); } @@ -206,14 +204,13 @@ static void connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *con, connector *c = (connector *)con; gpr_mu_lock(&c->mu); GPR_ASSERT(c->notify == NULL); - GPR_ASSERT(notify->cb); c->notify = notify; c->args = *args; c->result = result; - c->tcp = NULL; + GPR_ASSERT(c->endpoint == NULL); connector_ref(con); // Ref taken for callback. grpc_closure_init(&c->connected, connected, c); - grpc_tcp_client_connect(exec_ctx, &c->connected, &c->tcp, + grpc_tcp_client_connect(exec_ctx, &c->connected, &c->endpoint, args->interested_parties, args->channel_args, args->addr, args->deadline); gpr_mu_unlock(&c->mu); @@ -260,16 +257,14 @@ static grpc_channel *client_channel_factory_create_channel( grpc_channel *channel = grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); grpc_resolver *resolver = grpc_resolver_create(target, args); - if (!resolver) { + if (resolver == NULL) { GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, "client_channel_factory_create_channel"); return NULL; } - grpc_client_channel_finish_initialization( exec_ctx, grpc_channel_get_channel_stack(channel), resolver, cc_factory); GRPC_RESOLVER_UNREF(exec_ctx, resolver, "create_channel"); - return channel; } @@ -292,16 +287,13 @@ grpc_channel *grpc_insecure_channel_create(const char *target, GRPC_API_TRACE( "grpc_insecure_channel_create(target=%p, args=%p, reserved=%p)", 3, (target, args, reserved)); - GPR_ASSERT(!reserved); - + GPR_ASSERT(reserved == NULL); grpc_client_channel_factory *factory = (grpc_client_channel_factory *)&client_channel_factory; grpc_channel *channel = client_channel_factory_create_channel( &exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, args); - grpc_client_channel_factory_unref(&exec_ctx, factory); grpc_exec_ctx_finish(&exec_ctx); - return channel != NULL ? channel : grpc_lame_client_channel_create( target, GRPC_STATUS_INTERNAL, "Failed to create client channel"); diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c index d8b5a199f77..df88eb6015c 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c @@ -47,12 +47,10 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/handshaker.h" #include "src/core/lib/iomgr/tcp_client.h" -#include "src/core/lib/security/context/security_context.h" #include "src/core/lib/security/credentials/credentials.h" -#include "src/core/lib/security/transport/auth_filters.h" +#include "src/core/lib/security/transport/security_connector.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/channel.h" -#include "src/core/lib/tsi/transport_security_interface.h" // // connector @@ -66,8 +64,6 @@ typedef struct { bool shutdown; - grpc_channel_security_connector *security_connector; - grpc_closure *notify; grpc_connect_in_args args; grpc_connect_out_args *result; @@ -76,7 +72,7 @@ typedef struct { grpc_endpoint *endpoint; // Non-NULL until handshaking starts. - grpc_closure connected_closure; + grpc_closure connected; grpc_handshake_manager *handshake_mgr; } connector; @@ -138,7 +134,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, } grpc_closure *notify = c->notify; c->notify = NULL; - grpc_exec_ctx_sched(exec_ctx, notify, GRPC_ERROR_REF(error), NULL); + grpc_exec_ctx_sched(exec_ctx, notify, error, NULL); gpr_mu_unlock(&c->mu); connector_unref(exec_ctx, (grpc_connector*)c); } @@ -215,10 +211,10 @@ static void connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *con, c->result = result; GPR_ASSERT(c->endpoint == NULL); connector_ref(con); // Ref taken for callback. - grpc_closure_init(&c->connected_closure, connected, c); - grpc_tcp_client_connect( - exec_ctx, &c->connected_closure, &c->endpoint, args->interested_parties, - args->channel_args, args->addr, args->deadline); + grpc_closure_init(&c->connected, connected, c); + grpc_tcp_client_connect(exec_ctx, &c->connected, &c->endpoint, + args->interested_parties, args->channel_args, + args->addr, args->deadline); gpr_mu_unlock(&c->mu); } @@ -258,7 +254,8 @@ static grpc_subchannel *client_channel_factory_create_subchannel( connector *c = gpr_malloc(sizeof(*c)); memset(c, 0, sizeof(*c)); c->base.vtable = &connector_vtable; - c->security_connector = f->security_connector; + gpr_mu_init(&c->mu); + gpr_ref_init(&c->refs, 1); c->handshake_mgr = grpc_handshake_manager_create(); char *proxy_name = grpc_get_http_proxy_server(); if (proxy_name != NULL) { @@ -268,9 +265,7 @@ static grpc_subchannel *client_channel_factory_create_subchannel( gpr_free(proxy_name); } grpc_channel_security_connector_create_handshakers( - exec_ctx, c->security_connector, c->handshake_mgr); - gpr_mu_init(&c->mu); - gpr_ref_init(&c->refs, 1); + exec_ctx, f->security_connector, c->handshake_mgr); grpc_subchannel *s = grpc_subchannel_create(exec_ctx, &c->base, args); grpc_connector_unref(exec_ctx, &c->base); return s; @@ -284,15 +279,14 @@ static grpc_channel *client_channel_factory_create_channel( grpc_channel *channel = grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); grpc_resolver *resolver = grpc_resolver_create(target, args); - if (resolver != NULL) { - grpc_client_channel_finish_initialization( - exec_ctx, grpc_channel_get_channel_stack(channel), resolver, &f->base); - GRPC_RESOLVER_UNREF(exec_ctx, resolver, "create"); - } else { + if (resolver == NULL) { GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, "client_channel_factory_create_channel"); - channel = NULL; + return NULL; } + grpc_client_channel_finish_initialization( + exec_ctx, grpc_channel_get_channel_stack(channel), resolver, &f->base); + GRPC_RESOLVER_UNREF(exec_ctx, resolver, "create_channel"); return channel; }