浏览代码

Add Z_FINISH flush at end of stream

Muxi Yan 8 年之前
父节点
当前提交
7225408dc7
共有 1 个文件被更改,包括 14 次插入0 次删除
  1. 14 0
      src/core/ext/transport/chttp2/transport/writing.c

+ 14 - 0
src/core/ext/transport/chttp2/transport/writing.c

@@ -325,6 +325,19 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write(
                 is_last_frame =
                     is_last_data_frame && s->send_trailing_metadata != NULL &&
                     grpc_metadata_batch_is_empty(s->send_trailing_metadata);
+                if (is_last_frame && s->stream_compression_ctx) {
+                  GPR_ASSERT(grpc_stream_compress(
+                      s->stream_compression_ctx, &s->flow_controlled_buffer,
+                      s->compressed_data_buffer, NULL, MAX_SIZE_T,
+                      GRPC_STREAM_COMPRESSION_FLUSH_FINISH));
+                  grpc_stream_compression_context_destroy(s->stream_compression_ctx);
+                  s->stream_compression_ctx = NULL;
+                  /* After finish, bytes in s->compressed_data_buffer may be
+                   * more than max_outgoing. Start another round of the current
+                   * while loop so that send_bytes, is_last_data_frame and
+                   * is_last_frame are recalculated. */
+                  continue;
+                }
                 grpc_chttp2_encode_data(s->id, s->compressed_data_buffer,
                                         send_bytes, is_last_frame,
                                         &s->stats.outgoing, &t->outbuf);
@@ -345,6 +358,7 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write(
                     s->stream_compression_ctx, &s->flow_controlled_buffer,
                     s->compressed_data_buffer, NULL, MAX_SIZE_T,
                     GRPC_STREAM_COMPRESSION_FLUSH_SYNC));
+                GPR_ASSERT(s->compressed_data_buffer->length > 0);
               }
             }
           } else {