aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Makdharma <makarandd@google.com>2016-08-26 10:02:00 -0700
committerGravatar Makdharma <makarandd@google.com>2016-08-26 10:02:00 -0700
commit6a523f0a0361e7cd9dcdf0ff31f375e306247a1c (patch)
treecf7cd0cb5a3ff549e81ce0a845dbbf3c94e3e861 /src/core
parent178f4bc24da2b1d4d9f52c010be5a1f63d1c4224 (diff)
working with send_message with multiple slices
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lib/channel/http_client_filter.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c
index 87256184bb..f127e3a964 100644
--- a/src/core/lib/channel/http_client_filter.c
+++ b/src/core/lib/channel/http_client_filter.c
@@ -53,6 +53,7 @@ typedef struct call_data {
grpc_linked_mdelem payload_bin;
grpc_metadata_batch *recv_initial_metadata;
+ uint8_t *payload_bytes;
/** Closure to call when finished with the hc_on_recv hook */
grpc_closure *on_done_recv;
@@ -151,17 +152,23 @@ static void hc_mutate_op(grpc_call_element *elem,
if (method == GRPC_MDELEM_METHOD_GET) {
gpr_slice slice;
- /* TODO (makdharma): extend code for messages with multiple slices */
- if (grpc_byte_stream_next(NULL, op->send_message, &slice,
- op->send_message->length, NULL)) {
- grpc_mdelem *payload_bin = grpc_mdelem_from_metadata_strings(
+ gpr_slice_buffer slices;
+ gpr_slice_buffer_init(&slices);
+ calld->payload_bytes = gpr_malloc(op->send_message->length);
+ uint8_t *wrptr = calld->payload_bytes;
+
+ while (grpc_byte_stream_next(NULL, op->send_message, &slice, ~(size_t)0, NULL)) {
+ memcpy(wrptr, GPR_SLICE_START_PTR(slice), GPR_SLICE_LENGTH(slice));
+ wrptr += GPR_SLICE_LENGTH(slice);
+ gpr_slice_buffer_add(&slices, slice);
+ if (op->send_message->length == slices.length) {
+ grpc_mdelem *payload_bin = grpc_mdelem_from_metadata_strings(
GRPC_MDSTR_GRPC_PAYLOAD_BIN,
- grpc_mdstr_from_buffer(GPR_SLICE_START_PTR(slice),
- GPR_SLICE_LENGTH(slice)));
- grpc_metadata_batch_add_tail(op->send_initial_metadata,
- &calld->payload_bin, payload_bin);
- } else {
- gpr_log(GPR_ERROR, "send_message could not be read");
+ grpc_mdstr_from_buffer(calld->payload_bytes, op->send_message->length));
+ grpc_metadata_batch_add_tail(op->send_initial_metadata,
+ &calld->payload_bin, payload_bin);
+ break;
+ }
}
op->send_message = NULL;
}
@@ -246,7 +253,7 @@ static size_t max_payload_size_from_args(const grpc_channel_args *args) {
gpr_log(GPR_ERROR, "%s: must be an integer",
GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET);
} else {
- return args->args[i].value.integer;
+ return (size_t)args->args[i].value.integer;
}
}
}