diff options
author | Craig Tiller <ctiller@google.com> | 2015-08-18 09:27:28 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-08-18 09:27:28 -0700 |
commit | bb1c795f998f052f854a6e1aeebff44e293a29f4 (patch) | |
tree | 9998e4efb1773ba06edcce5fbcaf940b05e54622 /src/core | |
parent | e4fec620b527047cfa80e35da8576d35510975c8 (diff) | |
parent | c31cd86a7448050653e41a861aa331ce5b078a81 (diff) |
Merge pull request #2965 from yang-g/lame_client_error_message
Let lame_client accept error status
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/surface/lame_client.c | 25 | ||||
-rw-r--r-- | src/core/surface/secure_channel_create.c | 8 |
2 files changed, 26 insertions, 7 deletions
diff --git a/src/core/surface/lame_client.c b/src/core/surface/lame_client.c index c4215a2cfb..80704cbf67 100644 --- a/src/core/surface/lame_client.c +++ b/src/core/surface/lame_client.c @@ -50,6 +50,8 @@ typedef struct { typedef struct { grpc_mdctx *mdctx; grpc_channel *master; + grpc_status_code error_code; + const char *error_message; } channel_data; static void lame_start_transport_stream_op(grpc_call_element *elem, @@ -64,11 +66,11 @@ static void lame_start_transport_stream_op(grpc_call_element *elem, if (op->recv_ops != NULL) { char tmp[GPR_LTOA_MIN_BUFSIZE]; grpc_metadata_batch mdb; - gpr_ltoa(GRPC_STATUS_UNKNOWN, tmp); + gpr_ltoa(chand->error_code, tmp); calld->status.md = grpc_mdelem_from_strings(chand->mdctx, "grpc-status", tmp); calld->details.md = grpc_mdelem_from_strings(chand->mdctx, "grpc-message", - "Rpc sent on a lame channel."); + chand->error_message); calld->status.prev = calld->details.next = NULL; calld->status.next = &calld->details; calld->details.prev = &calld->status; @@ -138,8 +140,21 @@ static const grpc_channel_filter lame_filter = { "lame-client", }; -grpc_channel *grpc_lame_client_channel_create(const char *target) { +#define CHANNEL_STACK_FROM_CHANNEL(c) ((grpc_channel_stack *)((c) + 1)) + +grpc_channel *grpc_lame_client_channel_create(const char *target, + grpc_status_code error_code, + const char *error_message) { + grpc_channel *channel; + grpc_channel_element *elem; + channel_data *chand; static const grpc_channel_filter *filters[] = {&lame_filter}; - return grpc_channel_create_from_filters(target, filters, 1, NULL, - grpc_mdctx_create(), 1); + channel = grpc_channel_create_from_filters(target, filters, 1, NULL, + grpc_mdctx_create(), 1); + elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); + GPR_ASSERT(elem->filter == &lame_filter); + chand = (channel_data *)elem->channel_data; + chand->error_code = error_code; + chand->error_message = error_message; + return channel; } diff --git a/src/core/surface/secure_channel_create.c b/src/core/surface/secure_channel_create.c index c3150250b8..5b03ba95a7 100644 --- a/src/core/surface/secure_channel_create.c +++ b/src/core/surface/secure_channel_create.c @@ -199,13 +199,17 @@ grpc_channel *grpc_secure_channel_create(grpc_credentials *creds, if (grpc_find_security_connector_in_args(args) != NULL) { gpr_log(GPR_ERROR, "Cannot set security context in channel args."); - return grpc_lame_client_channel_create(target); + return grpc_lame_client_channel_create( + target, GRPC_STATUS_INVALID_ARGUMENT, + "Security connector exists in channel args."); } if (grpc_credentials_create_security_connector( creds, target, args, NULL, &connector, &new_args_from_connector) != GRPC_SECURITY_OK) { - return grpc_lame_client_channel_create(target); + return grpc_lame_client_channel_create( + target, GRPC_STATUS_INVALID_ARGUMENT, + "Failed to create security connector."); } mdctx = grpc_mdctx_create(); |