client_config: chttp2_fullstack_no_op_unsecure_test passes

pull/2303/head
Craig Tiller 10 years ago
parent 916246625b
commit f7afa1f1ba
  1. 16
      src/core/client_config/connector.c
  2. 11
      src/core/client_config/connector.h
  3. 15
      src/core/client_config/resolver_factory.c
  4. 28
      src/core/client_config/subchannel.c
  5. 17
      src/core/client_config/subchannel.h
  6. 14
      src/core/client_config/subchannel_factory.h
  7. 53
      src/core/surface/channel_create.c

@ -33,3 +33,19 @@
#include "src/core/client_config/connector.h" #include "src/core/client_config/connector.h"
void grpc_connector_ref(grpc_connector *connector) {
connector->vtable->ref(connector);
}
void grpc_connector_unref(grpc_connector *connector) {
connector->vtable->unref(connector);
}
void grpc_connector_connect(grpc_connector *connector,
const grpc_channel_args *channel_args,
grpc_mdctx *metadata_context,
grpc_transport **transport,
grpc_iomgr_closure *notify) {
connector->vtable->connect(connector, channel_args, metadata_context,
transport, notify);
}

@ -46,11 +46,18 @@ struct grpc_connector {
struct grpc_connector_vtable { struct grpc_connector_vtable {
void (*ref)(grpc_connector *connector); void (*ref)(grpc_connector *connector);
void (*unref)(grpc_connector *connector); void (*unref)(grpc_connector *connector);
void (*connect)(grpc_connector *connector, const grpc_channel_args *channel_args, grpc_mdctx *metadata_context, grpc_transport **transport, grpc_iomgr_closure *notify); void (*connect)(grpc_connector *connector,
const grpc_channel_args *channel_args,
grpc_mdctx *metadata_context, grpc_transport **transport,
grpc_iomgr_closure *notify);
}; };
void grpc_connector_ref(grpc_connector *connector); void grpc_connector_ref(grpc_connector *connector);
void grpc_connector_unref(grpc_connector *connector); void grpc_connector_unref(grpc_connector *connector);
void grpc_connector_connect(grpc_connector *connector, const grpc_channel_args *channel_args, grpc_mdctx *metadata_context, grpc_transport **transport, grpc_iomgr_closure *notify); void grpc_connector_connect(grpc_connector *connector,
const grpc_channel_args *channel_args,
grpc_mdctx *metadata_context,
grpc_transport **transport,
grpc_iomgr_closure *notify);
#endif #endif

@ -32,3 +32,18 @@
*/ */
#include "src/core/client_config/resolver_factory.h" #include "src/core/client_config/resolver_factory.h"
void grpc_resolver_factory_ref(grpc_resolver_factory *factory) {
factory->vtable->ref(factory);
}
void grpc_resolver_factory_unref(grpc_resolver_factory *factory) {
factory->vtable->unref(factory);
}
/** Create a resolver instance for a name */
grpc_resolver *grpc_resolver_factory_create_resolver(
grpc_resolver_factory *factory, grpc_uri *uri,
grpc_subchannel_factory *subchannel_factory) {
return factory->vtable->create_resolver(factory, uri, subchannel_factory);
}

@ -33,11 +33,22 @@
#include "src/core/client_config/subchannel.h" #include "src/core/client_config/subchannel.h"
#include <string.h>
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
struct grpc_subchannel { struct grpc_subchannel {
gpr_refcount refs; gpr_refcount refs;
grpc_connector *connector; grpc_connector *connector;
/** non-transport related channel filters */
const grpc_channel_filter **filters;
size_t filter_count;
/** channel arguments */
grpc_channel_args *args;
/** address to connect to */
struct sockaddr *addr;
size_t addr_len;
}; };
struct grpc_subchannel_call { struct grpc_subchannel_call {
@ -59,6 +70,23 @@ void grpc_subchannel_unref(grpc_subchannel *channel) {
} }
} }
grpc_subchannel *grpc_subchannel_create(grpc_connector *connector,
grpc_subchannel_args *args) {
grpc_subchannel *c = gpr_malloc(sizeof(*c));
memset(c, 0, sizeof(*c));
gpr_ref_init(&c->refs, 1);
c->connector = connector;
grpc_connector_ref(c->connector);
c->filters = gpr_malloc(sizeof(grpc_channel_filter *) * args->filter_count);
memcpy(c->filters, args->filters,
sizeof(grpc_channel_filter *) * args->filter_count);
c->filter_count = args->filter_count;
c->addr = gpr_malloc(args->addr_len);
memcpy(c->addr, args->addr, args->addr_len);
c->addr_len = args->addr_len;
return c;
}
/* /*
* grpc_subchannel_call implementation * grpc_subchannel_call implementation
*/ */

