Add patch to identity

pull/12399/head
Muxi Yan 7 years ago
parent c3229b777c
commit 93197df3d5
  1. 3
      src/core/lib/compression/stream_compression_gzip.c
  2. 15
      src/core/lib/compression/stream_compression_identity.c

@ -19,7 +19,7 @@
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/lib/compression/stream_compression.h" #include "src/core/lib/compression/stream_compression_gzip.h"
#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
@ -201,6 +201,7 @@ grpc_stream_compression_context_create_gzip(
return NULL; return NULL;
} }
gzip_ctx->base.vtable = &grpc_stream_compression_gzip_vtable;
return (grpc_stream_compression_context *)gzip_ctx; return (grpc_stream_compression_context *)gzip_ctx;
} }

@ -19,21 +19,30 @@
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/lib/compression/stream_compression.h" #include "src/core/lib/compression/stream_compression_identity.h"
#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
#define OUTPUT_BLOCK_SIZE (1024) #define OUTPUT_BLOCK_SIZE (1024)
/* Singleton context used for all identity streams. */
static grpc_stream_compression_context identity_ctx = {
.vtable = &grpc_stream_compression_identity_vtable
};
static void grpc_stream_compression_pass_through(grpc_slice_buffer *in, static void grpc_stream_compression_pass_through(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) {
if (max_output_size >= in->length) { if (max_output_size >= in->length) {
if (output_size) {
*output_size = in->length; *output_size = in->length;
}
grpc_slice_buffer_move_into(in, out); grpc_slice_buffer_move_into(in, out);
} else { } else {
if (output_size) {
*output_size = max_output_size; *output_size = max_output_size;
}
grpc_slice_buffer_move_first(in, max_output_size, out); grpc_slice_buffer_move_first(in, max_output_size, out);
} }
} }
@ -59,7 +68,9 @@ static bool grpc_stream_decompress_identity(
return false; return false;
} }
grpc_stream_compression_pass_through(in, out, output_size, max_output_size); grpc_stream_compression_pass_through(in, out, output_size, max_output_size);
if (end_of_context) {
*end_of_context = false; *end_of_context = false;
}
return true; return true;
} }
@ -69,7 +80,7 @@ grpc_stream_compression_context_create_identity(
GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS || GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS ||
method == GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS); 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 *)&identity_ctx;
} }
static void grpc_stream_compression_context_destroy_identity( static void grpc_stream_compression_context_destroy_identity(

Loading…
Cancel
Save