Skip to content
Snippets Groups Projects
Commit f77a8ff4 authored by Mark D. Roth's avatar Mark D. Roth
Browse files

Code cleanup.

parent 3d7e4929
No related branches found
No related tags found
No related merge requests found
...@@ -45,9 +45,7 @@ ...@@ -45,9 +45,7 @@
#include "src/core/ext/client_channel/resolver_registry.h" #include "src/core/ext/client_channel/resolver_registry.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/channel_args.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/handshaker.h"
#include "src/core/lib/channel/http_client_filter.h"
#include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/tcp_client.h"
#include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/channel.h"
...@@ -70,7 +68,7 @@ typedef struct { ...@@ -70,7 +68,7 @@ typedef struct {
grpc_closure initial_string_sent; grpc_closure initial_string_sent;
grpc_slice_buffer initial_string_buffer; 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; grpc_closure connected;
...@@ -90,7 +88,7 @@ static void connector_unref(grpc_exec_ctx *exec_ctx, grpc_connector *con) { ...@@ -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); grpc_handshake_manager_destroy(exec_ctx, c->handshake_mgr);
// If handshaking is not yet in progress, destroy the endpoint. // If handshaking is not yet in progress, destroy the endpoint.
// Otherwise, the handshaker will do this for us. // 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); gpr_free(c);
} }
} }
...@@ -102,7 +100,7 @@ static void connector_shutdown(grpc_exec_ctx *exec_ctx, grpc_connector *con) { ...@@ -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); grpc_handshake_manager_shutdown(exec_ctx, c->handshake_mgr);
// If handshaking is not yet in progress, shutdown the endpoint. // If handshaking is not yet in progress, shutdown the endpoint.
// Otherwise, the handshaker will do this for us. // 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); gpr_mu_unlock(&c->mu);
} }
...@@ -157,9 +155,9 @@ static void on_initial_connect_string_sent(grpc_exec_ctx *exec_ctx, void *arg, ...@@ -157,9 +155,9 @@ static void on_initial_connect_string_sent(grpc_exec_ctx *exec_ctx, void *arg,
connector_unref(exec_ctx, arg); connector_unref(exec_ctx, arg);
} else { } else {
grpc_handshake_manager_do_handshake( 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->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); gpr_mu_unlock(&c->mu);
} }
} }
...@@ -180,20 +178,20 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { ...@@ -180,20 +178,20 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
gpr_mu_unlock(&c->mu); gpr_mu_unlock(&c->mu);
connector_unref(exec_ctx, arg); connector_unref(exec_ctx, arg);
} else { } else {
GPR_ASSERT(c->tcp != NULL); GPR_ASSERT(c->endpoint != NULL);
if (!GRPC_SLICE_IS_EMPTY(c->args.initial_connect_string)) { if (!GRPC_SLICE_IS_EMPTY(c->args.initial_connect_string)) {
grpc_closure_init(&c->initial_string_sent, on_initial_connect_string_sent, grpc_closure_init(&c->initial_string_sent, on_initial_connect_string_sent,
c); c);
grpc_slice_buffer_init(&c->initial_string_buffer); grpc_slice_buffer_init(&c->initial_string_buffer);
grpc_slice_buffer_add(&c->initial_string_buffer, grpc_slice_buffer_add(&c->initial_string_buffer,
c->args.initial_connect_string); 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); &c->initial_string_sent);
} else { } else {
grpc_handshake_manager_do_handshake( 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->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); gpr_mu_unlock(&c->mu);
} }
...@@ -206,14 +204,13 @@ static void connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *con, ...@@ -206,14 +204,13 @@ static void connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *con,
connector *c = (connector *)con; connector *c = (connector *)con;
gpr_mu_lock(&c->mu); gpr_mu_lock(&c->mu);
GPR_ASSERT(c->notify == NULL); GPR_ASSERT(c->notify == NULL);
GPR_ASSERT(notify->cb);
c->notify = notify; c->notify = notify;
c->args = *args; c->args = *args;
c->result = result; c->result = result;
c->tcp = NULL; GPR_ASSERT(c->endpoint == NULL);
connector_ref(con); // Ref taken for callback. connector_ref(con); // Ref taken for callback.
grpc_closure_init(&c->connected, connected, c); 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->interested_parties, args->channel_args,
args->addr, args->deadline); args->addr, args->deadline);
gpr_mu_unlock(&c->mu); gpr_mu_unlock(&c->mu);
...@@ -260,16 +257,14 @@ static grpc_channel *client_channel_factory_create_channel( ...@@ -260,16 +257,14 @@ static grpc_channel *client_channel_factory_create_channel(
grpc_channel *channel = grpc_channel *channel =
grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL);
grpc_resolver *resolver = grpc_resolver_create(target, args); grpc_resolver *resolver = grpc_resolver_create(target, args);
if (!resolver) { if (resolver == NULL) {
GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel,
"client_channel_factory_create_channel"); "client_channel_factory_create_channel");
return NULL; return NULL;
} }
grpc_client_channel_finish_initialization( grpc_client_channel_finish_initialization(
exec_ctx, grpc_channel_get_channel_stack(channel), resolver, cc_factory); exec_ctx, grpc_channel_get_channel_stack(channel), resolver, cc_factory);
GRPC_RESOLVER_UNREF(exec_ctx, resolver, "create_channel"); GRPC_RESOLVER_UNREF(exec_ctx, resolver, "create_channel");
return channel; return channel;
} }
...@@ -292,16 +287,13 @@ grpc_channel *grpc_insecure_channel_create(const char *target, ...@@ -292,16 +287,13 @@ grpc_channel *grpc_insecure_channel_create(const char *target,
GRPC_API_TRACE( GRPC_API_TRACE(
"grpc_insecure_channel_create(target=%p, args=%p, reserved=%p)", 3, "grpc_insecure_channel_create(target=%p, args=%p, reserved=%p)", 3,
(target, args, reserved)); (target, args, reserved));
GPR_ASSERT(!reserved); GPR_ASSERT(reserved == NULL);
grpc_client_channel_factory *factory = grpc_client_channel_factory *factory =
(grpc_client_channel_factory *)&client_channel_factory; (grpc_client_channel_factory *)&client_channel_factory;
grpc_channel *channel = client_channel_factory_create_channel( grpc_channel *channel = client_channel_factory_create_channel(
&exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, args); &exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, args);
grpc_client_channel_factory_unref(&exec_ctx, factory); grpc_client_channel_factory_unref(&exec_ctx, factory);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
return channel != NULL ? channel : grpc_lame_client_channel_create( return channel != NULL ? channel : grpc_lame_client_channel_create(
target, GRPC_STATUS_INTERNAL, target, GRPC_STATUS_INTERNAL,
"Failed to create client channel"); "Failed to create client channel");
......
...@@ -47,12 +47,10 @@ ...@@ -47,12 +47,10 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/handshaker.h" #include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/iomgr/tcp_client.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/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/api_trace.h"
#include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/channel.h"
#include "src/core/lib/tsi/transport_security_interface.h"
// //
// connector // connector
...@@ -66,8 +64,6 @@ typedef struct { ...@@ -66,8 +64,6 @@ typedef struct {
bool shutdown; bool shutdown;
grpc_channel_security_connector *security_connector;
grpc_closure *notify; grpc_closure *notify;
grpc_connect_in_args args; grpc_connect_in_args args;
grpc_connect_out_args *result; grpc_connect_out_args *result;
...@@ -76,7 +72,7 @@ typedef struct { ...@@ -76,7 +72,7 @@ typedef struct {
grpc_endpoint *endpoint; // Non-NULL until handshaking starts. grpc_endpoint *endpoint; // Non-NULL until handshaking starts.
grpc_closure connected_closure; grpc_closure connected;
grpc_handshake_manager *handshake_mgr; grpc_handshake_manager *handshake_mgr;
} connector; } connector;
...@@ -138,7 +134,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, ...@@ -138,7 +134,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
} }
grpc_closure *notify = c->notify; grpc_closure *notify = c->notify;
c->notify = NULL; 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); gpr_mu_unlock(&c->mu);
connector_unref(exec_ctx, (grpc_connector*)c); connector_unref(exec_ctx, (grpc_connector*)c);
} }
...@@ -215,10 +211,10 @@ static void connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *con, ...@@ -215,10 +211,10 @@ static void connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *con,
c->result = result; c->result = result;
GPR_ASSERT(c->endpoint == NULL); GPR_ASSERT(c->endpoint == NULL);
connector_ref(con); // Ref taken for callback. connector_ref(con); // Ref taken for callback.
grpc_closure_init(&c->connected_closure, connected, c); grpc_closure_init(&c->connected, connected, c);
grpc_tcp_client_connect( grpc_tcp_client_connect(exec_ctx, &c->connected, &c->endpoint,
exec_ctx, &c->connected_closure, &c->endpoint, args->interested_parties, args->interested_parties, args->channel_args,
args->channel_args, args->addr, args->deadline); args->addr, args->deadline);
gpr_mu_unlock(&c->mu); gpr_mu_unlock(&c->mu);
} }
...@@ -258,7 +254,8 @@ static grpc_subchannel *client_channel_factory_create_subchannel( ...@@ -258,7 +254,8 @@ static grpc_subchannel *client_channel_factory_create_subchannel(
connector *c = gpr_malloc(sizeof(*c)); connector *c = gpr_malloc(sizeof(*c));
memset(c, 0, sizeof(*c)); memset(c, 0, sizeof(*c));
c->base.vtable = &connector_vtable; 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(); c->handshake_mgr = grpc_handshake_manager_create();
char *proxy_name = grpc_get_http_proxy_server(); char *proxy_name = grpc_get_http_proxy_server();
if (proxy_name != NULL) { if (proxy_name != NULL) {
...@@ -268,9 +265,7 @@ static grpc_subchannel *client_channel_factory_create_subchannel( ...@@ -268,9 +265,7 @@ static grpc_subchannel *client_channel_factory_create_subchannel(
gpr_free(proxy_name); gpr_free(proxy_name);
} }
grpc_channel_security_connector_create_handshakers( grpc_channel_security_connector_create_handshakers(
exec_ctx, c->security_connector, c->handshake_mgr); exec_ctx, f->security_connector, c->handshake_mgr);
gpr_mu_init(&c->mu);
gpr_ref_init(&c->refs, 1);
grpc_subchannel *s = grpc_subchannel_create(exec_ctx, &c->base, args); grpc_subchannel *s = grpc_subchannel_create(exec_ctx, &c->base, args);
grpc_connector_unref(exec_ctx, &c->base); grpc_connector_unref(exec_ctx, &c->base);
return s; return s;
...@@ -284,15 +279,14 @@ static grpc_channel *client_channel_factory_create_channel( ...@@ -284,15 +279,14 @@ static grpc_channel *client_channel_factory_create_channel(
grpc_channel *channel = grpc_channel *channel =
grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL); grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL);
grpc_resolver *resolver = grpc_resolver_create(target, args); grpc_resolver *resolver = grpc_resolver_create(target, args);
if (resolver != NULL) { 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 {
GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel,
"client_channel_factory_create_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; return channel;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment