aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/surface/channel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/surface/channel.c')
-rw-r--r--src/core/lib/surface/channel.c106
1 files changed, 59 insertions, 47 deletions
diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c
index 429dbad7c7..b87295786e 100644
--- a/src/core/lib/surface/channel.c
+++ b/src/core/lib/surface/channel.c
@@ -43,7 +43,6 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/iomgr.h"
-#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/support/string.h"
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/call.h"
@@ -58,15 +57,15 @@
#define NUM_CACHED_STATUS_ELEMS 3
typedef struct registered_call {
- grpc_mdelem path;
- grpc_mdelem authority;
+ grpc_mdelem *path;
+ grpc_mdelem *authority;
struct registered_call *next;
} registered_call;
struct grpc_channel {
int is_client;
grpc_compression_options compression_options;
- grpc_mdelem default_authority;
+ grpc_mdelem *default_authority;
gpr_mu registered_call_mu;
registered_call *registered_calls;
@@ -103,8 +102,9 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target,
exec_ctx, builder, sizeof(grpc_channel), 1, destroy_channel, NULL,
(void **)&channel);
if (error != GRPC_ERROR_NONE) {
- gpr_log(GPR_ERROR, "channel stack builder failed: %s",
- grpc_error_string(error));
+ const char *msg = grpc_error_string(error);
+ gpr_log(GPR_ERROR, "channel stack builder failed: %s", msg);
+ grpc_error_free_string(msg);
GRPC_ERROR_UNREF(error);
goto done;
}
@@ -116,19 +116,19 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target,
channel->registered_calls = NULL;
grpc_compression_options_init(&channel->compression_options);
+
for (size_t i = 0; i < args->num_args; i++) {
if (0 == strcmp(args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY)) {
if (args->args[i].type != GRPC_ARG_STRING) {
gpr_log(GPR_ERROR, "%s ignored: it must be a string",
GRPC_ARG_DEFAULT_AUTHORITY);
} else {
- if (!GRPC_MDISNULL(channel->default_authority)) {
+ if (channel->default_authority) {
/* setting this takes precedence over anything else */
GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority);
}
- channel->default_authority = grpc_mdelem_from_slices(
- exec_ctx, GRPC_MDSTR_AUTHORITY,
- grpc_slice_from_copied_string(args->args[i].value.string));
+ channel->default_authority = grpc_mdelem_from_strings(
+ exec_ctx, ":authority", args->args[i].value.string);
}
} else if (0 ==
strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) {
@@ -136,15 +136,14 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target,
gpr_log(GPR_ERROR, "%s ignored: it must be a string",
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG);
} else {
- if (!GRPC_MDISNULL(channel->default_authority)) {
+ if (channel->default_authority) {
/* other ways of setting this (notably ssl) take precedence */
gpr_log(GPR_ERROR,
"%s ignored: default host already set some other way",
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG);
} else {
- channel->default_authority = grpc_mdelem_from_slices(
- exec_ctx, GRPC_MDSTR_AUTHORITY,
- grpc_slice_from_copied_string(args->args[i].value.string));
+ channel->default_authority = grpc_mdelem_from_strings(
+ exec_ctx, ":authority", args->args[i].value.string);
}
}
} else if (0 == strcmp(args->args[i].key,
@@ -192,18 +191,18 @@ void grpc_channel_get_info(grpc_channel *channel,
static grpc_call *grpc_channel_create_call_internal(
grpc_exec_ctx *exec_ctx, grpc_channel *channel, grpc_call *parent_call,
uint32_t propagation_mask, grpc_completion_queue *cq,
- grpc_pollset_set *pollset_set_alternative, grpc_mdelem path_mdelem,
- grpc_mdelem authority_mdelem, gpr_timespec deadline) {
- grpc_mdelem send_metadata[2];
+ grpc_pollset_set *pollset_set_alternative, grpc_mdelem *path_mdelem,
+ grpc_mdelem *authority_mdelem, gpr_timespec deadline) {
+ grpc_mdelem *send_metadata[2];
size_t num_metadata = 0;
GPR_ASSERT(channel->is_client);
GPR_ASSERT(!(cq != NULL && pollset_set_alternative != NULL));
send_metadata[num_metadata++] = path_mdelem;
- if (!GRPC_MDISNULL(authority_mdelem)) {
+ if (authority_mdelem != NULL) {
send_metadata[num_metadata++] = authority_mdelem;
- } else if (!GRPC_MDISNULL(channel->default_authority)) {
+ } else if (channel->default_authority != NULL) {
send_metadata[num_metadata++] = GRPC_MDELEM_REF(channel->default_authority);
}
@@ -228,17 +227,27 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel,
grpc_call *parent_call,
uint32_t propagation_mask,
grpc_completion_queue *cq,
- grpc_slice method, const grpc_slice *host,
+ const char *method, const char *host,
gpr_timespec deadline, void *reserved) {
+ GRPC_API_TRACE(
+ "grpc_channel_create_call("
+ "channel=%p, parent_call=%p, propagation_mask=%x, cq=%p, method=%s, "
+ "host=%s, "
+ "deadline=gpr_timespec { tv_sec: %" PRId64
+ ", tv_nsec: %d, clock_type: %d }, "
+ "reserved=%p)",
+ 10,
+ (channel, parent_call, (unsigned)propagation_mask, cq, method, host,
+ deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type, reserved));
GPR_ASSERT(!reserved);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_call *call = grpc_channel_create_call_internal(
&exec_ctx, channel, parent_call, propagation_mask, cq, NULL,
- grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_PATH,
- grpc_slice_ref_internal(method)),
- host != NULL ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY,
- grpc_slice_ref_internal(*host))
- : GRPC_MDNULL,
+ grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_PATH,
+ grpc_mdstr_from_string(method)),
+ host ? grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_AUTHORITY,
+ grpc_mdstr_from_string(host))
+ : NULL,
deadline);
grpc_exec_ctx_finish(&exec_ctx);
return call;
@@ -246,16 +255,17 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel,
grpc_call *grpc_channel_create_pollset_set_call(
grpc_exec_ctx *exec_ctx, grpc_channel *channel, grpc_call *parent_call,
- uint32_t propagation_mask, grpc_pollset_set *pollset_set, grpc_slice method,
- const grpc_slice *host, gpr_timespec deadline, void *reserved) {
+ uint32_t propagation_mask, grpc_pollset_set *pollset_set,
+ const char *method, const char *host, gpr_timespec deadline,
+ void *reserved) {
GPR_ASSERT(!reserved);
return grpc_channel_create_call_internal(
exec_ctx, channel, parent_call, propagation_mask, NULL, pollset_set,
- grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH,
- grpc_slice_ref_internal(method)),
- host != NULL ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY,
- grpc_slice_ref_internal(*host))
- : GRPC_MDNULL,
+ grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_PATH,
+ grpc_mdstr_from_string(method)),
+ host ? grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_AUTHORITY,
+ grpc_mdstr_from_string(host))
+ : NULL,
deadline);
}
@@ -267,15 +277,12 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method,
4, (channel, method, host, reserved));
GPR_ASSERT(!reserved);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
-
- rc->path = grpc_mdelem_from_slices(
- &exec_ctx, GRPC_MDSTR_PATH,
- grpc_slice_intern(grpc_slice_from_static_string(method)));
+ rc->path = grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_PATH,
+ grpc_mdstr_from_string(method));
rc->authority =
- host ? grpc_mdelem_from_slices(
- &exec_ctx, GRPC_MDSTR_AUTHORITY,
- grpc_slice_intern(grpc_slice_from_static_string(host)))
- : GRPC_MDNULL;
+ host ? grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_AUTHORITY,
+ grpc_mdstr_from_string(host))
+ : NULL;
gpr_mu_lock(&channel->registered_call_mu);
rc->next = channel->registered_calls;
channel->registered_calls = rc;
@@ -303,7 +310,8 @@ grpc_call *grpc_channel_create_registered_call(
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_call *call = grpc_channel_create_call_internal(
&exec_ctx, channel, parent_call, propagation_mask, completion_queue, NULL,
- GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), deadline);
+ GRPC_MDELEM_REF(rc->path),
+ rc->authority ? GRPC_MDELEM_REF(rc->authority) : NULL, deadline);
grpc_exec_ctx_finish(&exec_ctx);
return call;
}
@@ -332,10 +340,14 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, void *arg,
registered_call *rc = channel->registered_calls;
channel->registered_calls = rc->next;
GRPC_MDELEM_UNREF(exec_ctx, rc->path);
- GRPC_MDELEM_UNREF(exec_ctx, rc->authority);
+ if (rc->authority) {
+ GRPC_MDELEM_UNREF(exec_ctx, rc->authority);
+ }
gpr_free(rc);
}
- GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority);
+ if (channel->default_authority != NULL) {
+ GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority);
+ }
gpr_mu_destroy(&channel->registered_call_mu);
gpr_free(channel->target);
gpr_free(channel);
@@ -364,8 +376,8 @@ grpc_compression_options grpc_channel_compression_options(
return channel->compression_options;
}
-grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx,
- grpc_channel *channel, int i) {
+grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx,
+ grpc_channel *channel, int i) {
char tmp[GPR_LTOA_MIN_BUFSIZE];
switch (i) {
case 0:
@@ -376,6 +388,6 @@ grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx,
return GRPC_MDELEM_GRPC_STATUS_2;
}
gpr_ltoa(i, tmp);
- return grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_STATUS,
- grpc_slice_from_copied_string(tmp));
+ return grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_GRPC_STATUS,
+ grpc_mdstr_from_string(tmp));
}