From 2477cf37783bf580d45261fb44706fe99d6959d9 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 26 Sep 2017 12:20:35 -0700 Subject: Revert "General executor speedups, introspection" --- tools/codegen/core/gen_stats_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/codegen') diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 10ad0cc831..8359734c84 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -147,8 +147,7 @@ def gen_bucket_code(histogram): shift_data = find_ideal_shift(code_bounds[first_nontrivial:], 256 * histogram.buckets) #print first_nontrivial, shift_data, bounds #if shift_data is not None: print [hex(x >> shift_data[0]) for x in code_bounds[first_nontrivial:]] - code = '\n/* Automatically generated by tools/codegen/core/gen_stats_data.py */\n' - code += 'value = GPR_CLAMP(value, 0, %d);\n' % histogram.max + code = 'value = GPR_CLAMP(value, 0, %d);\n' % histogram.max map_table = gen_map_table(code_bounds[first_nontrivial:], shift_data) if first_nontrivial is None: code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, value);\n' @@ -408,3 +407,4 @@ with open('src/core/lib/debug/stats_data_bq_schema.sql', 'w') as S: for counter in inst_map['Counter']: columns.append(('%s_per_iteration' % counter.name, 'FLOAT')) print >>S, ',\n'.join('%s:%s' % x for x in columns) + -- cgit v1.2.3 From 90adcf5e989ddb66ea9f23227a17f842b8f53e28 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Thu, 21 Sep 2017 21:55:46 -0700 Subject: gen_static_metadata.py would generate .cc now. Also fixed asan build failures --- src/core/ext/transport/chttp2/transport/flow_control.cc | 4 ++-- tools/codegen/core/gen_static_metadata.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/codegen') diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index 569a6349d3..037813340d 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -86,7 +86,7 @@ static char* fmt_uint32_diff_str(uint32_t old_val, uint32_t new_val) { static void posttrace(shadow_flow_control* shadow_fc, grpc_chttp2_transport_flowctl* tfc, - grpc_chttp2_stream_flowctl* sfc, char* reason) { + grpc_chttp2_stream_flowctl* sfc, const char* reason) { uint32_t acked_local_window = tfc->t->settings[GRPC_SENT_SETTINGS] [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]; @@ -128,7 +128,7 @@ static void posttrace(shadow_flow_control* shadow_fc, gpr_free(saw_str); } -static char* urgency_to_string(grpc_chttp2_flowctl_urgency urgency) { +static const char* urgency_to_string(grpc_chttp2_flowctl_urgency urgency) { switch (urgency) { case GRPC_CHTTP2_FLOWCTL_NO_ACTION_NEEDED: return "no action"; diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index af7521da36..0833204e19 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -304,7 +304,7 @@ else: C = open( os.path.join( os.path.dirname(sys.argv[0]), - '../../../src/core/lib/transport/static_metadata.c'), 'w') + '../../../src/core/lib/transport/static_metadata.cc'), 'w') D = open( os.path.join( os.path.dirname(sys.argv[0]), -- cgit v1.2.3 From 19f0a909ac8d75fda477b4053cae1dd3a9f6c3d2 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Fri, 22 Sep 2017 09:56:18 -0700 Subject: pointer conversion for libuv build. gen_stats_data.py to generate .cc --- src/core/lib/iomgr/pollset_uv.cc | 2 +- tools/codegen/core/gen_stats_data.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/codegen') diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index 2651325e25..7ea5019ad5 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -65,7 +65,7 @@ void dummy_handle_close_cb(uv_handle_t *handle) { gpr_free(handle); } void grpc_pollset_global_init(void) { gpr_mu_init(&grpc_polling_mu); - dummy_uv_handle = gpr_malloc(sizeof(uv_timer_t)); + dummy_uv_handle = (uv_timer_t *)gpr_malloc(sizeof(uv_timer_t)); uv_timer_init(uv_default_loop(), dummy_uv_handle); grpc_pollset_work_run_loop = 1; } diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 8359734c84..2717fa836d 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -255,7 +255,7 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H print >>H, "#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */" -with open('src/core/lib/debug/stats_data.c', 'w') as C: +with open('src/core/lib/debug/stats_data.cc', 'w') as C: # copy-paste copyright notice from this file with open(sys.argv[0]) as my_source: copyright = [] -- cgit v1.2.3 From 547653ebdb3cc16e3c0fb65383322bc7dacc9b90 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Mon, 25 Sep 2017 21:20:19 -0700 Subject: some build changes, some unresolved dependencies --- build.yaml | 1 + .../grpclb/proto/grpc/lb/v1/load_balancer.pb.c | 21 ++------------------- .../ext/transport/chttp2/transport/stream_lists.cc | 1 + src/core/lib/iomgr/tcp_windows.cc | 1 + src/core/lib/support/cpu_iphone.cc | 2 ++ src/core/lib/support/cpu_posix.cc | 1 + src/core/lib/support/cpu_windows.cc | 1 + src/core/lib/support/string_util_windows.cc | 1 + src/core/lib/support/wrap_memcpy.cc | 2 ++ src/core/lib/transport/static_metadata.h | 7 +++++++ tools/codegen/core/gen_static_metadata.py | 8 ++++++++ tools/run_tests/generated/sources_and_headers.json | 1 + 12 files changed, 28 insertions(+), 19 deletions(-) (limited to 'tools/codegen') diff --git a/build.yaml b/build.yaml index 06b1618f88..0f411f8645 100644 --- a/build.yaml +++ b/build.yaml @@ -763,6 +763,7 @@ filegroups: - gpr filegroups: - grpc_trace_headers + - grpc_base_headers - name: grpc_trace_headers headers: - src/core/lib/debug/trace.h diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c b/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c index dd0ccc8476..6a5d54c82a 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c @@ -1,20 +1,3 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ /* Automatically generated nanopb constant definitions */ /* Generated by nanopb-0.3.7-dev */ @@ -97,7 +80,7 @@ const pb_field_t grpc_lb_v1_Server_fields[5] = { #if !defined(PB_FIELD_32BIT) /* If you get an error here, it means that you need to define PB_FIELD_32BIT * compile-time option. You can do that in pb.h or on compiler command line. - * + * * The reason you need to do this is that some of your messages contain tag * numbers or field sizes that are larger than what can fit in 8 or 16 bit * field descriptors. @@ -108,7 +91,7 @@ PB_STATIC_ASSERT((pb_membersize(grpc_lb_v1_LoadBalanceRequest, initial_request) #if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) /* If you get an error here, it means that you need to define PB_FIELD_16BIT * compile-time option. You can do that in pb.h or on compiler command line. - * + * * The reason you need to do this is that some of your messages contain tag * numbers or field sizes that are larger than what can fit in the default * 8 bit descriptors. diff --git a/src/core/ext/transport/chttp2/transport/stream_lists.cc b/src/core/ext/transport/chttp2/transport/stream_lists.cc index 34f62aef84..9f731a397f 100644 --- a/src/core/ext/transport/chttp2/transport/stream_lists.cc +++ b/src/core/ext/transport/chttp2/transport/stream_lists.cc @@ -16,6 +16,7 @@ * */ +#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/ext/transport/chttp2/transport/internal.h" #include diff --git a/src/core/lib/iomgr/tcp_windows.cc b/src/core/lib/iomgr/tcp_windows.cc index d3659a077f..daf15b4944 100644 --- a/src/core/lib/iomgr/tcp_windows.cc +++ b/src/core/lib/iomgr/tcp_windows.cc @@ -37,6 +37,7 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/socket_windows.h" #include "src/core/lib/iomgr/tcp_client.h" +#include "src/core/lib/iomgr/tcp_windows.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/slice/slice_internal.h" diff --git a/src/core/lib/support/cpu_iphone.cc b/src/core/lib/support/cpu_iphone.cc index dfd69b9fd8..2847e03ba5 100644 --- a/src/core/lib/support/cpu_iphone.cc +++ b/src/core/lib/support/cpu_iphone.cc @@ -18,6 +18,8 @@ #include +#include + #ifdef GPR_CPU_IPHONE /* Probably 2 instead of 1, but see comment on gpr_cpu_current_cpu. */ diff --git a/src/core/lib/support/cpu_posix.cc b/src/core/lib/support/cpu_posix.cc index a1ba8202a8..503a96b4c8 100644 --- a/src/core/lib/support/cpu_posix.cc +++ b/src/core/lib/support/cpu_posix.cc @@ -24,6 +24,7 @@ #include #include +#include #include #include #include diff --git a/src/core/lib/support/cpu_windows.cc b/src/core/lib/support/cpu_windows.cc index af26ff3679..8d89453403 100644 --- a/src/core/lib/support/cpu_windows.cc +++ b/src/core/lib/support/cpu_windows.cc @@ -19,6 +19,7 @@ #include #ifdef GPR_WINDOWS +#include #include unsigned gpr_cpu_num_cores(void) { diff --git a/src/core/lib/support/string_util_windows.cc b/src/core/lib/support/string_util_windows.cc index f170669391..86e19527a7 100644 --- a/src/core/lib/support/string_util_windows.cc +++ b/src/core/lib/support/string_util_windows.cc @@ -33,6 +33,7 @@ #include #include +#include #include #include "src/core/lib/support/string.h" diff --git a/src/core/lib/support/wrap_memcpy.cc b/src/core/lib/support/wrap_memcpy.cc index cff056dc3b..c2362bf5b8 100644 --- a/src/core/lib/support/wrap_memcpy.cc +++ b/src/core/lib/support/wrap_memcpy.cc @@ -26,6 +26,7 @@ * Enable by setting LDFLAGS=-Wl,-wrap,memcpy when linking. */ +extern "C" { #ifdef __linux__ #if defined(__x86_64__) && !defined(GPR_MUSL_LIBC_COMPAT) __asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); @@ -38,3 +39,4 @@ void *__wrap_memcpy(void *destination, const void *source, size_t num) { } #endif #endif +} diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index f03a9d23b1..299410f22c 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -27,6 +27,10 @@ #ifndef GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H #define GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H +#ifdef __cplusplus +extern "C" { +#endif + #include "src/core/lib/transport/metadata.h" #define GRPC_STATIC_MDSTR_COUNT 100 @@ -584,4 +588,7 @@ extern const uint8_t grpc_static_accept_stream_encoding_metadata[4]; (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table \ [grpc_static_accept_stream_encoding_metadata[(algs)]], \ GRPC_MDELEM_STORAGE_STATIC)) +#ifdef __cplusplus +} +#endif #endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */ diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 0833204e19..355f3f4e23 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -354,6 +354,10 @@ an explanation of what's going on. print >> H, '#ifndef GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H' print >> H, '#define GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H' print >> H +print >> H, '#ifdef __cplusplus' +print >> H, 'extern "C" {' +print >> H, '#endif' +print >> H print >> H, '#include "src/core/lib/transport/metadata.h"' print >> H @@ -589,6 +593,10 @@ print >> C, '};' print >> H, '#define GRPC_MDELEM_ACCEPT_STREAM_ENCODING_FOR_ALGORITHMS(algs) (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[grpc_static_accept_stream_encoding_metadata[(algs)]], GRPC_MDELEM_STORAGE_STATIC))' +print >> H, '#ifdef __cplusplus' +print >> H, '}' +print >> H, '#endif' + print >> H, '#endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */' H.close() diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index d4c09eeddf..b23c5d7bc9 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -8951,6 +8951,7 @@ { "deps": [ "gpr", + "grpc_base_headers", "grpc_trace_headers" ], "headers": [], -- cgit v1.2.3 From bc460fa3c41ead4323c6fcb42f1a76c9cbef9b14 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Mon, 2 Oct 2017 17:42:41 -0700 Subject: Rebasing on master for easier merging and testing --- CMakeLists.txt | 12 ++ Makefile | 12 ++ binding.gyp | 2 + build.yaml | 2 + config.m4 | 2 + config.w32 | 2 + gRPC-Core.podspec | 2 + grpc.gemspec | 2 + grpc.gyp | 8 + package.xml | 2 + src/core/lib/compression/stream_compression.h | 4 +- src/core/lib/compression/stream_compression_gzip.c | 227 --------------------- .../lib/compression/stream_compression_gzip.cc | 227 +++++++++++++++++++++ src/core/lib/compression/stream_compression_gzip.h | 8 + .../lib/compression/stream_compression_identity.c | 93 --------- .../lib/compression/stream_compression_identity.cc | 93 +++++++++ .../lib/compression/stream_compression_identity.h | 8 + src/core/lib/debug/stats_data.h | 8 + src/core/lib/iomgr/gethostname.h | 1 - src/core/lib/iomgr/gethostname_fallback.cc | 2 +- src/core/lib/iomgr/gethostname_host_name_max.cc | 2 +- src/core/lib/iomgr/gethostname_sysconf.cc | 2 +- src/core/lib/iomgr/socket_utils_windows.cc | 4 - src/core/lib/iomgr/tcp_client_uv.cc | 8 +- src/python/grpcio/grpc_core_dependencies.py | 2 + tools/codegen/core/gen_stats_data.py | 8 + tools/doxygen/Doxyfile.core.internal | 2 + tools/run_tests/generated/sources_and_headers.json | 2 + 28 files changed, 413 insertions(+), 334 deletions(-) delete mode 100644 src/core/lib/compression/stream_compression_gzip.c create mode 100644 src/core/lib/compression/stream_compression_gzip.cc delete mode 100644 src/core/lib/compression/stream_compression_identity.c create mode 100644 src/core/lib/compression/stream_compression_identity.cc (limited to 'tools/codegen') diff --git a/CMakeLists.txt b/CMakeLists.txt index e3a1da0665..dcef03963c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -965,6 +965,8 @@ add_library(grpc src/core/lib/compression/compression.cc src/core/lib/compression/message_compress.cc src/core/lib/compression/stream_compression.cc + src/core/lib/compression/stream_compression_gzip.cc + src/core/lib/compression/stream_compression_identity.cc src/core/lib/debug/stats.cc src/core/lib/debug/stats_data.cc src/core/lib/http/format_request.cc @@ -1314,6 +1316,8 @@ add_library(grpc_cronet src/core/lib/compression/compression.cc src/core/lib/compression/message_compress.cc src/core/lib/compression/stream_compression.cc + src/core/lib/compression/stream_compression_gzip.cc + src/core/lib/compression/stream_compression_identity.cc src/core/lib/debug/stats.cc src/core/lib/debug/stats_data.cc src/core/lib/http/format_request.cc @@ -1631,6 +1635,8 @@ add_library(grpc_test_util src/core/lib/compression/compression.cc src/core/lib/compression/message_compress.cc src/core/lib/compression/stream_compression.cc + src/core/lib/compression/stream_compression_gzip.cc + src/core/lib/compression/stream_compression_identity.cc src/core/lib/debug/stats.cc src/core/lib/debug/stats_data.cc src/core/lib/http/format_request.cc @@ -1892,6 +1898,8 @@ add_library(grpc_test_util_unsecure src/core/lib/compression/compression.cc src/core/lib/compression/message_compress.cc src/core/lib/compression/stream_compression.cc + src/core/lib/compression/stream_compression_gzip.cc + src/core/lib/compression/stream_compression_identity.cc src/core/lib/debug/stats.cc src/core/lib/debug/stats_data.cc src/core/lib/http/format_request.cc @@ -2139,6 +2147,8 @@ add_library(grpc_unsecure src/core/lib/compression/compression.cc src/core/lib/compression/message_compress.cc src/core/lib/compression/stream_compression.cc + src/core/lib/compression/stream_compression_gzip.cc + src/core/lib/compression/stream_compression_identity.cc src/core/lib/debug/stats.cc src/core/lib/debug/stats_data.cc src/core/lib/http/format_request.cc @@ -2894,6 +2904,8 @@ add_library(grpc++_cronet src/core/lib/compression/compression.cc src/core/lib/compression/message_compress.cc src/core/lib/compression/stream_compression.cc + src/core/lib/compression/stream_compression_gzip.cc + src/core/lib/compression/stream_compression_identity.cc src/core/lib/debug/stats.cc src/core/lib/debug/stats_data.cc src/core/lib/http/format_request.cc diff --git a/Makefile b/Makefile index 9a871b7702..0fb5d4fab9 100644 --- a/Makefile +++ b/Makefile @@ -2956,6 +2956,8 @@ LIBGRPC_SRC = \ src/core/lib/compression/compression.cc \ src/core/lib/compression/message_compress.cc \ src/core/lib/compression/stream_compression.cc \ + src/core/lib/compression/stream_compression_gzip.cc \ + src/core/lib/compression/stream_compression_identity.cc \ src/core/lib/debug/stats.cc \ src/core/lib/debug/stats_data.cc \ src/core/lib/http/format_request.cc \ @@ -3305,6 +3307,8 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/compression/compression.cc \ src/core/lib/compression/message_compress.cc \ src/core/lib/compression/stream_compression.cc \ + src/core/lib/compression/stream_compression_gzip.cc \ + src/core/lib/compression/stream_compression_identity.cc \ src/core/lib/debug/stats.cc \ src/core/lib/debug/stats_data.cc \ src/core/lib/http/format_request.cc \ @@ -3621,6 +3625,8 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/compression/compression.cc \ src/core/lib/compression/message_compress.cc \ src/core/lib/compression/stream_compression.cc \ + src/core/lib/compression/stream_compression_gzip.cc \ + src/core/lib/compression/stream_compression_identity.cc \ src/core/lib/debug/stats.cc \ src/core/lib/debug/stats_data.cc \ src/core/lib/http/format_request.cc \ @@ -3873,6 +3879,8 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/compression/compression.cc \ src/core/lib/compression/message_compress.cc \ src/core/lib/compression/stream_compression.cc \ + src/core/lib/compression/stream_compression_gzip.cc \ + src/core/lib/compression/stream_compression_identity.cc \ src/core/lib/debug/stats.cc \ src/core/lib/debug/stats_data.cc \ src/core/lib/http/format_request.cc \ @@ -4098,6 +4106,8 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/compression/compression.cc \ src/core/lib/compression/message_compress.cc \ src/core/lib/compression/stream_compression.cc \ + src/core/lib/compression/stream_compression_gzip.cc \ + src/core/lib/compression/stream_compression_identity.cc \ src/core/lib/debug/stats.cc \ src/core/lib/debug/stats_data.cc \ src/core/lib/http/format_request.cc \ @@ -4836,6 +4846,8 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/compression/compression.cc \ src/core/lib/compression/message_compress.cc \ src/core/lib/compression/stream_compression.cc \ + src/core/lib/compression/stream_compression_gzip.cc \ + src/core/lib/compression/stream_compression_identity.cc \ src/core/lib/debug/stats.cc \ src/core/lib/debug/stats_data.cc \ src/core/lib/http/format_request.cc \ diff --git a/binding.gyp b/binding.gyp index 889b563e39..7caf5c3552 100644 --- a/binding.gyp +++ b/binding.gyp @@ -667,6 +667,8 @@ 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/message_compress.cc', 'src/core/lib/compression/stream_compression.cc', + 'src/core/lib/compression/stream_compression_gzip.cc', + 'src/core/lib/compression/stream_compression_identity.cc', 'src/core/lib/debug/stats.cc', 'src/core/lib/debug/stats_data.cc', 'src/core/lib/http/format_request.cc', diff --git a/build.yaml b/build.yaml index 0f411f8645..582f5d5a6a 100644 --- a/build.yaml +++ b/build.yaml @@ -195,6 +195,8 @@ filegroups: - src/core/lib/compression/compression.cc - src/core/lib/compression/message_compress.cc - src/core/lib/compression/stream_compression.cc + - src/core/lib/compression/stream_compression_gzip.cc + - src/core/lib/compression/stream_compression_identity.cc - src/core/lib/debug/stats.cc - src/core/lib/debug/stats_data.cc - src/core/lib/http/format_request.cc diff --git a/config.m4 b/config.m4 index 5450bbeb1d..34d7116c73 100644 --- a/config.m4 +++ b/config.m4 @@ -96,6 +96,8 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/compression/compression.cc \ src/core/lib/compression/message_compress.cc \ src/core/lib/compression/stream_compression.cc \ + src/core/lib/compression/stream_compression_gzip.cc \ + src/core/lib/compression/stream_compression_identity.cc \ src/core/lib/debug/stats.cc \ src/core/lib/debug/stats_data.cc \ src/core/lib/http/format_request.cc \ diff --git a/config.w32 b/config.w32 index 62b8dcdd76..3535582699 100644 --- a/config.w32 +++ b/config.w32 @@ -73,6 +73,8 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\compression\\compression.cc " + "src\\core\\lib\\compression\\message_compress.cc " + "src\\core\\lib\\compression\\stream_compression.cc " + + "src\\core\\lib\\compression\\stream_compression_gzip.cc " + + "src\\core\\lib\\compression\\stream_compression_identity.cc " + "src\\core\\lib\\debug\\stats.cc " + "src\\core\\lib\\debug\\stats_data.cc " + "src\\core\\lib\\http\\format_request.cc " + diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index e831058ee1..c1e8663336 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -481,6 +481,8 @@ Pod::Spec.new do |s| 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/message_compress.cc', 'src/core/lib/compression/stream_compression.cc', + 'src/core/lib/compression/stream_compression_gzip.cc', + 'src/core/lib/compression/stream_compression_identity.cc', 'src/core/lib/debug/stats.cc', 'src/core/lib/debug/stats_data.cc', 'src/core/lib/http/format_request.cc', diff --git a/grpc.gemspec b/grpc.gemspec index 98bdbe10e1..c37859f3d1 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -418,6 +418,8 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/compression/compression.cc ) s.files += %w( src/core/lib/compression/message_compress.cc ) s.files += %w( src/core/lib/compression/stream_compression.cc ) + s.files += %w( src/core/lib/compression/stream_compression_gzip.cc ) + s.files += %w( src/core/lib/compression/stream_compression_identity.cc ) s.files += %w( src/core/lib/debug/stats.cc ) s.files += %w( src/core/lib/debug/stats_data.cc ) s.files += %w( src/core/lib/http/format_request.cc ) diff --git a/grpc.gyp b/grpc.gyp index 55853a65c9..f10d1fe860 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -233,6 +233,8 @@ 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/message_compress.cc', 'src/core/lib/compression/stream_compression.cc', + 'src/core/lib/compression/stream_compression_gzip.cc', + 'src/core/lib/compression/stream_compression_identity.cc', 'src/core/lib/debug/stats.cc', 'src/core/lib/debug/stats_data.cc', 'src/core/lib/http/format_request.cc', @@ -532,6 +534,8 @@ 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/message_compress.cc', 'src/core/lib/compression/stream_compression.cc', + 'src/core/lib/compression/stream_compression_gzip.cc', + 'src/core/lib/compression/stream_compression_identity.cc', 'src/core/lib/debug/stats.cc', 'src/core/lib/debug/stats_data.cc', 'src/core/lib/http/format_request.cc', @@ -736,6 +740,8 @@ 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/message_compress.cc', 'src/core/lib/compression/stream_compression.cc', + 'src/core/lib/compression/stream_compression_gzip.cc', + 'src/core/lib/compression/stream_compression_identity.cc', 'src/core/lib/debug/stats.cc', 'src/core/lib/debug/stats_data.cc', 'src/core/lib/http/format_request.cc', @@ -925,6 +931,8 @@ 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/message_compress.cc', 'src/core/lib/compression/stream_compression.cc', + 'src/core/lib/compression/stream_compression_gzip.cc', + 'src/core/lib/compression/stream_compression_identity.cc', 'src/core/lib/debug/stats.cc', 'src/core/lib/debug/stats_data.cc', 'src/core/lib/http/format_request.cc', diff --git a/package.xml b/package.xml index 0656c457d2..52373c4b51 100644 --- a/package.xml +++ b/package.xml @@ -430,6 +430,8 @@ + + diff --git a/src/core/lib/compression/stream_compression.h b/src/core/lib/compression/stream_compression.h index 901f9357ee..6ee3ac1966 100644 --- a/src/core/lib/compression/stream_compression.h +++ b/src/core/lib/compression/stream_compression.h @@ -24,12 +24,12 @@ #include #include +#include "src/core/lib/transport/static_metadata.h" + #ifdef __cplusplus extern "C" { #endif -#include "src/core/lib/transport/static_metadata.h" - typedef struct grpc_stream_compression_vtable grpc_stream_compression_vtable; /* Stream compression/decompression context */ diff --git a/src/core/lib/compression/stream_compression_gzip.c b/src/core/lib/compression/stream_compression_gzip.c deleted file mode 100644 index 087b018be5..0000000000 --- a/src/core/lib/compression/stream_compression_gzip.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include "src/core/lib/compression/stream_compression_gzip.h" -#include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/slice/slice_internal.h" - -#define OUTPUT_BLOCK_SIZE (1024) - -typedef struct grpc_stream_compression_context_gzip { - grpc_stream_compression_context base; - - z_stream zs; - int (*flate)(z_stream *zs, int flush); -} grpc_stream_compression_context_gzip; - -static bool gzip_flate(grpc_stream_compression_context_gzip *ctx, - grpc_slice_buffer *in, grpc_slice_buffer *out, - size_t *output_size, size_t max_output_size, int flush, - bool *end_of_context) { - GPR_ASSERT(flush == 0 || flush == Z_SYNC_FLUSH || flush == Z_FINISH); - /* Full flush is not allowed when inflating. */ - GPR_ASSERT(!(ctx->flate == inflate && (flush == Z_FINISH))); - - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - int r; - bool eoc = false; - size_t original_max_output_size = max_output_size; - while (max_output_size > 0 && (in->length > 0 || flush) && !eoc) { - size_t slice_size = max_output_size < OUTPUT_BLOCK_SIZE ? max_output_size - : OUTPUT_BLOCK_SIZE; - grpc_slice slice_out = GRPC_SLICE_MALLOC(slice_size); - ctx->zs.avail_out = (uInt)slice_size; - ctx->zs.next_out = GRPC_SLICE_START_PTR(slice_out); - while (ctx->zs.avail_out > 0 && in->length > 0 && !eoc) { - grpc_slice slice = grpc_slice_buffer_take_first(in); - ctx->zs.avail_in = (uInt)GRPC_SLICE_LENGTH(slice); - ctx->zs.next_in = GRPC_SLICE_START_PTR(slice); - r = ctx->flate(&ctx->zs, Z_NO_FLUSH); - if (r < 0 && r != Z_BUF_ERROR) { - gpr_log(GPR_ERROR, "zlib error (%d)", r); - grpc_slice_unref_internal(&exec_ctx, slice_out); - grpc_exec_ctx_finish(&exec_ctx); - return false; - } else if (r == Z_STREAM_END && ctx->flate == inflate) { - eoc = true; - } - if (ctx->zs.avail_in > 0) { - grpc_slice_buffer_undo_take_first( - in, - grpc_slice_sub(slice, GRPC_SLICE_LENGTH(slice) - ctx->zs.avail_in, - GRPC_SLICE_LENGTH(slice))); - } - grpc_slice_unref_internal(&exec_ctx, slice); - } - if (flush != 0 && ctx->zs.avail_out > 0 && !eoc) { - GPR_ASSERT(in->length == 0); - r = ctx->flate(&ctx->zs, flush); - if (flush == Z_SYNC_FLUSH) { - switch (r) { - case Z_OK: - /* Maybe flush is not complete; just made some partial progress. */ - if (ctx->zs.avail_out > 0) { - flush = 0; - } - break; - case Z_BUF_ERROR: - case Z_STREAM_END: - flush = 0; - break; - default: - gpr_log(GPR_ERROR, "zlib error (%d)", r); - grpc_slice_unref_internal(&exec_ctx, slice_out); - grpc_exec_ctx_finish(&exec_ctx); - return false; - } - } else if (flush == Z_FINISH) { - switch (r) { - case Z_OK: - case Z_BUF_ERROR: - /* Wait for the next loop to assign additional output space. */ - GPR_ASSERT(ctx->zs.avail_out == 0); - break; - case Z_STREAM_END: - flush = 0; - break; - default: - gpr_log(GPR_ERROR, "zlib error (%d)", r); - grpc_slice_unref_internal(&exec_ctx, slice_out); - grpc_exec_ctx_finish(&exec_ctx); - return false; - } - } - } - - if (ctx->zs.avail_out == 0) { - grpc_slice_buffer_add(out, slice_out); - } else if (ctx->zs.avail_out < slice_size) { - slice_out.data.refcounted.length -= ctx->zs.avail_out; - grpc_slice_buffer_add(out, slice_out); - } else { - grpc_slice_unref_internal(&exec_ctx, slice_out); - } - max_output_size -= (slice_size - ctx->zs.avail_out); - } - grpc_exec_ctx_finish(&exec_ctx); - if (end_of_context) { - *end_of_context = eoc; - } - if (output_size) { - *output_size = original_max_output_size - max_output_size; - } - return true; -} - -static bool grpc_stream_compress_gzip(grpc_stream_compression_context *ctx, - grpc_slice_buffer *in, - grpc_slice_buffer *out, - size_t *output_size, - size_t max_output_size, - grpc_stream_compression_flush flush) { - if (ctx == NULL) { - return false; - } - grpc_stream_compression_context_gzip *gzip_ctx = - (grpc_stream_compression_context_gzip *)ctx; - GPR_ASSERT(gzip_ctx->flate == deflate); - int gzip_flush; - switch (flush) { - case GRPC_STREAM_COMPRESSION_FLUSH_NONE: - gzip_flush = 0; - break; - case GRPC_STREAM_COMPRESSION_FLUSH_SYNC: - gzip_flush = Z_SYNC_FLUSH; - break; - case GRPC_STREAM_COMPRESSION_FLUSH_FINISH: - gzip_flush = Z_FINISH; - break; - default: - gzip_flush = 0; - } - return gzip_flate(gzip_ctx, in, out, output_size, max_output_size, gzip_flush, - NULL); -} - -static bool grpc_stream_decompress_gzip(grpc_stream_compression_context *ctx, - grpc_slice_buffer *in, - grpc_slice_buffer *out, - size_t *output_size, - size_t max_output_size, - bool *end_of_context) { - if (ctx == NULL) { - return false; - } - grpc_stream_compression_context_gzip *gzip_ctx = - (grpc_stream_compression_context_gzip *)ctx; - GPR_ASSERT(gzip_ctx->flate == inflate); - return gzip_flate(gzip_ctx, in, out, output_size, max_output_size, - Z_SYNC_FLUSH, end_of_context); -} - -static grpc_stream_compression_context * -grpc_stream_compression_context_create_gzip( - grpc_stream_compression_method method) { - 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 *)gpr_zalloc( - sizeof(grpc_stream_compression_context_gzip)); - int r; - if (gzip_ctx == NULL) { - return NULL; - } - if (method == GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS) { - r = inflateInit2(&gzip_ctx->zs, 0x1F); - gzip_ctx->flate = inflate; - } else { - r = deflateInit2(&gzip_ctx->zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 0x1F, 8, - Z_DEFAULT_STRATEGY); - gzip_ctx->flate = deflate; - } - if (r != Z_OK) { - gpr_free(gzip_ctx); - return NULL; - } - - gzip_ctx->base.vtable = &grpc_stream_compression_gzip_vtable; - return (grpc_stream_compression_context *)gzip_ctx; -} - -static void grpc_stream_compression_context_destroy_gzip( - grpc_stream_compression_context *ctx) { - if (ctx == NULL) { - return; - } - grpc_stream_compression_context_gzip *gzip_ctx = - (grpc_stream_compression_context_gzip *)ctx; - if (gzip_ctx->flate == inflate) { - inflateEnd(&gzip_ctx->zs); - } else { - deflateEnd(&gzip_ctx->zs); - } - gpr_free(ctx); -} - -const grpc_stream_compression_vtable grpc_stream_compression_gzip_vtable = { - grpc_stream_compress_gzip, grpc_stream_decompress_gzip, - grpc_stream_compression_context_create_gzip, - grpc_stream_compression_context_destroy_gzip}; diff --git a/src/core/lib/compression/stream_compression_gzip.cc b/src/core/lib/compression/stream_compression_gzip.cc new file mode 100644 index 0000000000..087b018be5 --- /dev/null +++ b/src/core/lib/compression/stream_compression_gzip.cc @@ -0,0 +1,227 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include "src/core/lib/compression/stream_compression_gzip.h" +#include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/slice/slice_internal.h" + +#define OUTPUT_BLOCK_SIZE (1024) + +typedef struct grpc_stream_compression_context_gzip { + grpc_stream_compression_context base; + + z_stream zs; + int (*flate)(z_stream *zs, int flush); +} grpc_stream_compression_context_gzip; + +static bool gzip_flate(grpc_stream_compression_context_gzip *ctx, + grpc_slice_buffer *in, grpc_slice_buffer *out, + size_t *output_size, size_t max_output_size, int flush, + bool *end_of_context) { + GPR_ASSERT(flush == 0 || flush == Z_SYNC_FLUSH || flush == Z_FINISH); + /* Full flush is not allowed when inflating. */ + GPR_ASSERT(!(ctx->flate == inflate && (flush == Z_FINISH))); + + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + int r; + bool eoc = false; + size_t original_max_output_size = max_output_size; + while (max_output_size > 0 && (in->length > 0 || flush) && !eoc) { + size_t slice_size = max_output_size < OUTPUT_BLOCK_SIZE ? max_output_size + : OUTPUT_BLOCK_SIZE; + grpc_slice slice_out = GRPC_SLICE_MALLOC(slice_size); + ctx->zs.avail_out = (uInt)slice_size; + ctx->zs.next_out = GRPC_SLICE_START_PTR(slice_out); + while (ctx->zs.avail_out > 0 && in->length > 0 && !eoc) { + grpc_slice slice = grpc_slice_buffer_take_first(in); + ctx->zs.avail_in = (uInt)GRPC_SLICE_LENGTH(slice); + ctx->zs.next_in = GRPC_SLICE_START_PTR(slice); + r = ctx->flate(&ctx->zs, Z_NO_FLUSH); + if (r < 0 && r != Z_BUF_ERROR) { + gpr_log(GPR_ERROR, "zlib error (%d)", r); + grpc_slice_unref_internal(&exec_ctx, slice_out); + grpc_exec_ctx_finish(&exec_ctx); + return false; + } else if (r == Z_STREAM_END && ctx->flate == inflate) { + eoc = true; + } + if (ctx->zs.avail_in > 0) { + grpc_slice_buffer_undo_take_first( + in, + grpc_slice_sub(slice, GRPC_SLICE_LENGTH(slice) - ctx->zs.avail_in, + GRPC_SLICE_LENGTH(slice))); + } + grpc_slice_unref_internal(&exec_ctx, slice); + } + if (flush != 0 && ctx->zs.avail_out > 0 && !eoc) { + GPR_ASSERT(in->length == 0); + r = ctx->flate(&ctx->zs, flush); + if (flush == Z_SYNC_FLUSH) { + switch (r) { + case Z_OK: + /* Maybe flush is not complete; just made some partial progress. */ + if (ctx->zs.avail_out > 0) { + flush = 0; + } + break; + case Z_BUF_ERROR: + case Z_STREAM_END: + flush = 0; + break; + default: + gpr_log(GPR_ERROR, "zlib error (%d)", r); + grpc_slice_unref_internal(&exec_ctx, slice_out); + grpc_exec_ctx_finish(&exec_ctx); + return false; + } + } else if (flush == Z_FINISH) { + switch (r) { + case Z_OK: + case Z_BUF_ERROR: + /* Wait for the next loop to assign additional output space. */ + GPR_ASSERT(ctx->zs.avail_out == 0); + break; + case Z_STREAM_END: + flush = 0; + break; + default: + gpr_log(GPR_ERROR, "zlib error (%d)", r); + grpc_slice_unref_internal(&exec_ctx, slice_out); + grpc_exec_ctx_finish(&exec_ctx); + return false; + } + } + } + + if (ctx->zs.avail_out == 0) { + grpc_slice_buffer_add(out, slice_out); + } else if (ctx->zs.avail_out < slice_size) { + slice_out.data.refcounted.length -= ctx->zs.avail_out; + grpc_slice_buffer_add(out, slice_out); + } else { + grpc_slice_unref_internal(&exec_ctx, slice_out); + } + max_output_size -= (slice_size - ctx->zs.avail_out); + } + grpc_exec_ctx_finish(&exec_ctx); + if (end_of_context) { + *end_of_context = eoc; + } + if (output_size) { + *output_size = original_max_output_size - max_output_size; + } + return true; +} + +static bool grpc_stream_compress_gzip(grpc_stream_compression_context *ctx, + grpc_slice_buffer *in, + grpc_slice_buffer *out, + size_t *output_size, + size_t max_output_size, + grpc_stream_compression_flush flush) { + if (ctx == NULL) { + return false; + } + grpc_stream_compression_context_gzip *gzip_ctx = + (grpc_stream_compression_context_gzip *)ctx; + GPR_ASSERT(gzip_ctx->flate == deflate); + int gzip_flush; + switch (flush) { + case GRPC_STREAM_COMPRESSION_FLUSH_NONE: + gzip_flush = 0; + break; + case GRPC_STREAM_COMPRESSION_FLUSH_SYNC: + gzip_flush = Z_SYNC_FLUSH; + break; + case GRPC_STREAM_COMPRESSION_FLUSH_FINISH: + gzip_flush = Z_FINISH; + break; + default: + gzip_flush = 0; + } + return gzip_flate(gzip_ctx, in, out, output_size, max_output_size, gzip_flush, + NULL); +} + +static bool grpc_stream_decompress_gzip(grpc_stream_compression_context *ctx, + grpc_slice_buffer *in, + grpc_slice_buffer *out, + size_t *output_size, + size_t max_output_size, + bool *end_of_context) { + if (ctx == NULL) { + return false; + } + grpc_stream_compression_context_gzip *gzip_ctx = + (grpc_stream_compression_context_gzip *)ctx; + GPR_ASSERT(gzip_ctx->flate == inflate); + return gzip_flate(gzip_ctx, in, out, output_size, max_output_size, + Z_SYNC_FLUSH, end_of_context); +} + +static grpc_stream_compression_context * +grpc_stream_compression_context_create_gzip( + grpc_stream_compression_method method) { + 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 *)gpr_zalloc( + sizeof(grpc_stream_compression_context_gzip)); + int r; + if (gzip_ctx == NULL) { + return NULL; + } + if (method == GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS) { + r = inflateInit2(&gzip_ctx->zs, 0x1F); + gzip_ctx->flate = inflate; + } else { + r = deflateInit2(&gzip_ctx->zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 0x1F, 8, + Z_DEFAULT_STRATEGY); + gzip_ctx->flate = deflate; + } + if (r != Z_OK) { + gpr_free(gzip_ctx); + return NULL; + } + + gzip_ctx->base.vtable = &grpc_stream_compression_gzip_vtable; + return (grpc_stream_compression_context *)gzip_ctx; +} + +static void grpc_stream_compression_context_destroy_gzip( + grpc_stream_compression_context *ctx) { + if (ctx == NULL) { + return; + } + grpc_stream_compression_context_gzip *gzip_ctx = + (grpc_stream_compression_context_gzip *)ctx; + if (gzip_ctx->flate == inflate) { + inflateEnd(&gzip_ctx->zs); + } else { + deflateEnd(&gzip_ctx->zs); + } + gpr_free(ctx); +} + +const grpc_stream_compression_vtable grpc_stream_compression_gzip_vtable = { + grpc_stream_compress_gzip, grpc_stream_decompress_gzip, + grpc_stream_compression_context_create_gzip, + grpc_stream_compression_context_destroy_gzip}; diff --git a/src/core/lib/compression/stream_compression_gzip.h b/src/core/lib/compression/stream_compression_gzip.h index 7cf49a0de9..a3f1b0406f 100644 --- a/src/core/lib/compression/stream_compression_gzip.h +++ b/src/core/lib/compression/stream_compression_gzip.h @@ -21,6 +21,14 @@ #include "src/core/lib/compression/stream_compression.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const grpc_stream_compression_vtable grpc_stream_compression_gzip_vtable; +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/core/lib/compression/stream_compression_identity.c b/src/core/lib/compression/stream_compression_identity.c deleted file mode 100644 index 9b2e6062e1..0000000000 --- a/src/core/lib/compression/stream_compression_identity.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include "src/core/lib/compression/stream_compression_identity.h" -#include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/slice/slice_internal.h" - -#define OUTPUT_BLOCK_SIZE (1024) - -/* Singleton context used for all identity streams. */ -static grpc_stream_compression_context identity_ctx = { - &grpc_stream_compression_identity_vtable}; - -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 (output_size) { - *output_size = in->length; - } - grpc_slice_buffer_move_into(in, out); - } else { - if (output_size) { - *output_size = max_output_size; - } - grpc_slice_buffer_move_first(in, max_output_size, out); - } -} - -static bool grpc_stream_compress_identity(grpc_stream_compression_context *ctx, - grpc_slice_buffer *in, - grpc_slice_buffer *out, - size_t *output_size, - size_t max_output_size, - grpc_stream_compression_flush flush) { - if (ctx == NULL) { - return false; - } - grpc_stream_compression_pass_through(in, out, output_size, max_output_size); - return true; -} - -static bool grpc_stream_decompress_identity( - grpc_stream_compression_context *ctx, grpc_slice_buffer *in, - grpc_slice_buffer *out, size_t *output_size, size_t max_output_size, - bool *end_of_context) { - if (ctx == NULL) { - return false; - } - grpc_stream_compression_pass_through(in, out, output_size, max_output_size); - if (end_of_context) { - *end_of_context = false; - } - return true; -} - -static grpc_stream_compression_context * -grpc_stream_compression_context_create_identity( - grpc_stream_compression_method method) { - GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS || - method == GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS); - /* No context needed in this case. Use fake context instead. */ - return (grpc_stream_compression_context *)&identity_ctx; -} - -static void grpc_stream_compression_context_destroy_identity( - grpc_stream_compression_context *ctx) { - return; -} - -const grpc_stream_compression_vtable grpc_stream_compression_identity_vtable = { - grpc_stream_compress_identity, grpc_stream_decompress_identity, - grpc_stream_compression_context_create_identity, - grpc_stream_compression_context_destroy_identity}; diff --git a/src/core/lib/compression/stream_compression_identity.cc b/src/core/lib/compression/stream_compression_identity.cc new file mode 100644 index 0000000000..9b2e6062e1 --- /dev/null +++ b/src/core/lib/compression/stream_compression_identity.cc @@ -0,0 +1,93 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include "src/core/lib/compression/stream_compression_identity.h" +#include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/slice/slice_internal.h" + +#define OUTPUT_BLOCK_SIZE (1024) + +/* Singleton context used for all identity streams. */ +static grpc_stream_compression_context identity_ctx = { + &grpc_stream_compression_identity_vtable}; + +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 (output_size) { + *output_size = in->length; + } + grpc_slice_buffer_move_into(in, out); + } else { + if (output_size) { + *output_size = max_output_size; + } + grpc_slice_buffer_move_first(in, max_output_size, out); + } +} + +static bool grpc_stream_compress_identity(grpc_stream_compression_context *ctx, + grpc_slice_buffer *in, + grpc_slice_buffer *out, + size_t *output_size, + size_t max_output_size, + grpc_stream_compression_flush flush) { + if (ctx == NULL) { + return false; + } + grpc_stream_compression_pass_through(in, out, output_size, max_output_size); + return true; +} + +static bool grpc_stream_decompress_identity( + grpc_stream_compression_context *ctx, grpc_slice_buffer *in, + grpc_slice_buffer *out, size_t *output_size, size_t max_output_size, + bool *end_of_context) { + if (ctx == NULL) { + return false; + } + grpc_stream_compression_pass_through(in, out, output_size, max_output_size); + if (end_of_context) { + *end_of_context = false; + } + return true; +} + +static grpc_stream_compression_context * +grpc_stream_compression_context_create_identity( + grpc_stream_compression_method method) { + GPR_ASSERT(method == GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS || + method == GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS); + /* No context needed in this case. Use fake context instead. */ + return (grpc_stream_compression_context *)&identity_ctx; +} + +static void grpc_stream_compression_context_destroy_identity( + grpc_stream_compression_context *ctx) { + return; +} + +const grpc_stream_compression_vtable grpc_stream_compression_identity_vtable = { + grpc_stream_compress_identity, grpc_stream_decompress_identity, + grpc_stream_compression_context_create_identity, + grpc_stream_compression_context_destroy_identity}; diff --git a/src/core/lib/compression/stream_compression_identity.h b/src/core/lib/compression/stream_compression_identity.h index 41926e949e..3a729fafad 100644 --- a/src/core/lib/compression/stream_compression_identity.h +++ b/src/core/lib/compression/stream_compression_identity.h @@ -21,7 +21,15 @@ #include "src/core/lib/compression/stream_compression.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const grpc_stream_compression_vtable grpc_stream_compression_identity_vtable; +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 28dab00117..cf5bafbd04 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -24,6 +24,10 @@ #include #include "src/core/lib/iomgr/exec_ctx.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED, GRPC_STATS_COUNTER_SERVER_CALLS_CREATED, @@ -467,4 +471,8 @@ extern const int *const grpc_stats_histo_bucket_boundaries[13]; extern void (*const grpc_stats_inc_histogram[13])(grpc_exec_ctx *exec_ctx, int x); +#ifdef __cplusplus +} +#endif + #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ diff --git a/src/core/lib/iomgr/gethostname.h b/src/core/lib/iomgr/gethostname.h index c0a4c7e6df..f335fea586 100644 --- a/src/core/lib/iomgr/gethostname.h +++ b/src/core/lib/iomgr/gethostname.h @@ -31,5 +31,4 @@ char *grpc_gethostname(); } #endif - #endif /* GRPC_CORE_LIB_IOMGR_GETHOSTNAME_H */ diff --git a/src/core/lib/iomgr/gethostname_fallback.cc b/src/core/lib/iomgr/gethostname_fallback.cc index 31dff5812c..e6f4c2f760 100644 --- a/src/core/lib/iomgr/gethostname_fallback.cc +++ b/src/core/lib/iomgr/gethostname_fallback.cc @@ -16,8 +16,8 @@ * */ -#include "src/core/lib/iomgr/port.h" #include "src/core/lib/iomgr/gethostname.h" +#include "src/core/lib/iomgr/port.h" #ifdef GRPC_GETHOSTNAME_FALLBACK diff --git a/src/core/lib/iomgr/gethostname_host_name_max.cc b/src/core/lib/iomgr/gethostname_host_name_max.cc index 9be319dab8..cdaf097c3e 100644 --- a/src/core/lib/iomgr/gethostname_host_name_max.cc +++ b/src/core/lib/iomgr/gethostname_host_name_max.cc @@ -16,8 +16,8 @@ * */ -#include "src/core/lib/iomgr/port.h" #include "src/core/lib/iomgr/gethostname.h" +#include "src/core/lib/iomgr/port.h" #ifdef GRPC_POSIX_HOST_NAME_MAX diff --git a/src/core/lib/iomgr/gethostname_sysconf.cc b/src/core/lib/iomgr/gethostname_sysconf.cc index 4cc7ebf4c0..8441e0615e 100644 --- a/src/core/lib/iomgr/gethostname_sysconf.cc +++ b/src/core/lib/iomgr/gethostname_sysconf.cc @@ -16,8 +16,8 @@ * */ -#include "src/core/lib/iomgr/port.h" #include "src/core/lib/iomgr/gethostname.h" +#include "src/core/lib/iomgr/port.h" #ifdef GRPC_POSIX_SYSCONF diff --git a/src/core/lib/iomgr/socket_utils_windows.cc b/src/core/lib/iomgr/socket_utils_windows.cc index 2732c159aa..6e85e4b61f 100644 --- a/src/core/lib/iomgr/socket_utils_windows.cc +++ b/src/core/lib/iomgr/socket_utils_windows.cc @@ -26,12 +26,8 @@ #include const char *grpc_inet_ntop(int af, const void *src, char *dst, size_t size) { -#ifdef GPR_WIN_INET_NTOP - return inet_ntop(af, src, dst, size); -#else /* Windows InetNtopA wants a mutable ip pointer */ return InetNtopA(af, (void *)src, dst, size); -#endif /* GPR_WIN_INET_NTOP */ } #endif /* GRPC_WINDOWS_SOCKETUTILS */ diff --git a/src/core/lib/iomgr/tcp_client_uv.cc b/src/core/lib/iomgr/tcp_client_uv.cc index 274366b356..b2c80d52c6 100644 --- a/src/core/lib/iomgr/tcp_client_uv.cc +++ b/src/core/lib/iomgr/tcp_client_uv.cc @@ -131,16 +131,16 @@ static void tcp_client_connect_impl(grpc_exec_ctx *exec_ctx, for (size_t i = 0; i < channel_args->num_args; i++) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { grpc_resource_quota_unref_internal(exec_ctx, resource_quota); - resource_quota = grpc_resource_quota_ref_internal((grpc_resource_quota *) - channel_args->args[i].value.pointer.p); + resource_quota = grpc_resource_quota_ref_internal( + (grpc_resource_quota *)channel_args->args[i].value.pointer.p); } } } - connect = (grpc_uv_tcp_connect*)gpr_zalloc(sizeof(grpc_uv_tcp_connect)); + connect = (grpc_uv_tcp_connect *)gpr_zalloc(sizeof(grpc_uv_tcp_connect)); connect->closure = closure; connect->endpoint = ep; - connect->tcp_handle = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t)); + connect->tcp_handle = (uv_tcp_t *)gpr_malloc(sizeof(uv_tcp_t)); connect->addr_name = grpc_sockaddr_to_uri(resolved_addr); connect->resource_quota = resource_quota; uv_tcp_init(uv_default_loop(), connect->tcp_handle); diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 2955d16be6..7b9fd6424d 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -72,6 +72,8 @@ CORE_SOURCE_FILES = [ 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/message_compress.cc', 'src/core/lib/compression/stream_compression.cc', + 'src/core/lib/compression/stream_compression_gzip.cc', + 'src/core/lib/compression/stream_compression_identity.cc', 'src/core/lib/debug/stats.cc', 'src/core/lib/debug/stats_data.cc', 'src/core/lib/http/format_request.cc', diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 2717fa836d..072a677615 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -208,6 +208,10 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "#include " print >>H, "#include \"src/core/lib/iomgr/exec_ctx.h\"" print >>H + print >>H, "#ifdef __cplusplus" + print >>H, "extern \"C\" {" + print >>H, "#endif" + print >>H for typename, instances in sorted(inst_map.items()): print >>H, "typedef enum {" @@ -252,6 +256,10 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "extern const int *const grpc_stats_histo_bucket_boundaries[%d];" % len(inst_map['Histogram']) print >>H, "extern void (*const grpc_stats_inc_histogram[%d])(grpc_exec_ctx *exec_ctx, int x);" % len(inst_map['Histogram']) + print >>H + print >>H, "#ifdef __cplusplus" + print >>H, "}" + print >>H, "#endif" print >>H print >>H, "#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */" diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index d4c645e728..ee593e3ea0 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1078,7 +1078,9 @@ src/core/lib/compression/message_compress.cc \ src/core/lib/compression/message_compress.h \ src/core/lib/compression/stream_compression.cc \ src/core/lib/compression/stream_compression.h \ +src/core/lib/compression/stream_compression_gzip.cc \ src/core/lib/compression/stream_compression_gzip.h \ +src/core/lib/compression/stream_compression_identity.cc \ src/core/lib/compression/stream_compression_identity.h \ src/core/lib/debug/stats.cc \ src/core/lib/debug/stats.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index b23c5d7bc9..95556b2e6f 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -8007,6 +8007,8 @@ "src/core/lib/compression/compression.cc", "src/core/lib/compression/message_compress.cc", "src/core/lib/compression/stream_compression.cc", + "src/core/lib/compression/stream_compression_gzip.cc", + "src/core/lib/compression/stream_compression_identity.cc", "src/core/lib/debug/stats.cc", "src/core/lib/debug/stats_data.cc", "src/core/lib/http/format_request.cc", -- cgit v1.2.3