aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2015-07-15 13:46:00 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2015-07-15 13:46:00 -0700
commit658b6087cc07f8706d270ee0e31f28bbf732ec3d (patch)
tree91a876ab4d17a95bd37f6fc3c54f7c20b334947a /src
parentd317e7570bd400ed0ae7ae11fe18674fac3ec734 (diff)
Added some comments, minot stylistic tweaks
Diffstat (limited to 'src')
-rw-r--r--src/core/channel/compress_filter.c24
-rw-r--r--src/core/surface/call.c1
2 files changed, 16 insertions, 9 deletions
diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c
index 69911cbda3..7d6f1a87a6 100644
--- a/src/core/channel/compress_filter.c
+++ b/src/core/channel/compress_filter.c
@@ -110,13 +110,17 @@ static int skip_compression(channel_data *channeld, call_data *calld) {
return channeld->default_compression_algorithm == GRPC_COMPRESS_NONE;
}
+/** Assembles a new grpc_stream_op_buffer with the compressed slices, modifying
+ * the associated GRPC_OP_BEGIN_MESSAGE accordingly (new compressed length,
+ * flags indicating compression is in effect) and replaces \a send_ops with it.
+ * */
static void finish_compressed_sopb(grpc_stream_op_buffer *send_ops,
grpc_call_element *elem) {
size_t i;
- grpc_stream_op_buffer new_send_ops;
call_data *calld = elem->call_data;
int new_slices_added = 0; /* GPR_FALSE */
-
+ grpc_metadata_batch metadata;
+ grpc_stream_op_buffer new_send_ops;
grpc_sopb_init(&new_send_ops);
for (i = 0; i < send_ops->nops; i++) {
@@ -128,6 +132,9 @@ static void finish_compressed_sopb(grpc_stream_op_buffer *send_ops,
sop->data.begin_message.flags | GRPC_WRITE_INTERNAL_COMPRESS);
break;
case GRPC_OP_SLICE:
+ /* Once we reach the slices section of the original buffer, simply add
+ * all the new (compressed) slices. We obviously want to do this only
+ * once, hence the "new_slices_added" guard. */
if (!new_slices_added) {
size_t j;
for (j = 0; j < calld->slices.count; ++j) {
@@ -138,8 +145,9 @@ static void finish_compressed_sopb(grpc_stream_op_buffer *send_ops,
}
break;
case GRPC_OP_METADATA:
- grpc_sopb_add_metadata(&new_send_ops, sop->data.metadata);
- memset(&(sop->data.metadata), 0, sizeof(grpc_metadata_batch));
+ /* move the metadata to the new buffer. */
+ grpc_metadata_batch_move(&metadata, &sop->data.metadata);
+ grpc_sopb_add_metadata(&new_send_ops, metadata);
break;
case GRPC_NO_OP:
break;
@@ -156,12 +164,12 @@ static void process_send_ops(grpc_call_element *elem,
size_t i;
int did_compress = 0;
- /* buffer up slices until we've processed all the expected ones (as given by
- * GRPC_OP_BEGIN_MESSAGE) */
for (i = 0; i < send_ops->nops; ++i) {
grpc_stream_op *sop = &send_ops->ops[i];
switch (sop->type) {
case GRPC_OP_BEGIN_MESSAGE:
+ /* buffer up slices until we've processed all the expected ones (as
+ * given by GRPC_OP_BEGIN_MESSAGE) */
calld->remaining_slice_bytes = sop->data.begin_message.length;
if (sop->data.begin_message.flags & GRPC_WRITE_NO_COMPRESS) {
calld->has_compression_algorithm = 1; /* GPR_TRUE */
@@ -192,12 +200,10 @@ static void process_send_ops(grpc_call_element *elem,
case GRPC_OP_SLICE:
if (skip_compression(channeld, calld)) continue;
GPR_ASSERT(calld->remaining_slice_bytes > 0);
- /* We need to copy the input because gpr_slice_buffer_add takes
- * ownership. However, we don't own sop->data.slice, the caller does. */
+ /* Increase input ref count, gpr_slice_buffer_add takes ownership. */
gpr_slice_buffer_add(&calld->slices, gpr_slice_ref(sop->data.slice));
calld->remaining_slice_bytes -= GPR_SLICE_LENGTH(sop->data.slice);
if (calld->remaining_slice_bytes == 0) {
- /* compress */
did_compress =
compress_send_sb(calld->compression_algorithm, &calld->slices);
}
diff --git a/src/core/surface/call.c b/src/core/surface/call.c
index 717158cf16..ca4a4e0a55 100644
--- a/src/core/surface/call.c
+++ b/src/core/surface/call.c
@@ -717,6 +717,7 @@ static void finish_message(grpc_call *call) {
/* some aliases for readability */
gpr_slice *slices = call->incoming_message.slices;
const size_t nslices = call->incoming_message.count;
+
if ((call->incoming_message_flags & GRPC_WRITE_INTERNAL_COMPRESS) &&
(call->compression_algorithm > GRPC_COMPRESS_NONE)) {
byte_buffer = grpc_raw_compressed_byte_buffer_create(