From a01f7a41cc1153bba33420a31281a5a2eb14c407 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 8 Jul 2015 00:16:50 -0700 Subject: [PATCH] More comments --- src/core/channel/compress_filter.c | 30 ++++++++++++++-------- src/core/transport/chttp2/stream_encoder.c | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c index 655c452ea98..bdcba2ab5fb 100644 --- a/src/core/channel/compress_filter.c +++ b/src/core/channel/compress_filter.c @@ -48,6 +48,7 @@ typedef struct call_data { gpr_slice_buffer slices; grpc_linked_mdelem compression_algorithm_storage; int remaining_slice_bytes; + int seen_initial_metadata; grpc_compression_algorithm compression_algorithm; gpr_uint8 has_compression_algorithm; } call_data; @@ -111,8 +112,8 @@ static int skip_compression(channel_data *channeld, call_data *calld) { return channeld->default_compression_algorithm == GRPC_COMPRESS_NONE; } -static void compressed_sopb(grpc_stream_op_buffer *send_ops, - grpc_call_element *elem) { +static void finish_compressed_sopb(grpc_stream_op_buffer *send_ops, + grpc_call_element *elem) { size_t i, j; call_data *calld = elem->call_data; channel_data *channeld = elem->channel_data; @@ -126,10 +127,13 @@ static void compressed_sopb(grpc_stream_op_buffer *send_ops, sop->data.begin_message.flags |= GRPC_WRITE_INTERNAL_COMPRESS; break; case GRPC_OP_METADATA: - grpc_metadata_batch_add_head( - &(sop->data.metadata), &calld->compression_algorithm_storage, - grpc_mdelem_ref(channeld->mdelem_compression_algorithms - [calld->compression_algorithm])); + if (!calld->seen_initial_metadata) { + grpc_metadata_batch_add_head( + &(sop->data.metadata), &calld->compression_algorithm_storage, + grpc_mdelem_ref(channeld->mdelem_compression_algorithms + [calld->compression_algorithm])); + calld->seen_initial_metadata = 1; /* GPR_TRUE */ + } break; case GRPC_OP_SLICE: gpr_slice_unref(sop->data.slice); @@ -137,8 +141,9 @@ static void compressed_sopb(grpc_stream_op_buffer *send_ops, if (j < calld->slices.count) { sop->data.slice = gpr_slice_ref(calld->slices.slices[j++]); } + break; case GRPC_NO_OP: - ; /* fallthrough */ + break; } } @@ -152,8 +157,8 @@ static void compressed_sopb(grpc_stream_op_buffer *send_ops, * the input. For example, compression may have een requested but somehow it was * decided not to honor the request: the compression flags need to be reset and * the fact that no compression was performed in the end signaled */ -static void not_compressed_sopb(grpc_stream_op_buffer *send_ops, - grpc_call_element *elem) { +static void finish_not_compressed_sopb(grpc_stream_op_buffer *send_ops, + grpc_call_element *elem) { size_t i; call_data *calld = elem->call_data; channel_data *channeld = elem->channel_data; @@ -234,7 +239,11 @@ static void process_send_ops(grpc_call_element *elem, /* Modify the send_ops stream_op_buffer depending on whether compression was * carried out */ - (did_compress ? compressed_sopb : not_compressed_sopb)(send_ops, elem); + if (did_compress) { + finish_compressed_sopb(send_ops, elem); + } else { + finish_not_compressed_sopb(send_ops, elem); + } } /* Called either: @@ -273,6 +282,7 @@ static void init_call_elem(grpc_call_element *elem, /* initialize members */ gpr_slice_buffer_init(&calld->slices); calld->has_compression_algorithm = 0; + calld->seen_initial_metadata = 0; /* GPR_FALSE */ if (initial_op) { if (initial_op->send_ops && initial_op->send_ops->nops > 0) { diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c index d0a17af5daa..243e4cbbda0 100644 --- a/src/core/transport/chttp2/stream_encoder.c +++ b/src/core/transport/chttp2/stream_encoder.c @@ -497,7 +497,7 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count, /* begin op: for now we just convert the op to a slice and fall through - this lets us reuse the slice framing code below */ compressed_flag_set = - !!(op->data.begin_message.flags & GRPC_WRITE_INTERNAL_COMPRESS); + (op->data.begin_message.flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0; slice = gpr_slice_malloc(5); p = GPR_SLICE_START_PTR(slice);