diff options
Diffstat (limited to 'src/core/ext/client_channel')
-rw-r--r-- | src/core/ext/client_channel/connector.h | 4 | ||||
-rw-r--r-- | src/core/ext/client_channel/default_initial_connect_string.c | 5 | ||||
-rw-r--r-- | src/core/ext/client_channel/initial_connect_string.c | 9 | ||||
-rw-r--r-- | src/core/ext/client_channel/initial_connect_string.h | 10 | ||||
-rw-r--r-- | src/core/ext/client_channel/parse_address.c | 33 | ||||
-rw-r--r-- | src/core/ext/client_channel/parse_address.h | 10 | ||||
-rw-r--r-- | src/core/ext/client_channel/subchannel.c | 13 | ||||
-rw-r--r-- | src/core/ext/client_channel/subchannel.h | 3 | ||||
-rw-r--r-- | src/core/ext/client_channel/subchannel_index.c | 14 |
9 files changed, 50 insertions, 51 deletions
diff --git a/src/core/ext/client_channel/connector.h b/src/core/ext/client_channel/connector.h index e08244b2c0..ed7d5450de 100644 --- a/src/core/ext/client_channel/connector.h +++ b/src/core/ext/client_channel/connector.h @@ -35,7 +35,7 @@ #define GRPC_CORE_EXT_CLIENT_CHANNEL_CONNECTOR_H #include "src/core/lib/channel/channel_stack.h" -#include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/transport/transport.h" typedef struct grpc_connector grpc_connector; @@ -49,7 +49,7 @@ typedef struct { /** set of pollsets interested in this connection */ grpc_pollset_set *interested_parties; /** address to connect to */ - const struct sockaddr *addr; + const grpc_resolved_address *addr; size_t addr_len; /** initial connect string to send */ gpr_slice initial_connect_string; diff --git a/src/core/ext/client_channel/default_initial_connect_string.c b/src/core/ext/client_channel/default_initial_connect_string.c index a70da4a84a..0b251372fd 100644 --- a/src/core/ext/client_channel/default_initial_connect_string.c +++ b/src/core/ext/client_channel/default_initial_connect_string.c @@ -32,8 +32,7 @@ */ #include <grpc/support/slice.h> -#include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/resolve_address.h" -void grpc_set_default_initial_connect_string(struct sockaddr **addr, - size_t *addr_len, +void grpc_set_default_initial_connect_string(grpc_resolved_address **addr, gpr_slice *initial_str) {} diff --git a/src/core/ext/client_channel/initial_connect_string.c b/src/core/ext/client_channel/initial_connect_string.c index fd8ddb83a8..fb1493d77d 100644 --- a/src/core/ext/client_channel/initial_connect_string.c +++ b/src/core/ext/client_channel/initial_connect_string.c @@ -35,9 +35,8 @@ #include <stddef.h> -extern void grpc_set_default_initial_connect_string(struct sockaddr **addr, - size_t *addr_len, - gpr_slice *initial_str); +extern void grpc_set_default_initial_connect_string( + grpc_resolved_address **addr, gpr_slice *initial_str); static grpc_set_initial_connect_string_func g_set_initial_connect_string_func = grpc_set_default_initial_connect_string; @@ -47,7 +46,7 @@ void grpc_test_set_initial_connect_string_function( g_set_initial_connect_string_func = func; } -void grpc_set_initial_connect_string(struct sockaddr **addr, size_t *addr_len, +void grpc_set_initial_connect_string(grpc_resolved_address **addr, gpr_slice *initial_str) { - g_set_initial_connect_string_func(addr, addr_len, initial_str); + g_set_initial_connect_string_func(addr, initial_str); } diff --git a/src/core/ext/client_channel/initial_connect_string.h b/src/core/ext/client_channel/initial_connect_string.h index 39f6465fc9..68adb0373c 100644 --- a/src/core/ext/client_channel/initial_connect_string.h +++ b/src/core/ext/client_channel/initial_connect_string.h @@ -35,16 +35,16 @@ #define GRPC_CORE_EXT_CLIENT_CHANNEL_INITIAL_CONNECT_STRING_H #include <grpc/support/slice.h> -#include "src/core/lib/iomgr/sockaddr.h" -typedef void (*grpc_set_initial_connect_string_func)(struct sockaddr **addr, - size_t *addr_len, - gpr_slice *initial_str); +#include "src/core/lib/iomgr/resolve_address.h" + +typedef void (*grpc_set_initial_connect_string_func)( + grpc_resolved_address **addr, gpr_slice *initial_str); void grpc_test_set_initial_connect_string_function( grpc_set_initial_connect_string_func func); /** Set a string to be sent once connected. Optionally reset addr. */ -void grpc_set_initial_connect_string(struct sockaddr **addr, size_t *addr_len, +void grpc_set_initial_connect_string(grpc_resolved_address **addr, gpr_slice *connect_string); #endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_INITIAL_CONNECT_STRING_H */ diff --git a/src/core/ext/client_channel/parse_address.c b/src/core/ext/client_channel/parse_address.c index 31ca44299b..b1d55ad0f5 100644 --- a/src/core/ext/client_channel/parse_address.c +++ b/src/core/ext/client_channel/parse_address.c @@ -32,10 +32,11 @@ */ #include "src/core/ext/client_channel/parse_address.h" +#include "src/core/lib/iomgr/sockaddr.h" #include <stdio.h> #include <string.h> -#ifdef GPR_HAVE_UNIX_SOCKET +#ifdef GRPC_HAVE_UNIX_SOCKET #include <sys/un.h> #endif @@ -44,33 +45,39 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> -#ifdef GPR_HAVE_UNIX_SOCKET -int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) { - struct sockaddr_un *un = (struct sockaddr_un *)addr; +#ifdef GRPC_HAVE_UNIX_SOCKET + +int parse_unix(grpc_uri *uri, grpc_resolved_address *resolved_addr) { + struct sockaddr_un *un = (struct sockaddr_un *)resolved_addr->addr; un->sun_family = AF_UNIX; strcpy(un->sun_path, uri->path); - *len = strlen(un->sun_path) + sizeof(un->sun_family) + 1; + resolved_addr->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1; return 1; } -#endif -int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) { +#else /* GRPC_HAVE_UNIX_SOCKET */ + +int parse_unix(grpc_uri *uri, grpc_resolved_address *resolved_addr) { abort(); } + +#endif /* GRPC_HAVE_UNIX_SOCKET */ + +int parse_ipv4(grpc_uri *uri, grpc_resolved_address *resolved_addr) { const char *host_port = uri->path; char *host; char *port; int port_num; int result = 0; - struct sockaddr_in *in = (struct sockaddr_in *)addr; + struct sockaddr_in *in = (struct sockaddr_in *)resolved_addr->addr; if (*host_port == '/') ++host_port; if (!gpr_split_host_port(host_port, &host, &port)) { return 0; } - memset(in, 0, sizeof(*in)); - *len = sizeof(*in); + memset(resolved_addr, 0, sizeof(grpc_resolved_address)); + resolved_addr->len = sizeof(struct sockaddr_in); in->sin_family = AF_INET; if (inet_pton(AF_INET, host, &in->sin_addr) == 0) { gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host); @@ -96,13 +103,13 @@ done: return result; } -int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) { +int parse_ipv6(grpc_uri *uri, grpc_resolved_address *resolved_addr) { const char *host_port = uri->path; char *host; char *port; int port_num; int result = 0; - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr; + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)resolved_addr->addr; if (*host_port == '/') ++host_port; if (!gpr_split_host_port(host_port, &host, &port)) { @@ -110,7 +117,7 @@ int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) { } memset(in6, 0, sizeof(*in6)); - *len = sizeof(*in6); + resolved_addr->len = sizeof(*in6); in6->sin6_family = AF_INET6; if (inet_pton(AF_INET6, host, &in6->sin6_addr) == 0) { gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host); diff --git a/src/core/ext/client_channel/parse_address.h b/src/core/ext/client_channel/parse_address.h index 3aa6c41546..bf99c5298a 100644 --- a/src/core/ext/client_channel/parse_address.h +++ b/src/core/ext/client_channel/parse_address.h @@ -37,20 +37,18 @@ #include <stddef.h> #include "src/core/ext/client_channel/uri_parser.h" -#include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/resolve_address.h" -#ifdef GPR_HAVE_UNIX_SOCKET /** Populate \a addr and \a len from \a uri, whose path is expected to contain a * unix socket path. Returns true upon success. */ -int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len); -#endif +int parse_unix(grpc_uri *uri, grpc_resolved_address *resolved_addr); /** Populate /a addr and \a len from \a uri, whose path is expected to contain a * host:port pair. Returns true upon success. */ -int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len); +int parse_ipv4(grpc_uri *uri, grpc_resolved_address *resolved_addr); /** Populate /a addr and \a len from \a uri, whose path is expected to contain a * host:port pair. Returns true upon success. */ -int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len); +int parse_ipv6(grpc_uri *uri, grpc_resolved_address *resolved_addr); #endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_PARSE_ADDRESS_H */ diff --git a/src/core/ext/client_channel/subchannel.c b/src/core/ext/client_channel/subchannel.c index 672e5c3a91..157f78877f 100644 --- a/src/core/ext/client_channel/subchannel.c +++ b/src/core/ext/client_channel/subchannel.c @@ -95,8 +95,7 @@ struct grpc_subchannel { /** channel arguments */ grpc_channel_args *args; /** address to connect to */ - struct sockaddr *addr; - size_t addr_len; + grpc_resolved_address *addr; grpc_subchannel_key *key; @@ -320,12 +319,11 @@ grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, } else { c->filters = NULL; } - c->addr = gpr_malloc(args->addr_len); - if (args->addr_len) memcpy(c->addr, args->addr, args->addr_len); + c->addr = gpr_malloc(sizeof(grpc_resolved_address)); + if (args->addr->len) + memcpy(c->addr, args->addr, sizeof(grpc_resolved_address)); c->pollset_set = grpc_pollset_set_create(); - c->addr_len = args->addr_len; - grpc_set_initial_connect_string(&c->addr, &c->addr_len, - &c->initial_connect_string); + grpc_set_initial_connect_string(&c->addr, &c->initial_connect_string); c->args = grpc_channel_args_copy(args->args); c->root_external_state_watcher.next = c->root_external_state_watcher.prev = &c->root_external_state_watcher; @@ -376,7 +374,6 @@ static void continue_connect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) { args.interested_parties = c->pollset_set; args.addr = c->addr; - args.addr_len = c->addr_len; args.deadline = c->next_attempt; args.channel_args = c->args; args.initial_connect_string = c->initial_connect_string; diff --git a/src/core/ext/client_channel/subchannel.h b/src/core/ext/client_channel/subchannel.h index c4a7da0c24..0350d5574c 100644 --- a/src/core/ext/client_channel/subchannel.h +++ b/src/core/ext/client_channel/subchannel.h @@ -167,8 +167,7 @@ struct grpc_subchannel_args { /** Server name */ const char *server_name; /** Address to connect to */ - struct sockaddr *addr; - size_t addr_len; + grpc_resolved_address *addr; }; /** create a subchannel given a connector */ diff --git a/src/core/ext/client_channel/subchannel_index.c b/src/core/ext/client_channel/subchannel_index.c index bf22975fba..7933760e0e 100644 --- a/src/core/ext/client_channel/subchannel_index.c +++ b/src/core/ext/client_channel/subchannel_index.c @@ -87,10 +87,10 @@ static grpc_subchannel_key *create_key( k->args.filters = NULL; } k->args.server_name = gpr_strdup(args->server_name); - k->args.addr_len = args->addr_len; - k->args.addr = gpr_malloc(args->addr_len); - if (k->args.addr_len > 0) { - memcpy(k->args.addr, args->addr, k->args.addr_len); + k->args.addr = gpr_malloc(sizeof(grpc_resolved_address)); + k->args.addr->len = args->addr->len; + if (k->args.addr->len > 0) { + memcpy(k->args.addr, args->addr, sizeof(grpc_resolved_address)); } k->args.args = copy_channel_args(args->args); return k; @@ -109,14 +109,14 @@ static int subchannel_key_compare(grpc_subchannel_key *a, grpc_subchannel_key *b) { int c = GPR_ICMP(a->connector, b->connector); if (c != 0) return c; - c = GPR_ICMP(a->args.addr_len, b->args.addr_len); + c = GPR_ICMP(a->args.addr->len, b->args.addr->len); if (c != 0) return c; c = GPR_ICMP(a->args.filter_count, b->args.filter_count); if (c != 0) return c; c = strcmp(a->args.server_name, b->args.server_name); if (c != 0) return c; - if (a->args.addr_len) { - c = memcmp(a->args.addr, b->args.addr, a->args.addr_len); + if (a->args.addr->len) { + c = memcmp(a->args.addr->addr, b->args.addr->addr, a->args.addr->len); if (c != 0) return c; } if (a->args.filter_count > 0) { |