clang-format

pull/12399/head
Muxi Yan 7 years ago
parent 8e14acc76b
commit 03600fc37d
  1. 9
      src/core/ext/transport/chttp2/transport/chttp2_transport.c
  2. 4
      src/core/ext/transport/chttp2/transport/writing.c
  3. 19
      src/core/lib/compression/stream_compression.c
  4. 22
      src/core/lib/compression/stream_compression.h
  5. 44
      src/core/lib/compression/stream_compression_gzip.c
  6. 36
      src/core/lib/compression/stream_compression_identity.c
  7. 3
      src/core/lib/compression/stream_compression_identity.h

@ -1297,8 +1297,13 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE;
/* Identify stream compression */ /* Identify stream compression */
if (op_payload->send_initial_metadata.send_initial_metadata->idx.named.content_encoding == NULL || if (op_payload->send_initial_metadata.send_initial_metadata->idx.named
grpc_stream_compression_method_parse(GRPC_MDVALUE(op_payload->send_initial_metadata.send_initial_metadata->idx.named.content_encoding->md), true, &s->stream_compression_method) == 0) { .content_encoding == NULL ||
grpc_stream_compression_method_parse(
GRPC_MDVALUE(
op_payload->send_initial_metadata.send_initial_metadata->idx
.named.content_encoding->md),
true, &s->stream_compression_method) == 0) {
s->stream_compression_method = GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS; s->stream_compression_method = GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS;
} }
grpc_slice_buffer_init(&s->compressed_data_buffer); grpc_slice_buffer_init(&s->compressed_data_buffer);

