diff options
author | Muxi Yan <mxyan@google.com> | 2018-01-19 12:20:15 -0800 |
---|---|---|
committer | Muxi Yan <mxyan@google.com> | 2018-01-19 12:20:15 -0800 |
commit | fb061c329ac5086b62619b118191574f3fd27a79 (patch) | |
tree | 6a855770d7218425a2cd53bc378800c30d6c8525 /include | |
parent | 032e9b32dc5978a042bdda5c3031ae6cbd928973 (diff) | |
parent | 9813858908da2e7deaa58d91f4030e6881e364e3 (diff) |
Merge remote-tracking branch 'upstream/master' into fix-stream-compression-config-interface
Diffstat (limited to 'include')
-rw-r--r-- | include/grpc++/impl/codegen/client_unary_call.h | 1 | ||||
-rw-r--r-- | include/grpc++/impl/codegen/method_handler_impl.h | 37 | ||||
-rw-r--r-- | include/grpc/impl/codegen/exec_ctx_fwd.h | 26 | ||||
-rw-r--r-- | include/grpc/impl/codegen/grpc_types.h | 1 | ||||
-rw-r--r-- | include/grpc/impl/codegen/port_platform.h | 49 | ||||
-rw-r--r-- | include/grpc/impl/codegen/slice.h | 1 | ||||
-rw-r--r-- | include/grpc/module.modulemap | 1 |
7 files changed, 78 insertions, 38 deletions
diff --git a/include/grpc++/impl/codegen/client_unary_call.h b/include/grpc++/impl/codegen/client_unary_call.h index 256dd859d3..543e54b972 100644 --- a/include/grpc++/impl/codegen/client_unary_call.h +++ b/include/grpc++/impl/codegen/client_unary_call.h @@ -65,6 +65,7 @@ class BlockingUnaryCallImpl { context->initial_metadata_flags()); ops.RecvInitialMetadata(context); ops.RecvMessage(result); + ops.AllowNoMessage(); ops.ClientSendClose(); ops.ClientRecvStatus(context, &status_); call.PerformOps(&ops); diff --git a/include/grpc++/impl/codegen/method_handler_impl.h b/include/grpc++/impl/codegen/method_handler_impl.h index c0af4ca130..daf090f86c 100644 --- a/include/grpc++/impl/codegen/method_handler_impl.h +++ b/include/grpc++/impl/codegen/method_handler_impl.h @@ -27,6 +27,27 @@ namespace grpc { namespace internal { + +// Invoke the method handler, fill in the status, and +// return whether or not we finished safely (without an exception). +// Note that exception handling is 0-cost in most compiler/library +// implementations (except when an exception is actually thrown), +// so this process doesn't require additional overhead in the common case. +// Additionally, we don't need to return if we caught an exception or not; +// the handling is the same in either case. +template <class Callable> +Status CatchingFunctionHandler(Callable&& handler) { +#if GRPC_ALLOW_EXCEPTIONS + try { + return handler(); + } catch (...) { + return Status(StatusCode::UNKNOWN, "Unexpected error in RPC handling"); + } +#else // GRPC_ALLOW_EXCEPTIONS + return handler(); +#endif // GRPC_ALLOW_EXCEPTIONS +} + /// A wrapper class of an application provided rpc method handler. template <class ServiceType, class RequestType, class ResponseType> class RpcMethodHandler : public MethodHandler { @@ -43,7 +64,9 @@ class RpcMethodHandler : public MethodHandler { param.request.bbuf_ptr(), &req); ResponseType rsp; if (status.ok()) { - status = func_(service_, param.server_context, &req, &rsp); + status = CatchingFunctionHandler([this, ¶m, &req, &rsp] { + return func_(service_, param.server_context, &req, &rsp); + }); } GPR_CODEGEN_ASSERT(!param.server_context->sent_initial_metadata_); @@ -86,7 +109,9 @@ class ClientStreamingHandler : public MethodHandler { void RunHandler(const HandlerParameter& param) final { ServerReader<RequestType> reader(param.call, param.server_context); ResponseType rsp; - Status status = func_(service_, param.server_context, &reader, &rsp); + Status status = CatchingFunctionHandler([this, ¶m, &reader, &rsp] { + return func_(service_, param.server_context, &reader, &rsp); + }); GPR_CODEGEN_ASSERT(!param.server_context->sent_initial_metadata_); CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage, @@ -130,7 +155,9 @@ class ServerStreamingHandler : public MethodHandler { if (status.ok()) { ServerWriter<ResponseType> writer(param.call, param.server_context); - status = func_(service_, param.server_context, &req, &writer); + status = CatchingFunctionHandler([this, ¶m, &req, &writer] { + return func_(service_, param.server_context, &req, &writer); + }); } CallOpSet<CallOpSendInitialMetadata, CallOpServerSendStatus> ops; @@ -172,7 +199,9 @@ class TemplatedBidiStreamingHandler : public MethodHandler { void RunHandler(const HandlerParameter& param) final { Streamer stream(param.call, param.server_context); - Status status = func_(param.server_context, &stream); + Status status = CatchingFunctionHandler([this, ¶m, &stream] { + return func_(param.server_context, &stream); + }); CallOpSet<CallOpSendInitialMetadata, CallOpServerSendStatus> ops; if (!param.server_context->sent_initial_metadata_) { diff --git a/include/grpc/impl/codegen/exec_ctx_fwd.h b/include/grpc/impl/codegen/exec_ctx_fwd.h deleted file mode 100644 index 005ff14e7e..0000000000 --- a/include/grpc/impl/codegen/exec_ctx_fwd.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * Copyright 2016 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. - * - */ - -#ifndef GRPC_IMPL_CODEGEN_EXEC_CTX_FWD_H -#define GRPC_IMPL_CODEGEN_EXEC_CTX_FWD_H - -/* forward declaration for exec_ctx.h */ -struct grpc_exec_ctx; -typedef struct grpc_exec_ctx grpc_exec_ctx; - -#endif /* GRPC_IMPL_CODEGEN_EXEC_CTX_FWD_H */ diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 9cad9becf0..e5aa29b88a 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -22,7 +22,6 @@ #include <grpc/impl/codegen/port_platform.h> #include <grpc/impl/codegen/compression_types.h> -#include <grpc/impl/codegen/exec_ctx_fwd.h> #include <grpc/impl/codegen/gpr_types.h> #include <grpc/impl/codegen/slice.h> #include <grpc/impl/codegen/status.h> diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index 5a0ed85111..819d17ce2a 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -195,12 +195,25 @@ #define GPR_PTHREAD_TLS 1 #else /* __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7 */ #define GPR_CPU_POSIX 1 +/* TODO(vjpai): there is a reported issue in bazel build for Mac where __thread + in a header is currently not working (bazelbuild/bazel#4341). Remove + the following conditional and use GPR_GCC_TLS when that is fixed */ +#ifndef GRPC_BAZEL_BUILD #define GPR_GCC_TLS 1 +#else /* GRPC_BAZEL_BUILD */ +#define GPR_PTHREAD_TLS 1 +#endif /* GRPC_BAZEL_BUILD */ #define GPR_APPLE_PTHREAD_NAME 1 #endif #else /* __MAC_OS_X_VERSION_MIN_REQUIRED */ #define GPR_CPU_POSIX 1 +/* TODO(vjpai): Remove the following conditional and use only GPR_GCC_TLS + when bazelbuild/bazel#4341 is fixed */ +#ifndef GRPC_BAZEL_BUILD #define GPR_GCC_TLS 1 +#else /* GRPC_BAZEL_BUILD */ +#define GPR_PTHREAD_TLS 1 +#endif /* GRPC_BAZEL_BUILD */ #endif #define GPR_POSIX_CRASH_HANDLER 1 #endif @@ -305,20 +318,23 @@ * This is primarily because of linker problems and toolchain misconfiguration: * TLS isn't supported until NDK r12b per * https://developer.android.com/ndk/downloads/revision_history.html + * TLS also does not work with Android NDK if GCC is being used as the compiler + * instead of Clang. * Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in * <android/ndk-version.h>. For NDK < r16, users should define these macros, * e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11. */ -#if defined(__ANDROID__) && defined(__clang__) && defined(GPR_GCC_TLS) +#if defined(__ANDROID__) && defined(GPR_GCC_TLS) #if __has_include(<android/ndk-version.h>) #include <android/ndk-version.h> #endif /* __has_include(<android/ndk-version.h>) */ -#if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \ - defined(__NDK_MINOR__) && \ - ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1))) +#if (defined(__clang__) && defined(__NDK_MAJOR__) && defined(__NDK_MINOR__) && \ + ((__NDK_MAJOR__ < 12) || \ + ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))) || \ + (defined(__GNUC__) && !defined(__clang__)) #undef GPR_GCC_TLS #define GPR_PTHREAD_TLS 1 #endif -#endif /*defined(__ANDROID__) && defined(__clang__) && defined(GPR_GCC_TLS) */ +#endif /*defined(__ANDROID__) && defined(GPR_GCC_TLS) */ #if defined(__has_include) #if __has_include(<atomic>) @@ -418,6 +434,14 @@ typedef unsigned __int64 uint64_t; #endif #endif +#ifndef GRPC_UNUSED +#if defined(__GNUC__) && !defined(__MINGW32__) +#define GRPC_UNUSED __attribute__((unused)) +#else +#define GRPC_UNUSED +#endif +#endif + #ifndef GPR_PRINT_FORMAT_CHECK #ifdef __GNUC__ #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \ @@ -461,6 +485,21 @@ typedef unsigned __int64 uint64_t; #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */ #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */ +/* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */ +#ifndef GRPC_ALLOW_EXCEPTIONS +/* If not already set, set to 1 on Windows (style guide standard) but to + * 0 on non-Windows platforms unless the compiler defines __EXCEPTIONS */ +#ifdef GPR_WINDOWS +#define GRPC_ALLOW_EXCEPTIONS 1 +#else /* GPR_WINDOWS */ +#ifdef __EXCEPTIONS +#define GRPC_ALLOW_EXCEPTIONS 1 +#else /* __EXCEPTIONS */ +#define GRPC_ALLOW_EXCEPTIONS 0 +#endif /* __EXCEPTIONS */ +#endif /* __GPR_WINDOWS */ +#endif /* GRPC_ALLOW_EXCEPTIONS */ + #ifndef __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS #endif diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index ad026b685e..a3cd1f1bbe 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -23,7 +23,6 @@ #include <stddef.h> -#include <grpc/impl/codegen/exec_ctx_fwd.h> #include <grpc/impl/codegen/gpr_slice.h> typedef struct grpc_slice grpc_slice; diff --git a/include/grpc/module.modulemap b/include/grpc/module.modulemap index 7b7b623dfd..d23072f556 100644 --- a/include/grpc/module.modulemap +++ b/include/grpc/module.modulemap @@ -30,7 +30,6 @@ framework module grpc { header "impl/codegen/byte_buffer_reader.h" header "impl/codegen/compression_types.h" header "impl/codegen/connectivity_state.h" - header "impl/codegen/exec_ctx_fwd.h" header "impl/codegen/grpc_types.h" header "impl/codegen/propagation_bits.h" header "impl/codegen/slice.h" |