@ -41,6 +41,7 @@
address. Provides a target for load balancing. */ address. Provides a target for load balancing. */
typedef struct grpc_subchannel grpc_subchannel; typedef struct grpc_subchannel grpc_subchannel;
typedef struct grpc_subchannel_call grpc_subchannel_call; typedef struct grpc_subchannel_call grpc_subchannel_call;
typedef struct grpc_subchannel_args grpc_subchannel_args;
void grpc_subchannel_ref(grpc_subchannel *channel); void grpc_subchannel_ref(grpc_subchannel *channel);
void grpc_subchannel_unref(grpc_subchannel *channel); void grpc_subchannel_unref(grpc_subchannel *channel);
@ -69,7 +70,21 @@ void grpc_subchannel_create_call(grpc_subchannel *subchannel,
void grpc_subchannel_call_process_op(grpc_subchannel_call *subchannel_call, void grpc_subchannel_call_process_op(grpc_subchannel_call *subchannel_call,
grpc_transport_stream_op *op); grpc_transport_stream_op *op);
struct grpc_subchannel_args {
/** Channel filters for this channel - wrapped factories will likely
want to mutate this */
const grpc_channel_filter **filters;
/** The number of filters in the above array */
size_t filter_count;
/** Channel arguments to be supplied to the newly created channel */
const grpc_channel_args *args;
/** Address to connect to */
struct sockaddr *addr;
size_t addr_len;
};
/** create a subchannel given a connector */ /** create a subchannel given a connector */
grpc_subchannel *grpc_subchannel_create(grpc_connector *connector); grpc_subchannel *grpc_subchannel_create(grpc_connector *connector,
grpc_subchannel_args *args);
#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_H */ #endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_H */

@ -39,7 +39,6 @@
typedef struct grpc_subchannel_factory grpc_subchannel_factory; typedef struct grpc_subchannel_factory grpc_subchannel_factory;
typedef struct grpc_subchannel_factory_vtable grpc_subchannel_factory_vtable; typedef struct grpc_subchannel_factory_vtable grpc_subchannel_factory_vtable;
typedef struct grpc_subchannel_args grpc_subchannel_args;
/** Constructor for new configured channels. /** Constructor for new configured channels.
Creating decorators around this type is encouraged to adapt behavior. */ Creating decorators around this type is encouraged to adapt behavior. */
@ -47,19 +46,6 @@ struct grpc_subchannel_factory {
const grpc_subchannel_factory_vtable *vtable; const grpc_subchannel_factory_vtable *vtable;
}; };
struct grpc_subchannel_args {
/** Channel filters for this channel - wrapped factories will likely
want to mutate this */
const grpc_channel_filter **filters;
/** The number of filters in the above array */
size_t filter_count;
/** Channel arguments to be supplied to the newly created channel */
const grpc_channel_args *args;
/** Address to connect to */
struct sockaddr *addr;
size_t addr_len;
};
struct grpc_subchannel_factory_vtable { struct grpc_subchannel_factory_vtable {
void (*ref)(grpc_subchannel_factory *factory); void (*ref)(grpc_subchannel_factory *factory);
void (*unref)(grpc_subchannel_factory *factory); void (*unref)(grpc_subchannel_factory *factory);

@ -46,44 +46,42 @@
typedef struct { typedef struct {
grpc_connector base; grpc_connector base;
gpr_refcount refs; gpr_refcount refs;
struct sockaddr *addr;
int addr_len;
grpc_channel_args *args;
} connector; } connector;
typedef struct { static void connector_ref(grpc_connector *con) {
grpc_subchannel_factory base; connector *c = (connector *)con;
gpr_refcount refs; gpr_ref(&c->refs);
grpc_channel_args *args;
} subchannel_factory;
static void subchannel_factory_ref(grpc_subchannel_factory *scf) {
subchannel_factory *f = (subchannel_factory*)scf;
gpr_ref(&f->refs);
} }
static void subchannel_factory_unref(grpc_subchannel_factory *scf) { static void connector_unref(grpc_connector *con) {
subchannel_factory *f = (subchannel_factory*)scf; connector *c = (connector *)con;
if (gpr_unref(&f->refs)) { if (gpr_unref(&c->refs)) {
grpc_channel_args_destroy(f->args); gpr_free(c);
gpr_free(f);
} }
} }
static void connector_connect(grpc_connector *connector, const grpc_channel_args *channel_args, grpc_mdctx *metadata_context, grpc_transport **transport, grpc_iomgr_closure *notify) {
abort();
}
static const grpc_connector_vtable connector_vtable = {connector_ref, connector_unref, connector_connect};
static void subchannel_factory_ref(grpc_subchannel_factory *scf) {}
static void subchannel_factory_unref(grpc_subchannel_factory *scf) {}
static grpc_subchannel *subchannel_factory_create_subchannel(grpc_subchannel_factory *scf, grpc_subchannel_args *args) { static grpc_subchannel *subchannel_factory_create_subchannel(grpc_subchannel_factory *scf, grpc_subchannel_args *args) {
subchannel_factory *f = (subchannel_factory*)scf;
connector *c = gpr_malloc(sizeof(*c)); connector *c = gpr_malloc(sizeof(*c));
grpc_subchannel *s;
c->base.vtable = &connector_vtable; c->base.vtable = &connector_vtable;
gpr_ref_init(&c->refs, 1); gpr_ref_init(&c->refs, 1);
c->addr = gpr_malloc(args->addr_len); s = grpc_subchannel_create(&c->base, args);
memcpy(c->addr, args->addr, args->addr_len); grpc_connector_unref(&c->base);
c->addr_len = args->addr_len; return s;
c->args = grpc_channel_args_merge(args->args, f->args);
return grpc_subchannel_create(&c->base);
} }
static const grpc_subchannel_factory_vtable subchannel_factory_vtable = {subchannel_factory_ref, subchannel_factory_unref, subchannel_factory_create_subchannel}; static const grpc_subchannel_factory_vtable subchannel_factory_vtable = {subchannel_factory_ref, subchannel_factory_unref, subchannel_factory_create_subchannel};
static grpc_subchannel_factory subchannel_factory = {&subchannel_factory_vtable};
/* Create a client channel: /* Create a client channel:
Asynchronously: - resolve target Asynchronously: - resolve target
@ -92,7 +90,6 @@ static const grpc_subchannel_factory_vtable subchannel_factory_vtable = {subchan
grpc_channel *grpc_channel_create(const char *target, grpc_channel *grpc_channel_create(const char *target,
const grpc_channel_args *args) { const grpc_channel_args *args) {
grpc_channel *channel = NULL; grpc_channel *channel = NULL;
subchannel_factory *scfactory = gpr_malloc(sizeof(*scfactory));
#define MAX_FILTERS 3 #define MAX_FILTERS 3
const grpc_channel_filter *filters[MAX_FILTERS]; const grpc_channel_filter *filters[MAX_FILTERS];
grpc_resolver *resolver; grpc_resolver *resolver;
@ -104,11 +101,7 @@ grpc_channel *grpc_channel_create(const char *target,
filters[n++] = &grpc_client_channel_filter; filters[n++] = &grpc_client_channel_filter;
GPR_ASSERT(n <= MAX_FILTERS); GPR_ASSERT(n <= MAX_FILTERS);
scfactory->base.vtable = &subchannel_factory_vtable; resolver = grpc_resolver_create(target, &subchannel_factory);
gpr_ref_init(&scfactory->refs, 1);
scfactory->args = grpc_channel_args_copy(args);
resolver = grpc_resolver_create(target, &scfactory->base);
if (!resolver) { if (!resolver) {
return NULL; return NULL;
} }

Loading…
Cancel
Save