@ -317,8 +317,8 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write(
grpc_chttp2_encode_data(s->id, &s->compressed_data_buffer, grpc_chttp2_encode_data(s->id, &s->compressed_data_buffer,
send_bytes, is_last_frame, send_bytes, is_last_frame,
&s->stats.outgoing, &t->outbuf); &s->stats.outgoing, &t->outbuf);
grpc_chttp2_flowctl_sent_data(&t->flow_control, grpc_chttp2_flowctl_sent_data(&t->flow_control, &s->flow_control,
&s->flow_control, send_bytes); send_bytes);
max_outgoing -= send_bytes; max_outgoing -= send_bytes;
if (s->compressed_data_buffer.length == 0) { if (s->compressed_data_buffer.length == 0) {
s->sending_bytes += s->uncompressed_data_size; s->sending_bytes += s->uncompressed_data_size;

@ -21,20 +21,23 @@
#include "src/core/lib/compression/stream_compression.h" #include "src/core/lib/compression/stream_compression.h"
#include "src/core/lib/compression/stream_compression_gzip.h" #include "src/core/lib/compression/stream_compression_gzip.h"
extern const grpc_stream_compression_vtable grpc_stream_compression_identity_vtable; extern const grpc_stream_compression_vtable
grpc_stream_compression_identity_vtable;
bool grpc_stream_compress(grpc_stream_compression_context *ctx, bool grpc_stream_compress(grpc_stream_compression_context *ctx,
grpc_slice_buffer *in, grpc_slice_buffer *out, grpc_slice_buffer *in, grpc_slice_buffer *out,
size_t *output_size, size_t max_output_size, size_t *output_size, size_t max_output_size,
grpc_stream_compression_flush flush) { grpc_stream_compression_flush flush) {
return ctx->vtable->compress(ctx, in, out, output_size, max_output_size, flush); return ctx->vtable->compress(ctx, in, out, output_size, max_output_size,
flush);
} }
bool grpc_stream_decompress(grpc_stream_compression_context *ctx, bool grpc_stream_decompress(grpc_stream_compression_context *ctx,
grpc_slice_buffer *in, grpc_slice_buffer *out, grpc_slice_buffer *in, grpc_slice_buffer *out,
size_t *output_size, size_t max_output_size, size_t *output_size, size_t max_output_size,
bool *end_of_context) { bool *end_of_context) {
return ctx->vtable->decompress(ctx, in, out, output_size, max_output_size, end_of_context); return ctx->vtable->decompress(ctx, in, out, output_size, max_output_size,
end_of_context);
} }
grpc_stream_compression_context *grpc_stream_compression_context_create( grpc_stream_compression_context *grpc_stream_compression_context_create(
@ -58,15 +61,17 @@ void grpc_stream_compression_context_destroy(
} }
int grpc_stream_compression_method_parse( int grpc_stream_compression_method_parse(
grpc_slice value, bool is_compress, grpc_stream_compression_method *method) { grpc_slice value, bool is_compress,
grpc_stream_compression_method *method) {
if (grpc_slice_eq(value, GRPC_MDSTR_IDENTITY)) { if (grpc_slice_eq(value, GRPC_MDSTR_IDENTITY)) {
*method = is_compress ? GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS : GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS; *method = is_compress ? GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS
: GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS;
return 1; return 1;
} else if (grpc_slice_eq(value, GRPC_MDSTR_GZIP)) { } else if (grpc_slice_eq(value, GRPC_MDSTR_GZIP)) {
*method = is_compress ? GRPC_STREAM_COMPRESSION_GZIP_COMPRESS : GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS; *method = is_compress ? GRPC_STREAM_COMPRESSION_GZIP_COMPRESS
: GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS;
return 1; return 1;
} else { } else {
return 0; return 0;
} }
} }

@ -49,18 +49,16 @@ typedef enum grpc_stream_compression_flush {
} grpc_stream_compression_flush; } grpc_stream_compression_flush;
struct grpc_stream_compression_vtable { struct grpc_stream_compression_vtable {
bool (*compress)(grpc_stream_compression_context *ctx, bool (*compress)(grpc_stream_compression_context *ctx, grpc_slice_buffer *in,
grpc_slice_buffer *in, grpc_slice_buffer *out, grpc_slice_buffer *out, size_t *output_size,
size_t *output_size, size_t max_output_size, size_t max_output_size, grpc_stream_compression_flush flush);
grpc_stream_compression_flush flush); bool (*decompress)(grpc_stream_compression_context *ctx,
bool (*decompress)(grpc_stream_compression_context *ctx, grpc_slice_buffer *in, grpc_slice_buffer *out,
grpc_slice_buffer *in, grpc_slice_buffer *out, size_t *output_size, size_t max_output_size,
size_t *output_size, size_t max_output_size, bool *end_of_context);
bool *end_of_context); grpc_stream_compression_context *(*context_create)(
grpc_stream_compression_context *(*context_create)( grpc_stream_compression_method method);
grpc_stream_compression_method method); void (*context_destroy)(grpc_stream_compression_context *ctx);
void (*context_destroy)(
grpc_stream_compression_context *ctx);
}; };
/** /**

@ -132,13 +132,16 @@ static bool gzip_flate(grpc_stream_compression_context_gzip *ctx,
} }
static bool grpc_stream_compress_gzip(grpc_stream_compression_context *ctx, static bool grpc_stream_compress_gzip(grpc_stream_compression_context *ctx,
grpc_slice_buffer *in, grpc_slice_buffer *out, grpc_slice_buffer *in,
size_t *output_size, size_t max_output_size, grpc_slice_buffer *out,
grpc_stream_compression_flush flush) { size_t *output_size,
size_t max_output_size,
grpc_stream_compression_flush flush) {
if (ctx == NULL) { if (ctx == NULL) {
return false; return false;
} }
grpc_stream_compression_context_gzip *gzip_ctx = (grpc_stream_compression_context_gzip *)ctx; grpc_stream_compression_context_gzip *gzip_ctx =
(grpc_stream_compression_context_gzip *)ctx;
GPR_ASSERT(gzip_ctx->flate == deflate); GPR_ASSERT(gzip_ctx->flate == deflate);
int gzip_flush; int gzip_flush;
switch (flush) { switch (flush) {
@ -159,21 +162,26 @@ static bool grpc_stream_compress_gzip(grpc_stream_compression_context *ctx,
} }
static bool grpc_stream_decompress_gzip(grpc_stream_compression_context *ctx, static bool grpc_stream_decompress_gzip(grpc_stream_compression_context *ctx,
grpc_slice_buffer *in, grpc_slice_buffer *out, grpc_slice_buffer *in,
size_t *output_size, size_t max_output_size, grpc_slice_buffer *out,
bool *end_of_context) { size_t *output_size,
size_t max_output_size,
bool *end_of_context) {
if (ctx == NULL) { if (ctx == NULL) {
return false; return false;
} }
grpc_stream_compression_context_gzip *gzip_ctx = (grpc_stream_compression_context_gzip *)ctx; grpc_stream_compression_context_gzip *gzip_ctx =
(grpc_stream_compression_context_gzip *)ctx;
GPR_ASSERT(gzip_ctx->flate == inflate); GPR_ASSERT(gzip_ctx->flate == inflate);
return gzip_flate(gzip_ctx, in, out, output_size, max_output_size, Z_SYNC_FLUSH, return gzip_flate(gzip_ctx, in, out, output_size, max_output_size,
end_of_context); Z_SYNC_FLUSH, end_of_context);
} }
static grpc_stream_compression_context *grpc_stream_compression_context_create_gzip( static grpc_stream_compression_context *
grpc_stream_compression_context_create_gzip(
grpc_stream_compression_method method) { grpc_stream_compression_method method) {
GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_GZIP_COMPRESS || method == GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS); GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_GZIP_COMPRESS ||
method == GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS);
grpc_stream_compression_context_gzip *gzip_ctx = grpc_stream_compression_context_gzip *gzip_ctx =
gpr_zalloc(sizeof(grpc_stream_compression_context_gzip)); gpr_zalloc(sizeof(grpc_stream_compression_context_gzip));
int r; int r;
@ -201,7 +209,8 @@ static void grpc_stream_compression_context_destroy_gzip(
if (ctx == NULL) { if (ctx == NULL) {
return; return;
} }
grpc_stream_compression_context_gzip *gzip_ctx = (grpc_stream_compression_context_gzip*)ctx; grpc_stream_compression_context_gzip *gzip_ctx =
(grpc_stream_compression_context_gzip *)ctx;
if (gzip_ctx->flate == inflate) { if (gzip_ctx->flate == inflate) {
inflateEnd(&gzip_ctx->zs); inflateEnd(&gzip_ctx->zs);
} else { } else {
@ -211,8 +220,7 @@ static void grpc_stream_compression_context_destroy_gzip(
} }
const grpc_stream_compression_vtable grpc_stream_compression_gzip_vtable = { const grpc_stream_compression_vtable grpc_stream_compression_gzip_vtable = {
.compress = grpc_stream_compress_gzip, .compress = grpc_stream_compress_gzip,
.decompress = grpc_stream_decompress_gzip, .decompress = grpc_stream_decompress_gzip,
.context_create = grpc_stream_compression_context_create_gzip, .context_create = grpc_stream_compression_context_create_gzip,
.context_destroy = grpc_stream_compression_context_destroy_gzip .context_destroy = grpc_stream_compression_context_destroy_gzip};
};

@ -25,7 +25,10 @@
#define OUTPUT_BLOCK_SIZE (1024) #define OUTPUT_BLOCK_SIZE (1024)
static void grpc_stream_compression_pass_through(grpc_slice_buffer *in, grpc_slice_buffer *out, size_t *output_size, size_t max_output_size) { static void grpc_stream_compression_pass_through(grpc_slice_buffer *in,
grpc_slice_buffer *out,
size_t *output_size,
size_t max_output_size) {
if (max_output_size >= in->length) { if (max_output_size >= in->length) {
*output_size = in->length; *output_size = in->length;
grpc_slice_buffer_move_into(in, out); grpc_slice_buffer_move_into(in, out);
@ -36,9 +39,11 @@ static void grpc_stream_compression_pass_through(grpc_slice_buffer *in, grpc_sli
} }
static bool grpc_stream_compress_identity(grpc_stream_compression_context *ctx, static bool grpc_stream_compress_identity(grpc_stream_compression_context *ctx,
grpc_slice_buffer *in, grpc_slice_buffer *out, grpc_slice_buffer *in,
size_t *output_size, size_t max_output_size, grpc_slice_buffer *out,
grpc_stream_compression_flush flush) { size_t *output_size,
size_t max_output_size,
grpc_stream_compression_flush flush) {
if (ctx == NULL) { if (ctx == NULL) {
return false; return false;
} }
@ -46,10 +51,10 @@ static bool grpc_stream_compress_identity(grpc_stream_compression_context *ctx,
return true; return true;
} }
static bool grpc_stream_decompress_identity(grpc_stream_compression_context *ctx, static bool grpc_stream_decompress_identity(
grpc_slice_buffer *in, grpc_slice_buffer *out, grpc_stream_compression_context *ctx, grpc_slice_buffer *in,
size_t *output_size, size_t max_output_size, grpc_slice_buffer *out, size_t *output_size, size_t max_output_size,
bool *end_of_context) { bool *end_of_context) {
if (ctx == NULL) { if (ctx == NULL) {
return false; return false;
} }
@ -57,9 +62,11 @@ static bool grpc_stream_decompress_identity(grpc_stream_compression_context *ctx
return true; return true;
} }
static grpc_stream_compression_context *grpc_stream_compression_context_create_identity( static grpc_stream_compression_context *
grpc_stream_compression_context_create_identity(
grpc_stream_compression_method method) { grpc_stream_compression_method method) {
GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS || method == GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS); GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS ||
method == GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS);
/* No context needed in this case. Use fake context instead. */ /* No context needed in this case. Use fake context instead. */
return (grpc_stream_compression_context *)1; return (grpc_stream_compression_context *)1;
} }
@ -70,8 +77,7 @@ static void grpc_stream_compression_context_destroy_identity(
} }
const grpc_stream_compression_vtable grpc_stream_compression_identity_vtable = { const grpc_stream_compression_vtable grpc_stream_compression_identity_vtable = {
.compress = grpc_stream_compress_identity, .compress = grpc_stream_compress_identity,
.decompress = grpc_stream_decompress_identity, .decompress = grpc_stream_decompress_identity,
.context_create = grpc_stream_compression_context_create_identity, .context_create = grpc_stream_compression_context_create_identity,
.context_destroy = grpc_stream_compression_context_destroy_identity .context_destroy = grpc_stream_compression_context_destroy_identity};
};

@ -21,6 +21,7 @@
#include "src/core/lib/compression/stream_compression.h" #include "src/core/lib/compression/stream_compression.h"
extern const grpc_stream_compression_vtable grpc_stream_compression_identity_vtable; extern const grpc_stream_compression_vtable
grpc_stream_compression_identity_vtable;
#endif #endif

Loading…
Cancel
Save