diff options
author | neksard <neksard@yandex-team.ru> | 2022-02-10 16:45:33 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:33 +0300 |
commit | 1d9c550e7c38e051d7961f576013a482003a70d9 (patch) | |
tree | b2cc84ee7850122e7ccf51d0ea21e4fa7e7a5685 /contrib/libs/grpc/include/grpcpp/impl | |
parent | 8f7cf138264e0caa318144bf8a2c950e0b0a8593 (diff) | |
download | ydb-1d9c550e7c38e051d7961f576013a482003a70d9.tar.gz |
Restoring authorship annotation for <neksard@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/grpc/include/grpcpp/impl')
25 files changed, 2874 insertions, 2874 deletions
diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/async_generic_service.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/async_generic_service.h index cb82f446da..a812b086a2 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/async_generic_service.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/async_generic_service.h @@ -1,84 +1,84 @@ -/* - * - * Copyright 2015 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 GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H -#define GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H - +/* + * + * Copyright 2015 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 GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H +#define GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H + #include <grpc/impl/codegen/port_platform.h> #include <grpcpp/impl/codegen/async_stream.h> -#include <grpcpp/impl/codegen/byte_buffer.h> +#include <grpcpp/impl/codegen/byte_buffer.h> #include <grpcpp/impl/codegen/server_callback.h> #include <grpcpp/impl/codegen/server_callback_handlers.h> - -struct grpc_server; - -namespace grpc { - + +struct grpc_server; + +namespace grpc { + typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer> - GenericServerAsyncReaderWriter; + GenericServerAsyncReaderWriter; typedef ServerAsyncResponseWriter<ByteBuffer> GenericServerAsyncResponseWriter; typedef ServerAsyncReader<ByteBuffer, ByteBuffer> GenericServerAsyncReader; typedef ServerAsyncWriter<ByteBuffer> GenericServerAsyncWriter; - + class GenericServerContext final : public ServerContext { - public: + public: const TString& method() const { return method_; } const TString& host() const { return host_; } - - private: + + private: friend class ServerInterface; - + TString method_; TString host_; -}; - -// A generic service at the server side accepts all RPC methods and hosts. It is -// typically used in proxies. The generic service can be registered to a server -// which also has other services. -// Sample usage: -// ServerBuilder builder; -// auto cq = builder.AddCompletionQueue(); -// AsyncGenericService generic_service; -// builder.RegisterAsyncGenericService(&generic_service); -// auto server = builder.BuildAndStart(); -// -// // request a new call -// GenericServerContext context; -// GenericServerAsyncReaderWriter stream; -// generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag); -// -// When tag is retrieved from cq->Next(), context.method() can be used to look -// at the method and the RPC can be handled accordingly. -class AsyncGenericService final { - public: - AsyncGenericService() : server_(nullptr) {} - - void RequestCall(GenericServerContext* ctx, - GenericServerAsyncReaderWriter* reader_writer, +}; + +// A generic service at the server side accepts all RPC methods and hosts. It is +// typically used in proxies. The generic service can be registered to a server +// which also has other services. +// Sample usage: +// ServerBuilder builder; +// auto cq = builder.AddCompletionQueue(); +// AsyncGenericService generic_service; +// builder.RegisterAsyncGenericService(&generic_service); +// auto server = builder.BuildAndStart(); +// +// // request a new call +// GenericServerContext context; +// GenericServerAsyncReaderWriter stream; +// generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag); +// +// When tag is retrieved from cq->Next(), context.method() can be used to look +// at the method and the RPC can be handled accordingly. +class AsyncGenericService final { + public: + AsyncGenericService() : server_(nullptr) {} + + void RequestCall(GenericServerContext* ctx, + GenericServerAsyncReaderWriter* reader_writer, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag); - - private: + + private: friend class grpc::Server; grpc::Server* server_; -}; - +}; + #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL namespace experimental { #endif @@ -137,6 +137,6 @@ class CallbackGenericService { #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL } // namespace experimental #endif -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/byte_buffer.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/byte_buffer.h index 5b157cb43e..6e64ec9981 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/byte_buffer.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/byte_buffer.h @@ -54,7 +54,7 @@ class ExternalConnectionAcceptorImpl; template <class R> class DeserializeFuncType; class GrpcByteBufferPeer; - + } // namespace internal /// A sequence of bytes. class ByteBuffer final { @@ -89,9 +89,9 @@ class ByteBuffer final { } /// Constuct a byte buffer by referencing elements of existing buffer - /// \a buf. Wrapper of core function grpc_byte_buffer_copy . This is not - /// a deep copy; it is just a referencing. As a result, its performance is - /// size-independent. + /// \a buf. Wrapper of core function grpc_byte_buffer_copy . This is not + /// a deep copy; it is just a referencing. As a result, its performance is + /// size-independent. ByteBuffer(const ByteBuffer& buf) : buffer_(nullptr) { operator=(buf); } ~ByteBuffer() { @@ -100,9 +100,9 @@ class ByteBuffer final { } } - /// Wrapper of core function grpc_byte_buffer_copy . This is not - /// a deep copy; it is just a referencing. As a result, its performance is - /// size-independent. + /// Wrapper of core function grpc_byte_buffer_copy . This is not + /// a deep copy; it is just a referencing. As a result, its performance is + /// size-independent. ByteBuffer& operator=(const ByteBuffer& buf) { if (this != &buf) { Clear(); // first remove existing data @@ -127,9 +127,9 @@ class ByteBuffer final { /// Make a duplicate copy of the internals of this byte /// buffer so that we have our own owned version of it. - /// bbuf.Duplicate(); is equivalent to bbuf=bbuf; but is actually readable. - /// This is not a deep copy; it is a referencing and its performance - /// is size-independent. + /// bbuf.Duplicate(); is equivalent to bbuf=bbuf; but is actually readable. + /// This is not a deep copy; it is a referencing and its performance + /// is size-independent. void Duplicate() { buffer_ = g_core_codegen_interface->grpc_byte_buffer_copy(buffer_); } @@ -164,13 +164,13 @@ class ByteBuffer final { friend class internal::CallOpGenericRecvMessage; template <class ServiceType, class RequestType, class ResponseType> friend class internal::RpcMethodHandler; - template <class ServiceType, class RequestType, class ResponseType> + template <class ServiceType, class RequestType, class ResponseType> friend class internal::ServerStreamingHandler; - template <class RequestType, class ResponseType> + template <class RequestType, class ResponseType> friend class internal::CallbackUnaryHandler; - template <class RequestType, class ResponseType> + template <class RequestType, class ResponseType> friend class internal::CallbackServerStreamingHandler; - template <StatusCode code> + template <StatusCode code> friend class internal::ErrorMethodHandler; template <class R> friend class internal::DeserializeFuncType; diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h index eda6697777..b229286215 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h @@ -1,6 +1,6 @@ /* * - * Copyright 2018 gRPC authors. + * Copyright 2018 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,27 +18,27 @@ #ifndef GRPCPP_IMPL_CODEGEN_CALL_H #define GRPCPP_IMPL_CODEGEN_CALL_H -#include <grpc/impl/codegen/grpc_types.h> +#include <grpc/impl/codegen/grpc_types.h> #include <grpcpp/impl/codegen/call_hook.h> namespace grpc { class CompletionQueue; -namespace experimental { -class ClientRpcInfo; -class ServerRpcInfo; -} // namespace experimental +namespace experimental { +class ClientRpcInfo; +class ServerRpcInfo; +} // namespace experimental namespace internal { class CallHook; -class CallOpSetInterface; +class CallOpSetInterface; /// Straightforward wrapping of the C call object class Call final { public: - Call() - : call_hook_(nullptr), - cq_(nullptr), - call_(nullptr), - max_receive_message_size_(-1) {} + Call() + : call_hook_(nullptr), + cq_(nullptr), + call_(nullptr), + max_receive_message_size_(-1) {} /** call is owned by the caller */ Call(grpc_call* call, CallHook* call_hook, ::grpc::CompletionQueue* cq) : call_hook_(call_hook), @@ -47,21 +47,21 @@ class Call final { max_receive_message_size_(-1) {} Call(grpc_call* call, CallHook* call_hook, ::grpc::CompletionQueue* cq, - experimental::ClientRpcInfo* rpc_info) + experimental::ClientRpcInfo* rpc_info) : call_hook_(call_hook), cq_(cq), call_(call), - max_receive_message_size_(-1), - client_rpc_info_(rpc_info) {} + max_receive_message_size_(-1), + client_rpc_info_(rpc_info) {} Call(grpc_call* call, CallHook* call_hook, ::grpc::CompletionQueue* cq, - int max_receive_message_size, experimental::ServerRpcInfo* rpc_info) - : call_hook_(call_hook), - cq_(cq), - call_(call), - max_receive_message_size_(max_receive_message_size), - server_rpc_info_(rpc_info) {} - + int max_receive_message_size, experimental::ServerRpcInfo* rpc_info) + : call_hook_(call_hook), + cq_(cq), + call_(call), + max_receive_message_size_(max_receive_message_size), + server_rpc_info_(rpc_info) {} + void PerformOps(CallOpSetInterface* ops) { call_hook_->PerformOpsOnCall(ops, this); } @@ -71,21 +71,21 @@ class Call final { int max_receive_message_size() const { return max_receive_message_size_; } - experimental::ClientRpcInfo* client_rpc_info() const { - return client_rpc_info_; - } - - experimental::ServerRpcInfo* server_rpc_info() const { - return server_rpc_info_; - } - + experimental::ClientRpcInfo* client_rpc_info() const { + return client_rpc_info_; + } + + experimental::ServerRpcInfo* server_rpc_info() const { + return server_rpc_info_; + } + private: CallHook* call_hook_; ::grpc::CompletionQueue* cq_; grpc_call* call_; int max_receive_message_size_; - experimental::ClientRpcInfo* client_rpc_info_ = nullptr; - experimental::ServerRpcInfo* server_rpc_info_ = nullptr; + experimental::ClientRpcInfo* client_rpc_info_ = nullptr; + experimental::ServerRpcInfo* server_rpc_info_ = nullptr; }; } // namespace internal } // namespace grpc diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set.h index 21baa3ad19..379333164a 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set.h @@ -1,460 +1,460 @@ -/* - * - * Copyright 2018 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. - * - */ - -#if defined(__GNUC__) -#pragma GCC system_header -#endif - -#ifndef GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H -#define GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H - -#include <cstring> -#include <map> -#include <memory> - +/* + * + * Copyright 2018 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. + * + */ + +#if defined(__GNUC__) +#pragma GCC system_header +#endif + +#ifndef GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H +#define GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H + +#include <cstring> +#include <map> +#include <memory> + #include <grpc/impl/codegen/compression_types.h> #include <grpc/impl/codegen/grpc_types.h> -#include <grpcpp/impl/codegen/byte_buffer.h> -#include <grpcpp/impl/codegen/call.h> -#include <grpcpp/impl/codegen/call_hook.h> -#include <grpcpp/impl/codegen/call_op_set_interface.h> +#include <grpcpp/impl/codegen/byte_buffer.h> +#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/codegen/call_hook.h> +#include <grpcpp/impl/codegen/call_op_set_interface.h> #include <grpcpp/impl/codegen/client_context.h> #include <grpcpp/impl/codegen/completion_queue.h> -#include <grpcpp/impl/codegen/completion_queue_tag.h> -#include <grpcpp/impl/codegen/config.h> -#include <grpcpp/impl/codegen/core_codegen_interface.h> -#include <grpcpp/impl/codegen/intercepted_channel.h> -#include <grpcpp/impl/codegen/interceptor_common.h> -#include <grpcpp/impl/codegen/serialization_traits.h> -#include <grpcpp/impl/codegen/slice.h> -#include <grpcpp/impl/codegen/string_ref.h> - -namespace grpc { - -extern CoreCodegenInterface* g_core_codegen_interface; - -namespace internal { -class Call; -class CallHook; - -// TODO(yangg) if the map is changed before we send, the pointers will be a -// mess. Make sure it does not happen. -inline grpc_metadata* FillMetadataArray( +#include <grpcpp/impl/codegen/completion_queue_tag.h> +#include <grpcpp/impl/codegen/config.h> +#include <grpcpp/impl/codegen/core_codegen_interface.h> +#include <grpcpp/impl/codegen/intercepted_channel.h> +#include <grpcpp/impl/codegen/interceptor_common.h> +#include <grpcpp/impl/codegen/serialization_traits.h> +#include <grpcpp/impl/codegen/slice.h> +#include <grpcpp/impl/codegen/string_ref.h> + +namespace grpc { + +extern CoreCodegenInterface* g_core_codegen_interface; + +namespace internal { +class Call; +class CallHook; + +// TODO(yangg) if the map is changed before we send, the pointers will be a +// mess. Make sure it does not happen. +inline grpc_metadata* FillMetadataArray( const std::multimap<TString, TString>& metadata, size_t* metadata_count, const TString& optional_error_details) { - *metadata_count = metadata.size() + (optional_error_details.empty() ? 0 : 1); - if (*metadata_count == 0) { - return nullptr; - } - grpc_metadata* metadata_array = - (grpc_metadata*)(g_core_codegen_interface->gpr_malloc( - (*metadata_count) * sizeof(grpc_metadata))); - size_t i = 0; - for (auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) { - metadata_array[i].key = SliceReferencingString(iter->first); - metadata_array[i].value = SliceReferencingString(iter->second); - } - if (!optional_error_details.empty()) { - metadata_array[i].key = - g_core_codegen_interface->grpc_slice_from_static_buffer( - kBinaryErrorDetailsKey, sizeof(kBinaryErrorDetailsKey) - 1); - metadata_array[i].value = SliceReferencingString(optional_error_details); - } - return metadata_array; -} -} // namespace internal - -/// Per-message write options. -class WriteOptions { - public: - WriteOptions() : flags_(0), last_message_(false) {} - WriteOptions(const WriteOptions& other) - : flags_(other.flags_), last_message_(other.last_message_) {} - + *metadata_count = metadata.size() + (optional_error_details.empty() ? 0 : 1); + if (*metadata_count == 0) { + return nullptr; + } + grpc_metadata* metadata_array = + (grpc_metadata*)(g_core_codegen_interface->gpr_malloc( + (*metadata_count) * sizeof(grpc_metadata))); + size_t i = 0; + for (auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) { + metadata_array[i].key = SliceReferencingString(iter->first); + metadata_array[i].value = SliceReferencingString(iter->second); + } + if (!optional_error_details.empty()) { + metadata_array[i].key = + g_core_codegen_interface->grpc_slice_from_static_buffer( + kBinaryErrorDetailsKey, sizeof(kBinaryErrorDetailsKey) - 1); + metadata_array[i].value = SliceReferencingString(optional_error_details); + } + return metadata_array; +} +} // namespace internal + +/// Per-message write options. +class WriteOptions { + public: + WriteOptions() : flags_(0), last_message_(false) {} + WriteOptions(const WriteOptions& other) + : flags_(other.flags_), last_message_(other.last_message_) {} + /// Default assignment operator WriteOptions& operator=(const WriteOptions& other) = default; - /// Clear all flags. - inline void Clear() { flags_ = 0; } - - /// Returns raw flags bitset. - inline uint32_t flags() const { return flags_; } - - /// Sets flag for the disabling of compression for the next message write. - /// - /// \sa GRPC_WRITE_NO_COMPRESS - inline WriteOptions& set_no_compression() { - SetBit(GRPC_WRITE_NO_COMPRESS); - return *this; - } - - /// Clears flag for the disabling of compression for the next message write. - /// - /// \sa GRPC_WRITE_NO_COMPRESS - inline WriteOptions& clear_no_compression() { - ClearBit(GRPC_WRITE_NO_COMPRESS); - return *this; - } - - /// Get value for the flag indicating whether compression for the next - /// message write is forcefully disabled. - /// - /// \sa GRPC_WRITE_NO_COMPRESS - inline bool get_no_compression() const { - return GetBit(GRPC_WRITE_NO_COMPRESS); - } - - /// Sets flag indicating that the write may be buffered and need not go out on - /// the wire immediately. - /// - /// \sa GRPC_WRITE_BUFFER_HINT - inline WriteOptions& set_buffer_hint() { - SetBit(GRPC_WRITE_BUFFER_HINT); - return *this; - } - - /// Clears flag indicating that the write may be buffered and need not go out - /// on the wire immediately. - /// - /// \sa GRPC_WRITE_BUFFER_HINT - inline WriteOptions& clear_buffer_hint() { - ClearBit(GRPC_WRITE_BUFFER_HINT); - return *this; - } - - /// Get value for the flag indicating that the write may be buffered and need - /// not go out on the wire immediately. - /// - /// \sa GRPC_WRITE_BUFFER_HINT - inline bool get_buffer_hint() const { return GetBit(GRPC_WRITE_BUFFER_HINT); } - - /// corked bit: aliases set_buffer_hint currently, with the intent that - /// set_buffer_hint will be removed in the future - inline WriteOptions& set_corked() { - SetBit(GRPC_WRITE_BUFFER_HINT); - return *this; - } - - inline WriteOptions& clear_corked() { - ClearBit(GRPC_WRITE_BUFFER_HINT); - return *this; - } - - inline bool is_corked() const { return GetBit(GRPC_WRITE_BUFFER_HINT); } - - /// last-message bit: indicates this is the last message in a stream - /// client-side: makes Write the equivalent of performing Write, WritesDone - /// in a single step - /// server-side: hold the Write until the service handler returns (sync api) - /// or until Finish is called (async api) - inline WriteOptions& set_last_message() { - last_message_ = true; - return *this; - } - - /// Clears flag indicating that this is the last message in a stream, - /// disabling coalescing. - inline WriteOptions& clear_last_message() { - last_message_ = false; - return *this; - } - - /// Guarantee that all bytes have been written to the socket before completing - /// this write (usually writes are completed when they pass flow control). - inline WriteOptions& set_write_through() { - SetBit(GRPC_WRITE_THROUGH); - return *this; - } - - inline bool is_write_through() const { return GetBit(GRPC_WRITE_THROUGH); } - - /// Get value for the flag indicating that this is the last message, and - /// should be coalesced with trailing metadata. - /// - /// \sa GRPC_WRITE_LAST_MESSAGE - bool is_last_message() const { return last_message_; } - - private: - void SetBit(const uint32_t mask) { flags_ |= mask; } - - void ClearBit(const uint32_t mask) { flags_ &= ~mask; } - - bool GetBit(const uint32_t mask) const { return (flags_ & mask) != 0; } - - uint32_t flags_; - bool last_message_; -}; - -namespace internal { - + /// Clear all flags. + inline void Clear() { flags_ = 0; } + + /// Returns raw flags bitset. + inline uint32_t flags() const { return flags_; } + + /// Sets flag for the disabling of compression for the next message write. + /// + /// \sa GRPC_WRITE_NO_COMPRESS + inline WriteOptions& set_no_compression() { + SetBit(GRPC_WRITE_NO_COMPRESS); + return *this; + } + + /// Clears flag for the disabling of compression for the next message write. + /// + /// \sa GRPC_WRITE_NO_COMPRESS + inline WriteOptions& clear_no_compression() { + ClearBit(GRPC_WRITE_NO_COMPRESS); + return *this; + } + + /// Get value for the flag indicating whether compression for the next + /// message write is forcefully disabled. + /// + /// \sa GRPC_WRITE_NO_COMPRESS + inline bool get_no_compression() const { + return GetBit(GRPC_WRITE_NO_COMPRESS); + } + + /// Sets flag indicating that the write may be buffered and need not go out on + /// the wire immediately. + /// + /// \sa GRPC_WRITE_BUFFER_HINT + inline WriteOptions& set_buffer_hint() { + SetBit(GRPC_WRITE_BUFFER_HINT); + return *this; + } + + /// Clears flag indicating that the write may be buffered and need not go out + /// on the wire immediately. + /// + /// \sa GRPC_WRITE_BUFFER_HINT + inline WriteOptions& clear_buffer_hint() { + ClearBit(GRPC_WRITE_BUFFER_HINT); + return *this; + } + + /// Get value for the flag indicating that the write may be buffered and need + /// not go out on the wire immediately. + /// + /// \sa GRPC_WRITE_BUFFER_HINT + inline bool get_buffer_hint() const { return GetBit(GRPC_WRITE_BUFFER_HINT); } + + /// corked bit: aliases set_buffer_hint currently, with the intent that + /// set_buffer_hint will be removed in the future + inline WriteOptions& set_corked() { + SetBit(GRPC_WRITE_BUFFER_HINT); + return *this; + } + + inline WriteOptions& clear_corked() { + ClearBit(GRPC_WRITE_BUFFER_HINT); + return *this; + } + + inline bool is_corked() const { return GetBit(GRPC_WRITE_BUFFER_HINT); } + + /// last-message bit: indicates this is the last message in a stream + /// client-side: makes Write the equivalent of performing Write, WritesDone + /// in a single step + /// server-side: hold the Write until the service handler returns (sync api) + /// or until Finish is called (async api) + inline WriteOptions& set_last_message() { + last_message_ = true; + return *this; + } + + /// Clears flag indicating that this is the last message in a stream, + /// disabling coalescing. + inline WriteOptions& clear_last_message() { + last_message_ = false; + return *this; + } + + /// Guarantee that all bytes have been written to the socket before completing + /// this write (usually writes are completed when they pass flow control). + inline WriteOptions& set_write_through() { + SetBit(GRPC_WRITE_THROUGH); + return *this; + } + + inline bool is_write_through() const { return GetBit(GRPC_WRITE_THROUGH); } + + /// Get value for the flag indicating that this is the last message, and + /// should be coalesced with trailing metadata. + /// + /// \sa GRPC_WRITE_LAST_MESSAGE + bool is_last_message() const { return last_message_; } + + private: + void SetBit(const uint32_t mask) { flags_ |= mask; } + + void ClearBit(const uint32_t mask) { flags_ &= ~mask; } + + bool GetBit(const uint32_t mask) const { return (flags_ & mask) != 0; } + + uint32_t flags_; + bool last_message_; +}; + +namespace internal { + /// Default argument for CallOpSet. The Unused parameter is unused by /// the class, but can be used for generating multiple names for the /// same thing. template <int Unused> -class CallNoOp { - protected: +class CallNoOp { + protected: void AddOp(grpc_op* /*ops*/, size_t* /*nops*/) {} void FinishOp(bool* /*status*/) {} - void SetInterceptionHookPoint( + void SetInterceptionHookPoint( InterceptorBatchMethodsImpl* /*interceptor_methods*/) {} - void SetFinishInterceptionHookPoint( + void SetFinishInterceptionHookPoint( InterceptorBatchMethodsImpl* /*interceptor_methods*/) {} void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) { } -}; - -class CallOpSendInitialMetadata { - public: - CallOpSendInitialMetadata() : send_(false) { - maybe_compression_level_.is_set = false; - } - +}; + +class CallOpSendInitialMetadata { + public: + CallOpSendInitialMetadata() : send_(false) { + maybe_compression_level_.is_set = false; + } + void SendInitialMetadata(std::multimap<TString, TString>* metadata, - uint32_t flags) { - maybe_compression_level_.is_set = false; - send_ = true; - flags_ = flags; - metadata_map_ = metadata; - } - - void set_compression_level(grpc_compression_level level) { - maybe_compression_level_.is_set = true; - maybe_compression_level_.level = level; - } - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (!send_ || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->flags = flags_; - op->reserved = NULL; - initial_metadata_ = - FillMetadataArray(*metadata_map_, &initial_metadata_count_, ""); - op->data.send_initial_metadata.count = initial_metadata_count_; - op->data.send_initial_metadata.metadata = initial_metadata_; - op->data.send_initial_metadata.maybe_compression_level.is_set = - maybe_compression_level_.is_set; - if (maybe_compression_level_.is_set) { - op->data.send_initial_metadata.maybe_compression_level.level = - maybe_compression_level_.level; - } - } + uint32_t flags) { + maybe_compression_level_.is_set = false; + send_ = true; + flags_ = flags; + metadata_map_ = metadata; + } + + void set_compression_level(grpc_compression_level level) { + maybe_compression_level_.is_set = true; + maybe_compression_level_.level = level; + } + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (!send_ || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->flags = flags_; + op->reserved = NULL; + initial_metadata_ = + FillMetadataArray(*metadata_map_, &initial_metadata_count_, ""); + op->data.send_initial_metadata.count = initial_metadata_count_; + op->data.send_initial_metadata.metadata = initial_metadata_; + op->data.send_initial_metadata.maybe_compression_level.is_set = + maybe_compression_level_.is_set; + if (maybe_compression_level_.is_set) { + op->data.send_initial_metadata.maybe_compression_level.level = + maybe_compression_level_.level; + } + } void FinishOp(bool* /*status*/) { - if (!send_ || hijacked_) return; - g_core_codegen_interface->gpr_free(initial_metadata_); - send_ = false; - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (!send_) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA); - interceptor_methods->SetSendInitialMetadata(metadata_map_); - } - - void SetFinishInterceptionHookPoint( + if (!send_ || hijacked_) return; + g_core_codegen_interface->gpr_free(initial_metadata_); + send_ = false; + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (!send_) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA); + interceptor_methods->SetSendInitialMetadata(metadata_map_); + } + + void SetFinishInterceptionHookPoint( InterceptorBatchMethodsImpl* /*interceptor_methods*/) {} - + void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) { - hijacked_ = true; - } - - bool hijacked_ = false; - bool send_; - uint32_t flags_; - size_t initial_metadata_count_; + hijacked_ = true; + } + + bool hijacked_ = false; + bool send_; + uint32_t flags_; + size_t initial_metadata_count_; std::multimap<TString, TString>* metadata_map_; - grpc_metadata* initial_metadata_; - struct { - bool is_set; - grpc_compression_level level; - } maybe_compression_level_; -}; - -class CallOpSendMessage { - public: - CallOpSendMessage() : send_buf_() {} - - /// Send \a message using \a options for the write. The \a options are cleared - /// after use. - template <class M> - Status SendMessage(const M& message, - WriteOptions options) GRPC_MUST_USE_RESULT; - - template <class M> - Status SendMessage(const M& message) GRPC_MUST_USE_RESULT; - - /// Send \a message using \a options for the write. The \a options are cleared - /// after use. This form of SendMessage allows gRPC to reference \a message - /// beyond the lifetime of SendMessage. - template <class M> - Status SendMessagePtr(const M* message, - WriteOptions options) GRPC_MUST_USE_RESULT; - - /// This form of SendMessage allows gRPC to reference \a message beyond the - /// lifetime of SendMessage. - template <class M> - Status SendMessagePtr(const M* message) GRPC_MUST_USE_RESULT; - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (msg_ == nullptr && !send_buf_.Valid()) return; - if (hijacked_) { - serializer_ = nullptr; - return; - } - if (msg_ != nullptr) { - GPR_CODEGEN_ASSERT(serializer_(msg_).ok()); - } - serializer_ = nullptr; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_SEND_MESSAGE; - op->flags = write_options_.flags(); - op->reserved = NULL; - op->data.send_message.send_message = send_buf_.c_buffer(); - // Flags are per-message: clear them after use. - write_options_.Clear(); - } - void FinishOp(bool* status) { - if (msg_ == nullptr && !send_buf_.Valid()) return; - if (hijacked_ && failed_send_) { - // Hijacking interceptor failed this Op - *status = false; - } else if (!*status) { - // This Op was passed down to core and the Op failed - failed_send_ = true; - } - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (msg_ == nullptr && !send_buf_.Valid()) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_SEND_MESSAGE); - interceptor_methods->SetSendMessage(&send_buf_, &msg_, &failed_send_, - serializer_); - } - - void SetFinishInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (msg_ != nullptr || send_buf_.Valid()) { - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_SEND_MESSAGE); - } - send_buf_.Clear(); - msg_ = nullptr; - // The contents of the SendMessage value that was previously set - // has had its references stolen by core's operations - interceptor_methods->SetSendMessage(nullptr, nullptr, &failed_send_, - nullptr); - } - + grpc_metadata* initial_metadata_; + struct { + bool is_set; + grpc_compression_level level; + } maybe_compression_level_; +}; + +class CallOpSendMessage { + public: + CallOpSendMessage() : send_buf_() {} + + /// Send \a message using \a options for the write. The \a options are cleared + /// after use. + template <class M> + Status SendMessage(const M& message, + WriteOptions options) GRPC_MUST_USE_RESULT; + + template <class M> + Status SendMessage(const M& message) GRPC_MUST_USE_RESULT; + + /// Send \a message using \a options for the write. The \a options are cleared + /// after use. This form of SendMessage allows gRPC to reference \a message + /// beyond the lifetime of SendMessage. + template <class M> + Status SendMessagePtr(const M* message, + WriteOptions options) GRPC_MUST_USE_RESULT; + + /// This form of SendMessage allows gRPC to reference \a message beyond the + /// lifetime of SendMessage. + template <class M> + Status SendMessagePtr(const M* message) GRPC_MUST_USE_RESULT; + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (msg_ == nullptr && !send_buf_.Valid()) return; + if (hijacked_) { + serializer_ = nullptr; + return; + } + if (msg_ != nullptr) { + GPR_CODEGEN_ASSERT(serializer_(msg_).ok()); + } + serializer_ = nullptr; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_SEND_MESSAGE; + op->flags = write_options_.flags(); + op->reserved = NULL; + op->data.send_message.send_message = send_buf_.c_buffer(); + // Flags are per-message: clear them after use. + write_options_.Clear(); + } + void FinishOp(bool* status) { + if (msg_ == nullptr && !send_buf_.Valid()) return; + if (hijacked_ && failed_send_) { + // Hijacking interceptor failed this Op + *status = false; + } else if (!*status) { + // This Op was passed down to core and the Op failed + failed_send_ = true; + } + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (msg_ == nullptr && !send_buf_.Valid()) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_SEND_MESSAGE); + interceptor_methods->SetSendMessage(&send_buf_, &msg_, &failed_send_, + serializer_); + } + + void SetFinishInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (msg_ != nullptr || send_buf_.Valid()) { + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_SEND_MESSAGE); + } + send_buf_.Clear(); + msg_ = nullptr; + // The contents of the SendMessage value that was previously set + // has had its references stolen by core's operations + interceptor_methods->SetSendMessage(nullptr, nullptr, &failed_send_, + nullptr); + } + void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) { - hijacked_ = true; - } - - private: - const void* msg_ = nullptr; // The original non-serialized message - bool hijacked_ = false; - bool failed_send_ = false; - ByteBuffer send_buf_; - WriteOptions write_options_; - std::function<Status(const void*)> serializer_; -}; - -template <class M> -Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) { - write_options_ = options; - serializer_ = [this](const void* message) { - bool own_buf; - send_buf_.Clear(); - // TODO(vjpai): Remove the void below when possible - // The void in the template parameter below should not be needed - // (since it should be implicit) but is needed due to an observed - // difference in behavior between clang and gcc for certain internal users - Status result = SerializationTraits<M, void>::Serialize( - *static_cast<const M*>(message), send_buf_.bbuf_ptr(), &own_buf); - if (!own_buf) { - send_buf_.Duplicate(); - } - return result; - }; - // Serialize immediately only if we do not have access to the message pointer - if (msg_ == nullptr) { - Status result = serializer_(&message); - serializer_ = nullptr; - return result; - } - return Status(); -} - -template <class M> -Status CallOpSendMessage::SendMessage(const M& message) { - return SendMessage(message, WriteOptions()); -} - -template <class M> -Status CallOpSendMessage::SendMessagePtr(const M* message, - WriteOptions options) { - msg_ = message; - return SendMessage(*message, options); -} - -template <class M> -Status CallOpSendMessage::SendMessagePtr(const M* message) { - msg_ = message; - return SendMessage(*message, WriteOptions()); -} - -template <class R> -class CallOpRecvMessage { - public: - void RecvMessage(R* message) { message_ = message; } - - // Do not change status if no message is received. - void AllowNoMessage() { allow_not_getting_message_ = true; } - + hijacked_ = true; + } + + private: + const void* msg_ = nullptr; // The original non-serialized message + bool hijacked_ = false; + bool failed_send_ = false; + ByteBuffer send_buf_; + WriteOptions write_options_; + std::function<Status(const void*)> serializer_; +}; + +template <class M> +Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) { + write_options_ = options; + serializer_ = [this](const void* message) { + bool own_buf; + send_buf_.Clear(); + // TODO(vjpai): Remove the void below when possible + // The void in the template parameter below should not be needed + // (since it should be implicit) but is needed due to an observed + // difference in behavior between clang and gcc for certain internal users + Status result = SerializationTraits<M, void>::Serialize( + *static_cast<const M*>(message), send_buf_.bbuf_ptr(), &own_buf); + if (!own_buf) { + send_buf_.Duplicate(); + } + return result; + }; + // Serialize immediately only if we do not have access to the message pointer + if (msg_ == nullptr) { + Status result = serializer_(&message); + serializer_ = nullptr; + return result; + } + return Status(); +} + +template <class M> +Status CallOpSendMessage::SendMessage(const M& message) { + return SendMessage(message, WriteOptions()); +} + +template <class M> +Status CallOpSendMessage::SendMessagePtr(const M* message, + WriteOptions options) { + msg_ = message; + return SendMessage(*message, options); +} + +template <class M> +Status CallOpSendMessage::SendMessagePtr(const M* message) { + msg_ = message; + return SendMessage(*message, WriteOptions()); +} + +template <class R> +class CallOpRecvMessage { + public: + void RecvMessage(R* message) { message_ = message; } + + // Do not change status if no message is received. + void AllowNoMessage() { allow_not_getting_message_ = true; } + bool got_message = false; - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (message_ == nullptr || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_RECV_MESSAGE; - op->flags = 0; - op->reserved = NULL; - op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr(); - } - - void FinishOp(bool* status) { + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (message_ == nullptr || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_RECV_MESSAGE; + op->flags = 0; + op->reserved = NULL; + op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr(); + } + + void FinishOp(bool* status) { if (message_ == nullptr) return; - if (recv_buf_.Valid()) { - if (*status) { - got_message = *status = - SerializationTraits<R>::Deserialize(recv_buf_.bbuf_ptr(), message_) - .ok(); - recv_buf_.Release(); - } else { - got_message = false; - recv_buf_.Clear(); - } + if (recv_buf_.Valid()) { + if (*status) { + got_message = *status = + SerializationTraits<R>::Deserialize(recv_buf_.bbuf_ptr(), message_) + .ok(); + recv_buf_.Release(); + } else { + got_message = false; + recv_buf_.Clear(); + } } else if (hijacked_) { if (hijacked_recv_message_failed_) { FinishOpRecvMessageFailureHandler(status); @@ -463,34 +463,34 @@ class CallOpRecvMessage { // to be performed since the message is already in its non-serialized // form. } - } else { + } else { FinishOpRecvMessageFailureHandler(status); - } - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (message_ == nullptr) return; + } + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (message_ == nullptr) return; interceptor_methods->SetRecvMessage(message_, &hijacked_recv_message_failed_); - } - - void SetFinishInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (message_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_RECV_MESSAGE); - if (!got_message) interceptor_methods->SetRecvMessage(nullptr, nullptr); - } - void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { - hijacked_ = true; - if (message_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_RECV_MESSAGE); - got_message = true; - } - - private: + } + + void SetFinishInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (message_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_RECV_MESSAGE); + if (!got_message) interceptor_methods->SetRecvMessage(nullptr, nullptr); + } + void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { + hijacked_ = true; + if (message_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_RECV_MESSAGE); + got_message = true; + } + + private: // Sets got_message and \a status for a failed recv message op void FinishOpRecvMessageFailureHandler(bool* status) { got_message = false; @@ -500,69 +500,69 @@ class CallOpRecvMessage { } R* message_ = nullptr; - ByteBuffer recv_buf_; + ByteBuffer recv_buf_; bool allow_not_getting_message_ = false; - bool hijacked_ = false; + bool hijacked_ = false; bool hijacked_recv_message_failed_ = false; -}; - -class DeserializeFunc { - public: - virtual Status Deserialize(ByteBuffer* buf) = 0; - virtual ~DeserializeFunc() {} -}; - -template <class R> -class DeserializeFuncType final : public DeserializeFunc { - public: - DeserializeFuncType(R* message) : message_(message) {} - Status Deserialize(ByteBuffer* buf) override { - return SerializationTraits<R>::Deserialize(buf->bbuf_ptr(), message_); - } - - ~DeserializeFuncType() override {} - - private: - R* message_; // Not a managed pointer because management is external to this -}; - -class CallOpGenericRecvMessage { - public: - template <class R> - void RecvMessage(R* message) { - // Use an explicit base class pointer to avoid resolution error in the - // following unique_ptr::reset for some old implementations. - DeserializeFunc* func = new DeserializeFuncType<R>(message); - deserialize_.reset(func); - message_ = message; - } - - // Do not change status if no message is received. - void AllowNoMessage() { allow_not_getting_message_ = true; } - +}; + +class DeserializeFunc { + public: + virtual Status Deserialize(ByteBuffer* buf) = 0; + virtual ~DeserializeFunc() {} +}; + +template <class R> +class DeserializeFuncType final : public DeserializeFunc { + public: + DeserializeFuncType(R* message) : message_(message) {} + Status Deserialize(ByteBuffer* buf) override { + return SerializationTraits<R>::Deserialize(buf->bbuf_ptr(), message_); + } + + ~DeserializeFuncType() override {} + + private: + R* message_; // Not a managed pointer because management is external to this +}; + +class CallOpGenericRecvMessage { + public: + template <class R> + void RecvMessage(R* message) { + // Use an explicit base class pointer to avoid resolution error in the + // following unique_ptr::reset for some old implementations. + DeserializeFunc* func = new DeserializeFuncType<R>(message); + deserialize_.reset(func); + message_ = message; + } + + // Do not change status if no message is received. + void AllowNoMessage() { allow_not_getting_message_ = true; } + bool got_message = false; - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (!deserialize_ || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_RECV_MESSAGE; - op->flags = 0; - op->reserved = NULL; - op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr(); - } - - void FinishOp(bool* status) { + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (!deserialize_ || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_RECV_MESSAGE; + op->flags = 0; + op->reserved = NULL; + op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr(); + } + + void FinishOp(bool* status) { if (!deserialize_) return; - if (recv_buf_.Valid()) { - if (*status) { - got_message = true; - *status = deserialize_->Deserialize(&recv_buf_).ok(); - recv_buf_.Release(); - } else { - got_message = false; - recv_buf_.Clear(); - } + if (recv_buf_.Valid()) { + if (*status) { + got_message = true; + *status = deserialize_->Deserialize(&recv_buf_).ok(); + recv_buf_.Release(); + } else { + got_message = false; + recv_buf_.Clear(); + } } else if (hijacked_) { if (hijacked_recv_message_failed_) { FinishOpRecvMessageFailureHandler(status); @@ -571,38 +571,38 @@ class CallOpGenericRecvMessage { // to be performed since the message is already in its non-serialized // form. } - } else { - got_message = false; - if (!allow_not_getting_message_) { - *status = false; - } - } - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (!deserialize_) return; + } else { + got_message = false; + if (!allow_not_getting_message_) { + *status = false; + } + } + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (!deserialize_) return; interceptor_methods->SetRecvMessage(message_, &hijacked_recv_message_failed_); - } - - void SetFinishInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (!deserialize_) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_RECV_MESSAGE); - if (!got_message) interceptor_methods->SetRecvMessage(nullptr, nullptr); + } + + void SetFinishInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (!deserialize_) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_RECV_MESSAGE); + if (!got_message) interceptor_methods->SetRecvMessage(nullptr, nullptr); deserialize_.reset(); - } - void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { - hijacked_ = true; - if (!deserialize_) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_RECV_MESSAGE); - got_message = true; - } - - private: + } + void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { + hijacked_ = true; + if (!deserialize_) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_RECV_MESSAGE); + got_message = true; + } + + private: // Sets got_message and \a status for a failed recv message op void FinishOpRecvMessageFailureHandler(bool* status) { got_message = false; @@ -612,190 +612,190 @@ class CallOpGenericRecvMessage { } void* message_ = nullptr; - std::unique_ptr<DeserializeFunc> deserialize_; - ByteBuffer recv_buf_; + std::unique_ptr<DeserializeFunc> deserialize_; + ByteBuffer recv_buf_; bool allow_not_getting_message_ = false; bool hijacked_ = false; bool hijacked_recv_message_failed_ = false; -}; - -class CallOpClientSendClose { - public: - CallOpClientSendClose() : send_(false) {} - - void ClientSendClose() { send_ = true; } - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (!send_ || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; - op->flags = 0; - op->reserved = NULL; - } +}; + +class CallOpClientSendClose { + public: + CallOpClientSendClose() : send_(false) {} + + void ClientSendClose() { send_ = true; } + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (!send_ || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = NULL; + } void FinishOp(bool* /*status*/) { send_ = false; } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (!send_) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_SEND_CLOSE); - } - - void SetFinishInterceptionHookPoint( + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (!send_) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_SEND_CLOSE); + } + + void SetFinishInterceptionHookPoint( InterceptorBatchMethodsImpl* /*interceptor_methods*/) {} - + void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) { - hijacked_ = true; - } - - private: - bool hijacked_ = false; - bool send_; -}; - -class CallOpServerSendStatus { - public: - CallOpServerSendStatus() : send_status_available_(false) {} - - void ServerSendStatus( + hijacked_ = true; + } + + private: + bool hijacked_ = false; + bool send_; +}; + +class CallOpServerSendStatus { + public: + CallOpServerSendStatus() : send_status_available_(false) {} + + void ServerSendStatus( std::multimap<TString, TString>* trailing_metadata, - const Status& status) { - send_error_details_ = status.error_details(); - metadata_map_ = trailing_metadata; - send_status_available_ = true; - send_status_code_ = static_cast<grpc_status_code>(status.error_code()); - send_error_message_ = status.error_message(); - } - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (!send_status_available_ || hijacked_) return; - trailing_metadata_ = FillMetadataArray( - *metadata_map_, &trailing_metadata_count_, send_error_details_); - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; - op->data.send_status_from_server.trailing_metadata_count = - trailing_metadata_count_; - op->data.send_status_from_server.trailing_metadata = trailing_metadata_; - op->data.send_status_from_server.status = send_status_code_; - error_message_slice_ = SliceReferencingString(send_error_message_); - op->data.send_status_from_server.status_details = - send_error_message_.empty() ? nullptr : &error_message_slice_; - op->flags = 0; - op->reserved = NULL; - } - + const Status& status) { + send_error_details_ = status.error_details(); + metadata_map_ = trailing_metadata; + send_status_available_ = true; + send_status_code_ = static_cast<grpc_status_code>(status.error_code()); + send_error_message_ = status.error_message(); + } + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (!send_status_available_ || hijacked_) return; + trailing_metadata_ = FillMetadataArray( + *metadata_map_, &trailing_metadata_count_, send_error_details_); + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; + op->data.send_status_from_server.trailing_metadata_count = + trailing_metadata_count_; + op->data.send_status_from_server.trailing_metadata = trailing_metadata_; + op->data.send_status_from_server.status = send_status_code_; + error_message_slice_ = SliceReferencingString(send_error_message_); + op->data.send_status_from_server.status_details = + send_error_message_.empty() ? nullptr : &error_message_slice_; + op->flags = 0; + op->reserved = NULL; + } + void FinishOp(bool* /*status*/) { - if (!send_status_available_ || hijacked_) return; - g_core_codegen_interface->gpr_free(trailing_metadata_); - send_status_available_ = false; - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (!send_status_available_) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_SEND_STATUS); - interceptor_methods->SetSendTrailingMetadata(metadata_map_); - interceptor_methods->SetSendStatus(&send_status_code_, &send_error_details_, - &send_error_message_); - } - - void SetFinishInterceptionHookPoint( + if (!send_status_available_ || hijacked_) return; + g_core_codegen_interface->gpr_free(trailing_metadata_); + send_status_available_ = false; + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (!send_status_available_) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_SEND_STATUS); + interceptor_methods->SetSendTrailingMetadata(metadata_map_); + interceptor_methods->SetSendStatus(&send_status_code_, &send_error_details_, + &send_error_message_); + } + + void SetFinishInterceptionHookPoint( InterceptorBatchMethodsImpl* /*interceptor_methods*/) {} - + void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) { - hijacked_ = true; - } - - private: - bool hijacked_ = false; - bool send_status_available_; - grpc_status_code send_status_code_; + hijacked_ = true; + } + + private: + bool hijacked_ = false; + bool send_status_available_; + grpc_status_code send_status_code_; TString send_error_details_; TString send_error_message_; - size_t trailing_metadata_count_; + size_t trailing_metadata_count_; std::multimap<TString, TString>* metadata_map_; - grpc_metadata* trailing_metadata_; - grpc_slice error_message_slice_; -}; - -class CallOpRecvInitialMetadata { - public: - CallOpRecvInitialMetadata() : metadata_map_(nullptr) {} - + grpc_metadata* trailing_metadata_; + grpc_slice error_message_slice_; +}; + +class CallOpRecvInitialMetadata { + public: + CallOpRecvInitialMetadata() : metadata_map_(nullptr) {} + void RecvInitialMetadata(::grpc::ClientContext* context) { - context->initial_metadata_received_ = true; - metadata_map_ = &context->recv_initial_metadata_; - } - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (metadata_map_ == nullptr || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_RECV_INITIAL_METADATA; - op->data.recv_initial_metadata.recv_initial_metadata = metadata_map_->arr(); - op->flags = 0; - op->reserved = NULL; - } - + context->initial_metadata_received_ = true; + metadata_map_ = &context->recv_initial_metadata_; + } + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (metadata_map_ == nullptr || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = metadata_map_->arr(); + op->flags = 0; + op->reserved = NULL; + } + void FinishOp(bool* /*status*/) { - if (metadata_map_ == nullptr || hijacked_) return; - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - interceptor_methods->SetRecvInitialMetadata(metadata_map_); - } - - void SetFinishInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (metadata_map_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_RECV_INITIAL_METADATA); - metadata_map_ = nullptr; - } - - void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { - hijacked_ = true; - if (metadata_map_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_RECV_INITIAL_METADATA); - } - - private: - bool hijacked_ = false; - MetadataMap* metadata_map_; -}; - -class CallOpClientRecvStatus { - public: - CallOpClientRecvStatus() - : recv_status_(nullptr), debug_error_string_(nullptr) {} - + if (metadata_map_ == nullptr || hijacked_) return; + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + interceptor_methods->SetRecvInitialMetadata(metadata_map_); + } + + void SetFinishInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (metadata_map_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_RECV_INITIAL_METADATA); + metadata_map_ = nullptr; + } + + void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { + hijacked_ = true; + if (metadata_map_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_RECV_INITIAL_METADATA); + } + + private: + bool hijacked_ = false; + MetadataMap* metadata_map_; +}; + +class CallOpClientRecvStatus { + public: + CallOpClientRecvStatus() + : recv_status_(nullptr), debug_error_string_(nullptr) {} + void ClientRecvStatus(::grpc::ClientContext* context, Status* status) { - client_context_ = context; - metadata_map_ = &client_context_->trailing_metadata_; - recv_status_ = status; - error_message_ = g_core_codegen_interface->grpc_empty_slice(); - } - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (recv_status_ == nullptr || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; - op->data.recv_status_on_client.trailing_metadata = metadata_map_->arr(); - op->data.recv_status_on_client.status = &status_code_; - op->data.recv_status_on_client.status_details = &error_message_; - op->data.recv_status_on_client.error_string = &debug_error_string_; - op->flags = 0; - op->reserved = NULL; - } - + client_context_ = context; + metadata_map_ = &client_context_->trailing_metadata_; + recv_status_ = status; + error_message_ = g_core_codegen_interface->grpc_empty_slice(); + } + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (recv_status_ == nullptr || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = metadata_map_->arr(); + op->data.recv_status_on_client.status = &status_code_; + op->data.recv_status_on_client.status_details = &error_message_; + op->data.recv_status_on_client.error_string = &debug_error_string_; + op->flags = 0; + op->reserved = NULL; + } + void FinishOp(bool* /*status*/) { - if (recv_status_ == nullptr || hijacked_) return; + if (recv_status_ == nullptr || hijacked_) return; if (static_cast<StatusCode>(status_code_) == StatusCode::OK) { *recv_status_ = Status(); GPR_CODEGEN_DEBUG_ASSERT(debug_error_string_ == nullptr); @@ -814,156 +814,156 @@ class CallOpClientRecvStatus { } // TODO(soheil): Find callers that set debug string even for status OK, // and fix them. - g_core_codegen_interface->grpc_slice_unref(error_message_); - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - interceptor_methods->SetRecvStatus(recv_status_); - interceptor_methods->SetRecvTrailingMetadata(metadata_map_); - } - - void SetFinishInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (recv_status_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_RECV_STATUS); - recv_status_ = nullptr; - } - - void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { - hijacked_ = true; - if (recv_status_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_RECV_STATUS); - } - - private: - bool hijacked_ = false; + g_core_codegen_interface->grpc_slice_unref(error_message_); + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + interceptor_methods->SetRecvStatus(recv_status_); + interceptor_methods->SetRecvTrailingMetadata(metadata_map_); + } + + void SetFinishInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (recv_status_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_RECV_STATUS); + recv_status_ = nullptr; + } + + void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { + hijacked_ = true; + if (recv_status_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_RECV_STATUS); + } + + private: + bool hijacked_ = false; ::grpc::ClientContext* client_context_; - MetadataMap* metadata_map_; - Status* recv_status_; - const char* debug_error_string_; - grpc_status_code status_code_; - grpc_slice error_message_; -}; - -template <class Op1 = CallNoOp<1>, class Op2 = CallNoOp<2>, - class Op3 = CallNoOp<3>, class Op4 = CallNoOp<4>, - class Op5 = CallNoOp<5>, class Op6 = CallNoOp<6>> -class CallOpSet; - -/// Primary implementation of CallOpSetInterface. -/// Since we cannot use variadic templates, we declare slots up to -/// the maximum count of ops we'll need in a set. We leverage the -/// empty base class optimization to slim this class (especially -/// when there are many unused slots used). To avoid duplicate base classes, + MetadataMap* metadata_map_; + Status* recv_status_; + const char* debug_error_string_; + grpc_status_code status_code_; + grpc_slice error_message_; +}; + +template <class Op1 = CallNoOp<1>, class Op2 = CallNoOp<2>, + class Op3 = CallNoOp<3>, class Op4 = CallNoOp<4>, + class Op5 = CallNoOp<5>, class Op6 = CallNoOp<6>> +class CallOpSet; + +/// Primary implementation of CallOpSetInterface. +/// Since we cannot use variadic templates, we declare slots up to +/// the maximum count of ops we'll need in a set. We leverage the +/// empty base class optimization to slim this class (especially +/// when there are many unused slots used). To avoid duplicate base classes, /// the template parameter for CallNoOp is varied by argument position. -template <class Op1, class Op2, class Op3, class Op4, class Op5, class Op6> -class CallOpSet : public CallOpSetInterface, - public Op1, - public Op2, - public Op3, - public Op4, - public Op5, - public Op6 { - public: - CallOpSet() : core_cq_tag_(this), return_tag_(this) {} - // The copy constructor and assignment operator reset the value of - // core_cq_tag_, return_tag_, done_intercepting_ and interceptor_methods_ - // since those are only meaningful on a specific object, not across objects. - CallOpSet(const CallOpSet& other) - : core_cq_tag_(this), - return_tag_(this), - call_(other.call_), - done_intercepting_(false), - interceptor_methods_(InterceptorBatchMethodsImpl()) {} - - CallOpSet& operator=(const CallOpSet& other) { - core_cq_tag_ = this; - return_tag_ = this; - call_ = other.call_; - done_intercepting_ = false; - interceptor_methods_ = InterceptorBatchMethodsImpl(); - return *this; - } - - void FillOps(Call* call) override { - done_intercepting_ = false; - g_core_codegen_interface->grpc_call_ref(call->call()); - call_ = - *call; // It's fine to create a copy of call since it's just pointers - - if (RunInterceptors()) { - ContinueFillOpsAfterInterception(); - } else { - // After the interceptors are run, ContinueFillOpsAfterInterception will - // be run - } - } - - bool FinalizeResult(void** tag, bool* status) override { - if (done_intercepting_) { - // Complete the avalanching since we are done with this batch of ops - call_.cq()->CompleteAvalanching(); - // We have already finished intercepting and filling in the results. This - // round trip from the core needed to be made because interceptors were - // run - *tag = return_tag_; - *status = saved_status_; - g_core_codegen_interface->grpc_call_unref(call_.call()); - return true; - } - - this->Op1::FinishOp(status); - this->Op2::FinishOp(status); - this->Op3::FinishOp(status); - this->Op4::FinishOp(status); - this->Op5::FinishOp(status); - this->Op6::FinishOp(status); - saved_status_ = *status; - if (RunInterceptorsPostRecv()) { - *tag = return_tag_; - g_core_codegen_interface->grpc_call_unref(call_.call()); - return true; - } - // Interceptors are going to be run, so we can't return the tag just yet. - // After the interceptors are run, ContinueFinalizeResultAfterInterception - return false; - } - - void set_output_tag(void* return_tag) { return_tag_ = return_tag; } - - void* core_cq_tag() override { return core_cq_tag_; } - - /// set_core_cq_tag is used to provide a different core CQ tag than "this". - /// This is used for callback-based tags, where the core tag is the core - /// callback function. It does not change the use or behavior of any other - /// function (such as FinalizeResult) - void set_core_cq_tag(void* core_cq_tag) { core_cq_tag_ = core_cq_tag; } - - // This will be called while interceptors are run if the RPC is a hijacked - // RPC. This should set hijacking state for each of the ops. - void SetHijackingState() override { - this->Op1::SetHijackingState(&interceptor_methods_); - this->Op2::SetHijackingState(&interceptor_methods_); - this->Op3::SetHijackingState(&interceptor_methods_); - this->Op4::SetHijackingState(&interceptor_methods_); - this->Op5::SetHijackingState(&interceptor_methods_); - this->Op6::SetHijackingState(&interceptor_methods_); - } - - // Should be called after interceptors are done running - void ContinueFillOpsAfterInterception() override { - static const size_t MAX_OPS = 6; - grpc_op ops[MAX_OPS]; - size_t nops = 0; - this->Op1::AddOp(ops, &nops); - this->Op2::AddOp(ops, &nops); - this->Op3::AddOp(ops, &nops); - this->Op4::AddOp(ops, &nops); - this->Op5::AddOp(ops, &nops); - this->Op6::AddOp(ops, &nops); +template <class Op1, class Op2, class Op3, class Op4, class Op5, class Op6> +class CallOpSet : public CallOpSetInterface, + public Op1, + public Op2, + public Op3, + public Op4, + public Op5, + public Op6 { + public: + CallOpSet() : core_cq_tag_(this), return_tag_(this) {} + // The copy constructor and assignment operator reset the value of + // core_cq_tag_, return_tag_, done_intercepting_ and interceptor_methods_ + // since those are only meaningful on a specific object, not across objects. + CallOpSet(const CallOpSet& other) + : core_cq_tag_(this), + return_tag_(this), + call_(other.call_), + done_intercepting_(false), + interceptor_methods_(InterceptorBatchMethodsImpl()) {} + + CallOpSet& operator=(const CallOpSet& other) { + core_cq_tag_ = this; + return_tag_ = this; + call_ = other.call_; + done_intercepting_ = false; + interceptor_methods_ = InterceptorBatchMethodsImpl(); + return *this; + } + + void FillOps(Call* call) override { + done_intercepting_ = false; + g_core_codegen_interface->grpc_call_ref(call->call()); + call_ = + *call; // It's fine to create a copy of call since it's just pointers + + if (RunInterceptors()) { + ContinueFillOpsAfterInterception(); + } else { + // After the interceptors are run, ContinueFillOpsAfterInterception will + // be run + } + } + + bool FinalizeResult(void** tag, bool* status) override { + if (done_intercepting_) { + // Complete the avalanching since we are done with this batch of ops + call_.cq()->CompleteAvalanching(); + // We have already finished intercepting and filling in the results. This + // round trip from the core needed to be made because interceptors were + // run + *tag = return_tag_; + *status = saved_status_; + g_core_codegen_interface->grpc_call_unref(call_.call()); + return true; + } + + this->Op1::FinishOp(status); + this->Op2::FinishOp(status); + this->Op3::FinishOp(status); + this->Op4::FinishOp(status); + this->Op5::FinishOp(status); + this->Op6::FinishOp(status); + saved_status_ = *status; + if (RunInterceptorsPostRecv()) { + *tag = return_tag_; + g_core_codegen_interface->grpc_call_unref(call_.call()); + return true; + } + // Interceptors are going to be run, so we can't return the tag just yet. + // After the interceptors are run, ContinueFinalizeResultAfterInterception + return false; + } + + void set_output_tag(void* return_tag) { return_tag_ = return_tag; } + + void* core_cq_tag() override { return core_cq_tag_; } + + /// set_core_cq_tag is used to provide a different core CQ tag than "this". + /// This is used for callback-based tags, where the core tag is the core + /// callback function. It does not change the use or behavior of any other + /// function (such as FinalizeResult) + void set_core_cq_tag(void* core_cq_tag) { core_cq_tag_ = core_cq_tag; } + + // This will be called while interceptors are run if the RPC is a hijacked + // RPC. This should set hijacking state for each of the ops. + void SetHijackingState() override { + this->Op1::SetHijackingState(&interceptor_methods_); + this->Op2::SetHijackingState(&interceptor_methods_); + this->Op3::SetHijackingState(&interceptor_methods_); + this->Op4::SetHijackingState(&interceptor_methods_); + this->Op5::SetHijackingState(&interceptor_methods_); + this->Op6::SetHijackingState(&interceptor_methods_); + } + + // Should be called after interceptors are done running + void ContinueFillOpsAfterInterception() override { + static const size_t MAX_OPS = 6; + grpc_op ops[MAX_OPS]; + size_t nops = 0; + this->Op1::AddOp(ops, &nops); + this->Op2::AddOp(ops, &nops); + this->Op3::AddOp(ops, &nops); + this->Op4::AddOp(ops, &nops); + this->Op5::AddOp(ops, &nops); + this->Op6::AddOp(ops, &nops); grpc_call_error err = g_core_codegen_interface->grpc_call_start_batch( call_.call(), ops, nops, core_cq_tag(), nullptr); @@ -976,62 +976,62 @@ class CallOpSet : public CallOpSetInterface, // g_core_codegen_interface->grpc_call_error_to_string(err)); GPR_CODEGEN_ASSERT(false); } - } - - // Should be called after interceptors are done running on the finalize result - // path - void ContinueFinalizeResultAfterInterception() override { - done_intercepting_ = true; + } + + // Should be called after interceptors are done running on the finalize result + // path + void ContinueFinalizeResultAfterInterception() override { + done_intercepting_ = true; // The following call_start_batch is internally-generated so no need for an // explanatory log on failure. GPR_CODEGEN_ASSERT(g_core_codegen_interface->grpc_call_start_batch( call_.call(), nullptr, 0, core_cq_tag(), nullptr) == GRPC_CALL_OK); - } - - private: - // Returns true if no interceptors need to be run - bool RunInterceptors() { - interceptor_methods_.ClearState(); - interceptor_methods_.SetCallOpSetInterface(this); - interceptor_methods_.SetCall(&call_); - this->Op1::SetInterceptionHookPoint(&interceptor_methods_); - this->Op2::SetInterceptionHookPoint(&interceptor_methods_); - this->Op3::SetInterceptionHookPoint(&interceptor_methods_); - this->Op4::SetInterceptionHookPoint(&interceptor_methods_); - this->Op5::SetInterceptionHookPoint(&interceptor_methods_); - this->Op6::SetInterceptionHookPoint(&interceptor_methods_); - if (interceptor_methods_.InterceptorsListEmpty()) { - return true; - } - // This call will go through interceptors and would need to - // schedule new batches, so delay completion queue shutdown - call_.cq()->RegisterAvalanching(); - return interceptor_methods_.RunInterceptors(); - } - // Returns true if no interceptors need to be run - bool RunInterceptorsPostRecv() { - // Call and OpSet had already been set on the set state. - // SetReverse also clears previously set hook points - interceptor_methods_.SetReverse(); - this->Op1::SetFinishInterceptionHookPoint(&interceptor_methods_); - this->Op2::SetFinishInterceptionHookPoint(&interceptor_methods_); - this->Op3::SetFinishInterceptionHookPoint(&interceptor_methods_); - this->Op4::SetFinishInterceptionHookPoint(&interceptor_methods_); - this->Op5::SetFinishInterceptionHookPoint(&interceptor_methods_); - this->Op6::SetFinishInterceptionHookPoint(&interceptor_methods_); - return interceptor_methods_.RunInterceptors(); - } - - void* core_cq_tag_; - void* return_tag_; - Call call_; - bool done_intercepting_ = false; - InterceptorBatchMethodsImpl interceptor_methods_; - bool saved_status_; -}; - -} // namespace internal -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H + } + + private: + // Returns true if no interceptors need to be run + bool RunInterceptors() { + interceptor_methods_.ClearState(); + interceptor_methods_.SetCallOpSetInterface(this); + interceptor_methods_.SetCall(&call_); + this->Op1::SetInterceptionHookPoint(&interceptor_methods_); + this->Op2::SetInterceptionHookPoint(&interceptor_methods_); + this->Op3::SetInterceptionHookPoint(&interceptor_methods_); + this->Op4::SetInterceptionHookPoint(&interceptor_methods_); + this->Op5::SetInterceptionHookPoint(&interceptor_methods_); + this->Op6::SetInterceptionHookPoint(&interceptor_methods_); + if (interceptor_methods_.InterceptorsListEmpty()) { + return true; + } + // This call will go through interceptors and would need to + // schedule new batches, so delay completion queue shutdown + call_.cq()->RegisterAvalanching(); + return interceptor_methods_.RunInterceptors(); + } + // Returns true if no interceptors need to be run + bool RunInterceptorsPostRecv() { + // Call and OpSet had already been set on the set state. + // SetReverse also clears previously set hook points + interceptor_methods_.SetReverse(); + this->Op1::SetFinishInterceptionHookPoint(&interceptor_methods_); + this->Op2::SetFinishInterceptionHookPoint(&interceptor_methods_); + this->Op3::SetFinishInterceptionHookPoint(&interceptor_methods_); + this->Op4::SetFinishInterceptionHookPoint(&interceptor_methods_); + this->Op5::SetFinishInterceptionHookPoint(&interceptor_methods_); + this->Op6::SetFinishInterceptionHookPoint(&interceptor_methods_); + return interceptor_methods_.RunInterceptors(); + } + + void* core_cq_tag_; + void* return_tag_; + Call call_; + bool done_intercepting_ = false; + InterceptorBatchMethodsImpl interceptor_methods_; + bool saved_status_; +}; + +} // namespace internal +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set_interface.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set_interface.h index 664dae0e6a..3b74566a6d 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set_interface.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set_interface.h @@ -1,59 +1,59 @@ -/* - * - * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H -#define GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H - -#include <grpcpp/impl/codegen/completion_queue_tag.h> - -namespace grpc { -namespace internal { - -class Call; - -/// An abstract collection of call ops, used to generate the -/// grpc_call_op structure to pass down to the lower layers, -/// and as it is-a CompletionQueueTag, also massages the final -/// completion into the correct form for consumption in the C++ -/// API. -class CallOpSetInterface : public CompletionQueueTag { - public: - /// Fills in grpc_op, starting from ops[*nops] and moving - /// upwards. - virtual void FillOps(internal::Call* call) = 0; - - /// Get the tag to be used at the core completion queue. Generally, the - /// value of core_cq_tag will be "this". However, it can be overridden if we - /// want core to process the tag differently (e.g., as a core callback) - virtual void* core_cq_tag() = 0; - - // This will be called while interceptors are run if the RPC is a hijacked - // RPC. This should set hijacking state for each of the ops. - virtual void SetHijackingState() = 0; - - // Should be called after interceptors are done running - virtual void ContinueFillOpsAfterInterception() = 0; - - // Should be called after interceptors are done running on the finalize result - // path - virtual void ContinueFinalizeResultAfterInterception() = 0; -}; -} // namespace internal -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H +/* + * + * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H +#define GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H + +#include <grpcpp/impl/codegen/completion_queue_tag.h> + +namespace grpc { +namespace internal { + +class Call; + +/// An abstract collection of call ops, used to generate the +/// grpc_call_op structure to pass down to the lower layers, +/// and as it is-a CompletionQueueTag, also massages the final +/// completion into the correct form for consumption in the C++ +/// API. +class CallOpSetInterface : public CompletionQueueTag { + public: + /// Fills in grpc_op, starting from ops[*nops] and moving + /// upwards. + virtual void FillOps(internal::Call* call) = 0; + + /// Get the tag to be used at the core completion queue. Generally, the + /// value of core_cq_tag will be "this". However, it can be overridden if we + /// want core to process the tag differently (e.g., as a core callback) + virtual void* core_cq_tag() = 0; + + // This will be called while interceptors are run if the RPC is a hijacked + // RPC. This should set hijacking state for each of the ops. + virtual void SetHijackingState() = 0; + + // Should be called after interceptors are done running + virtual void ContinueFillOpsAfterInterception() = 0; + + // Should be called after interceptors are done running on the finalize result + // path + virtual void ContinueFinalizeResultAfterInterception() = 0; +}; +} // namespace internal +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/callback_common.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/callback_common.h index 784ac3f835..3c3bfd7e76 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/callback_common.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/callback_common.h @@ -1,226 +1,226 @@ -/* - * - * Copyright 2018 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. - * - */ - -#if defined(__GNUC__) -#pragma GCC system_header -#endif - -#ifndef GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H -#define GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H - -#include <functional> - -#include <grpc/impl/codegen/grpc_types.h> -#include <grpcpp/impl/codegen/call.h> -#include <grpcpp/impl/codegen/channel_interface.h> -#include <grpcpp/impl/codegen/config.h> -#include <grpcpp/impl/codegen/core_codegen_interface.h> -#include <grpcpp/impl/codegen/status.h> - -namespace grpc { -namespace internal { - -/// An exception-safe way of invoking a user-specified callback function -// TODO(vjpai): decide whether it is better for this to take a const lvalue -// parameter or an rvalue parameter, or if it even matters -template <class Func, class... Args> -void CatchingCallback(Func&& func, Args&&... args) { -#if GRPC_ALLOW_EXCEPTIONS - try { - func(std::forward<Args>(args)...); - } catch (...) { - // nothing to return or change here, just don't crash the library - } -#else // GRPC_ALLOW_EXCEPTIONS - func(std::forward<Args>(args)...); -#endif // GRPC_ALLOW_EXCEPTIONS -} - +/* + * + * Copyright 2018 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. + * + */ + +#if defined(__GNUC__) +#pragma GCC system_header +#endif + +#ifndef GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H +#define GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H + +#include <functional> + +#include <grpc/impl/codegen/grpc_types.h> +#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/codegen/channel_interface.h> +#include <grpcpp/impl/codegen/config.h> +#include <grpcpp/impl/codegen/core_codegen_interface.h> +#include <grpcpp/impl/codegen/status.h> + +namespace grpc { +namespace internal { + +/// An exception-safe way of invoking a user-specified callback function +// TODO(vjpai): decide whether it is better for this to take a const lvalue +// parameter or an rvalue parameter, or if it even matters +template <class Func, class... Args> +void CatchingCallback(Func&& func, Args&&... args) { +#if GRPC_ALLOW_EXCEPTIONS + try { + func(std::forward<Args>(args)...); + } catch (...) { + // nothing to return or change here, just don't crash the library + } +#else // GRPC_ALLOW_EXCEPTIONS + func(std::forward<Args>(args)...); +#endif // GRPC_ALLOW_EXCEPTIONS +} + template <class Reactor, class Func, class... Args> Reactor* CatchingReactorGetter(Func&& func, Args&&... args) { -#if GRPC_ALLOW_EXCEPTIONS - try { - return func(std::forward<Args>(args)...); - } catch (...) { - // fail the RPC, don't crash the library - return nullptr; - } -#else // GRPC_ALLOW_EXCEPTIONS - return func(std::forward<Args>(args)...); -#endif // GRPC_ALLOW_EXCEPTIONS -} - -// The contract on these tags is that they are single-shot. They must be -// constructed and then fired at exactly one point. There is no expectation -// that they can be reused without reconstruction. - -class CallbackWithStatusTag - : public grpc_experimental_completion_queue_functor { - public: - // always allocated against a call arena, no memory free required +#if GRPC_ALLOW_EXCEPTIONS + try { + return func(std::forward<Args>(args)...); + } catch (...) { + // fail the RPC, don't crash the library + return nullptr; + } +#else // GRPC_ALLOW_EXCEPTIONS + return func(std::forward<Args>(args)...); +#endif // GRPC_ALLOW_EXCEPTIONS +} + +// The contract on these tags is that they are single-shot. They must be +// constructed and then fired at exactly one point. There is no expectation +// that they can be reused without reconstruction. + +class CallbackWithStatusTag + : public grpc_experimental_completion_queue_functor { + public: + // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { GPR_CODEGEN_ASSERT(size == sizeof(CallbackWithStatusTag)); - } - - // This operator should never be called as the memory should be freed as part - // of the arena destruction. It only exists to provide a matching operator - // delete to the operator new so that some compilers will not complain (see - // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this - // there are no tests catching the compiler warning. + } + + // This operator should never be called as the memory should be freed as part + // of the arena destruction. It only exists to provide a matching operator + // delete to the operator new so that some compilers will not complain (see + // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this + // there are no tests catching the compiler warning. static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } - - CallbackWithStatusTag(grpc_call* call, std::function<void(Status)> f, - CompletionQueueTag* ops) - : call_(call), func_(std::move(f)), ops_(ops) { - g_core_codegen_interface->grpc_call_ref(call); - functor_run = &CallbackWithStatusTag::StaticRun; + + CallbackWithStatusTag(grpc_call* call, std::function<void(Status)> f, + CompletionQueueTag* ops) + : call_(call), func_(std::move(f)), ops_(ops) { + g_core_codegen_interface->grpc_call_ref(call); + functor_run = &CallbackWithStatusTag::StaticRun; // A client-side callback should never be run inline since they will always // have work to do from the user application. So, set the parent's // inlineable field to false inlineable = false; - } - ~CallbackWithStatusTag() {} - Status* status_ptr() { return &status_; } - - // force_run can not be performed on a tag if operations using this tag - // have been sent to PerformOpsOnCall. It is intended for error conditions - // that are detected before the operations are internally processed. - void force_run(Status s) { - status_ = std::move(s); - Run(true); - } - - private: - grpc_call* call_; - std::function<void(Status)> func_; - CompletionQueueTag* ops_; - Status status_; - - static void StaticRun(grpc_experimental_completion_queue_functor* cb, - int ok) { - static_cast<CallbackWithStatusTag*>(cb)->Run(static_cast<bool>(ok)); - } - void Run(bool ok) { - void* ignored = ops_; - - if (!ops_->FinalizeResult(&ignored, &ok)) { - // The tag was swallowed - return; - } - GPR_CODEGEN_ASSERT(ignored == ops_); - - // Last use of func_ or status_, so ok to move them out - auto func = std::move(func_); - auto status = std::move(status_); - func_ = nullptr; // reset to clear this out for sure - status_ = Status(); // reset to clear this out for sure - CatchingCallback(std::move(func), std::move(status)); - g_core_codegen_interface->grpc_call_unref(call_); - } -}; - -/// CallbackWithSuccessTag can be reused multiple times, and will be used in -/// this fashion for streaming operations. As a result, it shouldn't clear -/// anything up until its destructor -class CallbackWithSuccessTag - : public grpc_experimental_completion_queue_functor { - public: - // always allocated against a call arena, no memory free required + } + ~CallbackWithStatusTag() {} + Status* status_ptr() { return &status_; } + + // force_run can not be performed on a tag if operations using this tag + // have been sent to PerformOpsOnCall. It is intended for error conditions + // that are detected before the operations are internally processed. + void force_run(Status s) { + status_ = std::move(s); + Run(true); + } + + private: + grpc_call* call_; + std::function<void(Status)> func_; + CompletionQueueTag* ops_; + Status status_; + + static void StaticRun(grpc_experimental_completion_queue_functor* cb, + int ok) { + static_cast<CallbackWithStatusTag*>(cb)->Run(static_cast<bool>(ok)); + } + void Run(bool ok) { + void* ignored = ops_; + + if (!ops_->FinalizeResult(&ignored, &ok)) { + // The tag was swallowed + return; + } + GPR_CODEGEN_ASSERT(ignored == ops_); + + // Last use of func_ or status_, so ok to move them out + auto func = std::move(func_); + auto status = std::move(status_); + func_ = nullptr; // reset to clear this out for sure + status_ = Status(); // reset to clear this out for sure + CatchingCallback(std::move(func), std::move(status)); + g_core_codegen_interface->grpc_call_unref(call_); + } +}; + +/// CallbackWithSuccessTag can be reused multiple times, and will be used in +/// this fashion for streaming operations. As a result, it shouldn't clear +/// anything up until its destructor +class CallbackWithSuccessTag + : public grpc_experimental_completion_queue_functor { + public: + // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { GPR_CODEGEN_ASSERT(size == sizeof(CallbackWithSuccessTag)); - } - - // This operator should never be called as the memory should be freed as part - // of the arena destruction. It only exists to provide a matching operator - // delete to the operator new so that some compilers will not complain (see - // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this - // there are no tests catching the compiler warning. + } + + // This operator should never be called as the memory should be freed as part + // of the arena destruction. It only exists to provide a matching operator + // delete to the operator new so that some compilers will not complain (see + // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this + // there are no tests catching the compiler warning. static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } - - CallbackWithSuccessTag() : call_(nullptr) {} - - CallbackWithSuccessTag(const CallbackWithSuccessTag&) = delete; - CallbackWithSuccessTag& operator=(const CallbackWithSuccessTag&) = delete; - - ~CallbackWithSuccessTag() { Clear(); } - - // Set can only be called on a default-constructed or Clear'ed tag. - // It should never be called on a tag that was constructed with arguments - // or on a tag that has been Set before unless the tag has been cleared. + + CallbackWithSuccessTag() : call_(nullptr) {} + + CallbackWithSuccessTag(const CallbackWithSuccessTag&) = delete; + CallbackWithSuccessTag& operator=(const CallbackWithSuccessTag&) = delete; + + ~CallbackWithSuccessTag() { Clear(); } + + // Set can only be called on a default-constructed or Clear'ed tag. + // It should never be called on a tag that was constructed with arguments + // or on a tag that has been Set before unless the tag has been cleared. // can_inline indicates that this particular callback can be executed inline // (without needing a thread hop) and is only used for library-provided server // callbacks. - void Set(grpc_call* call, std::function<void(bool)> f, + void Set(grpc_call* call, std::function<void(bool)> f, CompletionQueueTag* ops, bool can_inline) { - GPR_CODEGEN_ASSERT(call_ == nullptr); - g_core_codegen_interface->grpc_call_ref(call); - call_ = call; - func_ = std::move(f); - ops_ = ops; - functor_run = &CallbackWithSuccessTag::StaticRun; + GPR_CODEGEN_ASSERT(call_ == nullptr); + g_core_codegen_interface->grpc_call_ref(call); + call_ = call; + func_ = std::move(f); + ops_ = ops; + functor_run = &CallbackWithSuccessTag::StaticRun; inlineable = can_inline; - } - - void Clear() { - if (call_ != nullptr) { - grpc_call* call = call_; - call_ = nullptr; - func_ = nullptr; - g_core_codegen_interface->grpc_call_unref(call); - } - } - - CompletionQueueTag* ops() { return ops_; } - - // force_run can not be performed on a tag if operations using this tag - // have been sent to PerformOpsOnCall. It is intended for error conditions - // that are detected before the operations are internally processed. - void force_run(bool ok) { Run(ok); } - - /// check if this tag is currently set - operator bool() const { return call_ != nullptr; } - - private: - grpc_call* call_; - std::function<void(bool)> func_; - CompletionQueueTag* ops_; - - static void StaticRun(grpc_experimental_completion_queue_functor* cb, - int ok) { - static_cast<CallbackWithSuccessTag*>(cb)->Run(static_cast<bool>(ok)); - } - void Run(bool ok) { - void* ignored = ops_; - // Allow a "false" return value from FinalizeResult to silence the - // callback, just as it silences a CQ tag in the async cases + } + + void Clear() { + if (call_ != nullptr) { + grpc_call* call = call_; + call_ = nullptr; + func_ = nullptr; + g_core_codegen_interface->grpc_call_unref(call); + } + } + + CompletionQueueTag* ops() { return ops_; } + + // force_run can not be performed on a tag if operations using this tag + // have been sent to PerformOpsOnCall. It is intended for error conditions + // that are detected before the operations are internally processed. + void force_run(bool ok) { Run(ok); } + + /// check if this tag is currently set + operator bool() const { return call_ != nullptr; } + + private: + grpc_call* call_; + std::function<void(bool)> func_; + CompletionQueueTag* ops_; + + static void StaticRun(grpc_experimental_completion_queue_functor* cb, + int ok) { + static_cast<CallbackWithSuccessTag*>(cb)->Run(static_cast<bool>(ok)); + } + void Run(bool ok) { + void* ignored = ops_; + // Allow a "false" return value from FinalizeResult to silence the + // callback, just as it silences a CQ tag in the async cases #ifndef NDEBUG - auto* ops = ops_; + auto* ops = ops_; #endif - bool do_callback = ops_->FinalizeResult(&ignored, &ok); + bool do_callback = ops_->FinalizeResult(&ignored, &ok); GPR_CODEGEN_DEBUG_ASSERT(ignored == ops); - - if (do_callback) { - CatchingCallback(func_, ok); - } - } -}; - -} // namespace internal -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H + + if (do_callback) { + CatchingCallback(func_, ok); + } + } +}; + +} // namespace internal +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/channel_interface.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/channel_interface.h index da3b6726d3..ea0752d90e 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/channel_interface.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/channel_interface.h @@ -16,15 +16,15 @@ * */ -#if defined(__GNUC__) -#pragma GCC system_header -#endif - +#if defined(__GNUC__) +#pragma GCC system_header +#endif + #ifndef GRPCPP_IMPL_CODEGEN_CHANNEL_INTERFACE_H #define GRPCPP_IMPL_CODEGEN_CHANNEL_INTERFACE_H #include <grpc/impl/codegen/connectivity_state.h> -#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/codegen/call.h> #include <grpcpp/impl/codegen/status.h> #include <grpcpp/impl/codegen/time.h> @@ -37,7 +37,7 @@ template <class W, class R> class ClientReaderWriter; namespace internal { template <class InputMessage, class OutputMessage> -class CallbackUnaryCallImpl; +class CallbackUnaryCallImpl; template <class R> class ClientAsyncReaderFactory; template <class W> @@ -46,12 +46,12 @@ template <class W, class R> class ClientAsyncReaderWriterFactory; template <class R> class ClientAsyncResponseReaderFactory; -template <class W, class R> -class ClientCallbackReaderWriterFactory; -template <class R> -class ClientCallbackReaderFactory; -template <class W> -class ClientCallbackWriterFactory; +template <class W, class R> +class ClientCallbackReaderWriterFactory; +template <class R> +class ClientCallbackReaderFactory; +template <class W> +class ClientCallbackWriterFactory; class ClientCallbackUnaryFactory; } // namespace internal @@ -67,7 +67,7 @@ namespace internal { class Call; class CallOpSetInterface; class RpcMethod; -class InterceptedChannel; +class InterceptedChannel; template <class InputMessage, class OutputMessage> class BlockingUnaryCallImpl; } // namespace internal @@ -122,20 +122,20 @@ class ChannelInterface { friend class ::grpc::internal::ClientAsyncReaderWriterFactory; template <class R> friend class ::grpc::internal::ClientAsyncResponseReaderFactory; - template <class W, class R> + template <class W, class R> friend class ::grpc::internal::ClientCallbackReaderWriterFactory; - template <class R> + template <class R> friend class ::grpc::internal::ClientCallbackReaderFactory; - template <class W> + template <class W> friend class ::grpc::internal::ClientCallbackWriterFactory; friend class ::grpc::internal::ClientCallbackUnaryFactory; template <class InputMessage, class OutputMessage> friend class ::grpc::internal::BlockingUnaryCallImpl; - template <class InputMessage, class OutputMessage> + template <class InputMessage, class OutputMessage> friend class ::grpc::internal::CallbackUnaryCallImpl; friend class ::grpc::internal::RpcMethod; friend class ::grpc::experimental::DelegatingChannel; - friend class ::grpc::internal::InterceptedChannel; + friend class ::grpc::internal::InterceptedChannel; virtual internal::Call CreateCall(const internal::RpcMethod& method, ::grpc::ClientContext* context, ::grpc::CompletionQueue* cq) = 0; @@ -148,28 +148,28 @@ class ChannelInterface { void* tag) = 0; virtual bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, gpr_timespec deadline) = 0; - - // EXPERIMENTAL - // This is needed to keep codegen_test_minimal happy. InterceptedChannel needs - // to make use of this but can't directly call Channel's implementation - // because of the test. - // Returns an empty Call object (rather than being pure) since this is a new - // method and adding a new pure method to an interface would be a breaking - // change (even though this is private and non-API) + + // EXPERIMENTAL + // This is needed to keep codegen_test_minimal happy. InterceptedChannel needs + // to make use of this but can't directly call Channel's implementation + // because of the test. + // Returns an empty Call object (rather than being pure) since this is a new + // method and adding a new pure method to an interface would be a breaking + // change (even though this is private and non-API) virtual internal::Call CreateCallInternal( const internal::RpcMethod& /*method*/, ::grpc::ClientContext* /*context*/, ::grpc::CompletionQueue* /*cq*/, size_t /*interceptor_pos*/) { - return internal::Call(); - } - - // EXPERIMENTAL - // A method to get the callbackable completion queue associated with this - // channel. If the return value is nullptr, this channel doesn't support - // callback operations. - // TODO(vjpai): Consider a better default like using a global CQ - // Returns nullptr (rather than being pure) since this is a post-1.0 method - // and adding a new pure method to an interface would be a breaking change - // (even though this is private and non-API) + return internal::Call(); + } + + // EXPERIMENTAL + // A method to get the callbackable completion queue associated with this + // channel. If the return value is nullptr, this channel doesn't support + // callback operations. + // TODO(vjpai): Consider a better default like using a global CQ + // Returns nullptr (rather than being pure) since this is a post-1.0 method + // and adding a new pure method to an interface would be a breaking change + // (even though this is private and non-API) virtual ::grpc::CompletionQueue* CallbackCQ() { return nullptr; } }; } // namespace grpc diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_callback.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_callback.h index 560edf491d..90c817ceaa 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_callback.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_callback.h @@ -1,25 +1,25 @@ -/* - * +/* + * * Copyright 2019 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 GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H -#define GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H + * + * 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 GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H +#define GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H #include <atomic> #include <functional> - + #include <grpcpp/impl/codegen/call.h> #include <grpcpp/impl/codegen/call_op_set.h> #include <grpcpp/impl/codegen/callback_common.h> @@ -27,8 +27,8 @@ #include <grpcpp/impl/codegen/config.h> #include <grpcpp/impl/codegen/core_codegen_interface.h> #include <grpcpp/impl/codegen/status.h> - -namespace grpc { + +namespace grpc { class Channel; class ClientContext; @@ -1190,30 +1190,30 @@ class ClientCallbackUnaryFactory { } // namespace internal // TODO(vjpai): Remove namespace experimental when de-experimentalized fully. -namespace experimental { - -template <class Response> +namespace experimental { + +template <class Response> using ClientCallbackReader = ::grpc::ClientCallbackReader<Response>; -template <class Request> +template <class Request> using ClientCallbackWriter = ::grpc::ClientCallbackWriter<Request>; - -template <class Request, class Response> + +template <class Request, class Response> using ClientCallbackReaderWriter = ::grpc::ClientCallbackReaderWriter<Request, Response>; - -template <class Response> + +template <class Response> using ClientReadReactor = ::grpc::ClientReadReactor<Response>; - -template <class Request> + +template <class Request> using ClientWriteReactor = ::grpc::ClientWriteReactor<Request>; - -template <class Request, class Response> + +template <class Request, class Response> using ClientBidiReactor = ::grpc::ClientBidiReactor<Request, Response>; - + typedef ::grpc::ClientUnaryReactor ClientUnaryReactor; -} // namespace experimental +} // namespace experimental -} // namespace grpc -#endif // GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H +} // namespace grpc +#endif // GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_interceptor.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_interceptor.h index 3d59da196b..78be1f7597 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_interceptor.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_interceptor.h @@ -1,190 +1,190 @@ -/* - * - * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H -#define GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H - -#include <memory> -#include <vector> - -#include <grpcpp/impl/codegen/interceptor.h> -#include <grpcpp/impl/codegen/rpc_method.h> -#include <grpcpp/impl/codegen/string_ref.h> - +/* + * + * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H +#define GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H + +#include <memory> +#include <vector> + +#include <grpcpp/impl/codegen/interceptor.h> +#include <grpcpp/impl/codegen/rpc_method.h> +#include <grpcpp/impl/codegen/string_ref.h> + namespace grpc { - + class Channel; -class ClientContext; - -namespace internal { -class InterceptorBatchMethodsImpl; -} - -namespace experimental { -class ClientRpcInfo; - -// A factory interface for creation of client interceptors. A vector of -// factories can be provided at channel creation which will be used to create a -// new vector of client interceptors per RPC. Client interceptor authors should -// create a subclass of ClientInterceptorFactorInterface which creates objects -// of their interceptors. -class ClientInterceptorFactoryInterface { - public: - virtual ~ClientInterceptorFactoryInterface() {} - // Returns a pointer to an Interceptor object on successful creation, nullptr - // otherwise. If nullptr is returned, this server interceptor factory is - // ignored for the purposes of that RPC. - virtual Interceptor* CreateClientInterceptor(ClientRpcInfo* info) = 0; -}; -} // namespace experimental - -namespace internal { -extern experimental::ClientInterceptorFactoryInterface* - g_global_client_interceptor_factory; -} - -/// ClientRpcInfo represents the state of a particular RPC as it -/// appears to an interceptor. It is created and owned by the library and -/// passed to the CreateClientInterceptor method of the application's -/// ClientInterceptorFactoryInterface implementation -namespace experimental { -class ClientRpcInfo { - public: - // TODO(yashykt): Stop default-constructing ClientRpcInfo and remove UNKNOWN - // from the list of possible Types. - /// Type categorizes RPCs by unary or streaming type - enum class Type { - UNARY, - CLIENT_STREAMING, - SERVER_STREAMING, - BIDI_STREAMING, - UNKNOWN // UNKNOWN is not API and will be removed later - }; - +class ClientContext; + +namespace internal { +class InterceptorBatchMethodsImpl; +} + +namespace experimental { +class ClientRpcInfo; + +// A factory interface for creation of client interceptors. A vector of +// factories can be provided at channel creation which will be used to create a +// new vector of client interceptors per RPC. Client interceptor authors should +// create a subclass of ClientInterceptorFactorInterface which creates objects +// of their interceptors. +class ClientInterceptorFactoryInterface { + public: + virtual ~ClientInterceptorFactoryInterface() {} + // Returns a pointer to an Interceptor object on successful creation, nullptr + // otherwise. If nullptr is returned, this server interceptor factory is + // ignored for the purposes of that RPC. + virtual Interceptor* CreateClientInterceptor(ClientRpcInfo* info) = 0; +}; +} // namespace experimental + +namespace internal { +extern experimental::ClientInterceptorFactoryInterface* + g_global_client_interceptor_factory; +} + +/// ClientRpcInfo represents the state of a particular RPC as it +/// appears to an interceptor. It is created and owned by the library and +/// passed to the CreateClientInterceptor method of the application's +/// ClientInterceptorFactoryInterface implementation +namespace experimental { +class ClientRpcInfo { + public: + // TODO(yashykt): Stop default-constructing ClientRpcInfo and remove UNKNOWN + // from the list of possible Types. + /// Type categorizes RPCs by unary or streaming type + enum class Type { + UNARY, + CLIENT_STREAMING, + SERVER_STREAMING, + BIDI_STREAMING, + UNKNOWN // UNKNOWN is not API and will be removed later + }; + ~ClientRpcInfo() {} - - // Delete copy constructor but allow default move constructor - ClientRpcInfo(const ClientRpcInfo&) = delete; - ClientRpcInfo(ClientRpcInfo&&) = default; - - // Getter methods - - /// Return the fully-specified method name - const char* method() const { return method_; } - - /// Return a pointer to the channel on which the RPC is being sent - ChannelInterface* channel() { return channel_; } - - /// Return a pointer to the underlying ClientContext structure associated - /// with the RPC to support features that apply to it + + // Delete copy constructor but allow default move constructor + ClientRpcInfo(const ClientRpcInfo&) = delete; + ClientRpcInfo(ClientRpcInfo&&) = default; + + // Getter methods + + /// Return the fully-specified method name + const char* method() const { return method_; } + + /// Return a pointer to the channel on which the RPC is being sent + ChannelInterface* channel() { return channel_; } + + /// Return a pointer to the underlying ClientContext structure associated + /// with the RPC to support features that apply to it grpc::ClientContext* client_context() { return ctx_; } - - /// Return the type of the RPC (unary or a streaming flavor) - Type type() const { return type_; } - - private: - static_assert(Type::UNARY == - static_cast<Type>(internal::RpcMethod::NORMAL_RPC), - "violated expectation about Type enum"); - static_assert(Type::CLIENT_STREAMING == - static_cast<Type>(internal::RpcMethod::CLIENT_STREAMING), - "violated expectation about Type enum"); - static_assert(Type::SERVER_STREAMING == - static_cast<Type>(internal::RpcMethod::SERVER_STREAMING), - "violated expectation about Type enum"); - static_assert(Type::BIDI_STREAMING == - static_cast<Type>(internal::RpcMethod::BIDI_STREAMING), - "violated expectation about Type enum"); - - // Default constructor should only be used by ClientContext - ClientRpcInfo() = default; - - // Constructor will only be called from ClientContext + + /// Return the type of the RPC (unary or a streaming flavor) + Type type() const { return type_; } + + private: + static_assert(Type::UNARY == + static_cast<Type>(internal::RpcMethod::NORMAL_RPC), + "violated expectation about Type enum"); + static_assert(Type::CLIENT_STREAMING == + static_cast<Type>(internal::RpcMethod::CLIENT_STREAMING), + "violated expectation about Type enum"); + static_assert(Type::SERVER_STREAMING == + static_cast<Type>(internal::RpcMethod::SERVER_STREAMING), + "violated expectation about Type enum"); + static_assert(Type::BIDI_STREAMING == + static_cast<Type>(internal::RpcMethod::BIDI_STREAMING), + "violated expectation about Type enum"); + + // Default constructor should only be used by ClientContext + ClientRpcInfo() = default; + + // Constructor will only be called from ClientContext ClientRpcInfo(grpc::ClientContext* ctx, internal::RpcMethod::RpcType type, const char* method, grpc::ChannelInterface* channel) - : ctx_(ctx), - type_(static_cast<Type>(type)), - method_(method), - channel_(channel) {} - - // Move assignment should only be used by ClientContext - // TODO(yashykt): Delete move assignment - ClientRpcInfo& operator=(ClientRpcInfo&&) = default; - - // Runs interceptor at pos \a pos. - void RunInterceptor( - experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { - GPR_CODEGEN_ASSERT(pos < interceptors_.size()); - interceptors_[pos]->Intercept(interceptor_methods); - } - - void RegisterInterceptors( - const std::vector<std::unique_ptr< - experimental::ClientInterceptorFactoryInterface>>& creators, - size_t interceptor_pos) { - if (interceptor_pos > creators.size()) { - // No interceptors to register - return; - } + : ctx_(ctx), + type_(static_cast<Type>(type)), + method_(method), + channel_(channel) {} + + // Move assignment should only be used by ClientContext + // TODO(yashykt): Delete move assignment + ClientRpcInfo& operator=(ClientRpcInfo&&) = default; + + // Runs interceptor at pos \a pos. + void RunInterceptor( + experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { + GPR_CODEGEN_ASSERT(pos < interceptors_.size()); + interceptors_[pos]->Intercept(interceptor_methods); + } + + void RegisterInterceptors( + const std::vector<std::unique_ptr< + experimental::ClientInterceptorFactoryInterface>>& creators, + size_t interceptor_pos) { + if (interceptor_pos > creators.size()) { + // No interceptors to register + return; + } // NOTE: The following is not a range-based for loop because it will only // iterate over a portion of the creators vector. - for (auto it = creators.begin() + interceptor_pos; it != creators.end(); - ++it) { - auto* interceptor = (*it)->CreateClientInterceptor(this); - if (interceptor != nullptr) { - interceptors_.push_back( - std::unique_ptr<experimental::Interceptor>(interceptor)); - } - } - if (internal::g_global_client_interceptor_factory != nullptr) { - interceptors_.push_back(std::unique_ptr<experimental::Interceptor>( - internal::g_global_client_interceptor_factory - ->CreateClientInterceptor(this))); - } - } - + for (auto it = creators.begin() + interceptor_pos; it != creators.end(); + ++it) { + auto* interceptor = (*it)->CreateClientInterceptor(this); + if (interceptor != nullptr) { + interceptors_.push_back( + std::unique_ptr<experimental::Interceptor>(interceptor)); + } + } + if (internal::g_global_client_interceptor_factory != nullptr) { + interceptors_.push_back(std::unique_ptr<experimental::Interceptor>( + internal::g_global_client_interceptor_factory + ->CreateClientInterceptor(this))); + } + } + grpc::ClientContext* ctx_ = nullptr; - // TODO(yashykt): make type_ const once move-assignment is deleted - Type type_{Type::UNKNOWN}; - const char* method_ = nullptr; - grpc::ChannelInterface* channel_ = nullptr; - std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; - bool hijacked_ = false; - size_t hijacked_interceptor_ = 0; - - friend class internal::InterceptorBatchMethodsImpl; + // TODO(yashykt): make type_ const once move-assignment is deleted + Type type_{Type::UNKNOWN}; + const char* method_ = nullptr; + grpc::ChannelInterface* channel_ = nullptr; + std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; + bool hijacked_ = false; + size_t hijacked_interceptor_ = 0; + + friend class internal::InterceptorBatchMethodsImpl; friend class grpc::ClientContext; -}; - -// PLEASE DO NOT USE THIS. ALWAYS PREFER PER CHANNEL INTERCEPTORS OVER A GLOBAL -// INTERCEPTOR. IF USAGE IS ABSOLUTELY NECESSARY, PLEASE READ THE SAFETY NOTES. -// Registers a global client interceptor factory object, which is used for all +}; + +// PLEASE DO NOT USE THIS. ALWAYS PREFER PER CHANNEL INTERCEPTORS OVER A GLOBAL +// INTERCEPTOR. IF USAGE IS ABSOLUTELY NECESSARY, PLEASE READ THE SAFETY NOTES. +// Registers a global client interceptor factory object, which is used for all // RPCs made in this process. The application is responsible for maintaining the // life of the object while gRPC operations are in progress. The global // interceptor factory should only be registered once at the start of the // process before any gRPC operations have begun. -void RegisterGlobalClientInterceptorFactory( - ClientInterceptorFactoryInterface* factory); - +void RegisterGlobalClientInterceptorFactory( + ClientInterceptorFactoryInterface* factory); + // For testing purposes only void TestOnlyResetGlobalClientInterceptorFactory(); -} // namespace experimental -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H +} // namespace experimental +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_unary_call.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_unary_call.h index 2c13cedf64..098bb50ee2 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_unary_call.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_unary_call.h @@ -47,18 +47,18 @@ class BlockingUnaryCallImpl { grpc::ClientContext* context, const InputMessage& request, OutputMessage* result) { ::grpc::CompletionQueue cq(grpc_completion_queue_attributes{ - GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, GRPC_CQ_DEFAULT_POLLING, - nullptr}); // Pluckable completion queue + GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, GRPC_CQ_DEFAULT_POLLING, + nullptr}); // Pluckable completion queue ::grpc::internal::Call call(channel->CreateCall(method, context, &cq)); CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage, CallOpRecvInitialMetadata, CallOpRecvMessage<OutputMessage>, CallOpClientSendClose, CallOpClientRecvStatus> ops; - status_ = ops.SendMessagePtr(&request); + status_ = ops.SendMessagePtr(&request); if (!status_.ok()) { return; } - ops.SendInitialMetadata(&context->send_initial_metadata_, + ops.SendInitialMetadata(&context->send_initial_metadata_, context->initial_metadata_flags()); ops.RecvInitialMetadata(context); ops.RecvMessage(result); @@ -66,17 +66,17 @@ class BlockingUnaryCallImpl { ops.ClientSendClose(); ops.ClientRecvStatus(context, &status_); call.PerformOps(&ops); - cq.Pluck(&ops); - // Some of the ops might fail. If the ops fail in the core layer, status - // would reflect the error. But, if the ops fail in the C++ layer, the - // status would still be the same as the one returned by gRPC Core. This can - // happen if deserialization of the message fails. - // TODO(yashykt): If deserialization fails, but the status received is OK, - // then it might be a good idea to change the status to something better - // than StatusCode::UNIMPLEMENTED to reflect this. - if (!ops.got_message && status_.ok()) { - status_ = Status(StatusCode::UNIMPLEMENTED, - "No message returned for unary request"); + cq.Pluck(&ops); + // Some of the ops might fail. If the ops fail in the core layer, status + // would reflect the error. But, if the ops fail in the C++ layer, the + // status would still be the same as the one returned by gRPC Core. This can + // happen if deserialization of the message fails. + // TODO(yashykt): If deserialization fails, but the status received is OK, + // then it might be a good idea to change the status to something better + // than StatusCode::UNIMPLEMENTED to reflect this. + if (!ops.got_message && status_.ok()) { + status_ = Status(StatusCode::UNIMPLEMENTED, + "No message returned for unary request"); } } Status status() { return status_; } diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/completion_queue_tag.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/completion_queue_tag.h index b97dde069c..304386a9ec 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/completion_queue_tag.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/completion_queue_tag.h @@ -26,25 +26,25 @@ namespace internal { class CompletionQueueTag { public: virtual ~CompletionQueueTag() {} - - /// FinalizeResult must be called before informing user code that the - /// operation bound to the underlying core completion queue tag has - /// completed. In practice, this means: - /// - /// 1. For the sync API - before returning from Pluck - /// 2. For the CQ-based async API - before returning from Next - /// 3. For the callback-based API - before invoking the user callback - /// - /// This is the method that translates from core-side tag/status to - /// C++ API-observable tag/status. - /// - /// The return value is the status of the operation (returning status is the - /// general behavior of this function). If this function returns false, the - /// tag is dropped and not returned from the completion queue: this concept is - /// for events that are observed at core but not requested by the user - /// application (e.g., server shutdown, for server unimplemented method - /// responses, or for cases where a server-side RPC doesn't have a completion - /// notification registered using AsyncNotifyWhenDone) + + /// FinalizeResult must be called before informing user code that the + /// operation bound to the underlying core completion queue tag has + /// completed. In practice, this means: + /// + /// 1. For the sync API - before returning from Pluck + /// 2. For the CQ-based async API - before returning from Next + /// 3. For the callback-based API - before invoking the user callback + /// + /// This is the method that translates from core-side tag/status to + /// C++ API-observable tag/status. + /// + /// The return value is the status of the operation (returning status is the + /// general behavior of this function). If this function returns false, the + /// tag is dropped and not returned from the completion queue: this concept is + /// for events that are observed at core but not requested by the user + /// application (e.g., server shutdown, for server unimplemented method + /// responses, or for cases where a server-side RPC doesn't have a completion + /// notification registered using AsyncNotifyWhenDone) virtual bool FinalizeResult(void** tag, bool* status) = 0; }; } // namespace internal diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/config_protobuf.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/config_protobuf.h index cb3088f985..c4012fb00c 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/config_protobuf.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/config_protobuf.h @@ -63,12 +63,12 @@ #define GRPC_CUSTOM_CODEDINPUTSTREAM ::google::protobuf::io::CodedInputStream #endif -#ifndef GRPC_CUSTOM_JSONUTIL +#ifndef GRPC_CUSTOM_JSONUTIL #include <google/protobuf/util/json_util.h> -#define GRPC_CUSTOM_JSONUTIL ::google::protobuf::util -#define GRPC_CUSTOM_UTIL_STATUS ::google::protobuf::util::Status -#endif - +#define GRPC_CUSTOM_JSONUTIL ::google::protobuf::util +#define GRPC_CUSTOM_UTIL_STATUS ::google::protobuf::util::Status +#endif + namespace grpc { namespace protobuf { @@ -86,12 +86,12 @@ typedef GRPC_CUSTOM_SERVICEDESCRIPTOR ServiceDescriptor; typedef GRPC_CUSTOM_SIMPLEDESCRIPTORDATABASE SimpleDescriptorDatabase; typedef GRPC_CUSTOM_SOURCELOCATION SourceLocation; -namespace util { -typedef GRPC_CUSTOM_UTIL_STATUS Status; -} // namespace util - -namespace json = GRPC_CUSTOM_JSONUTIL; - +namespace util { +typedef GRPC_CUSTOM_UTIL_STATUS Status; +} // namespace util + +namespace json = GRPC_CUSTOM_JSONUTIL; + namespace io { typedef GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM ZeroCopyOutputStream; typedef GRPC_CUSTOM_ZEROCOPYINPUTSTREAM ZeroCopyInputStream; diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen.h index f050930be7..50c8da4ffe 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen.h @@ -42,7 +42,7 @@ class CoreCodegen final : public CoreCodegenInterface { void* reserved) override; grpc_completion_queue* grpc_completion_queue_create_for_pluck( void* reserved) override; - void grpc_completion_queue_shutdown(grpc_completion_queue* cq) override; + void grpc_completion_queue_shutdown(grpc_completion_queue* cq) override; void grpc_completion_queue_destroy(grpc_completion_queue* cq) override; grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag, gpr_timespec deadline, @@ -64,9 +64,9 @@ class CoreCodegen final : public CoreCodegenInterface { void gpr_cv_signal(gpr_cv* cv) override; void gpr_cv_broadcast(gpr_cv* cv) override; - grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, - size_t nops, void* tag, - void* reserved) override; + grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, + size_t nops, void* tag, + void* reserved) override; grpc_call_error grpc_call_cancel_with_status(grpc_call* call, grpc_status_code status, const char* description, diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen_interface.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen_interface.h index 837948a583..c08cf6c683 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen_interface.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen_interface.h @@ -53,7 +53,7 @@ class CoreCodegenInterface { void* reserved) = 0; virtual grpc_completion_queue* grpc_completion_queue_create_for_pluck( void* reserved) = 0; - virtual void grpc_completion_queue_shutdown(grpc_completion_queue* cq) = 0; + virtual void grpc_completion_queue_shutdown(grpc_completion_queue* cq) = 0; virtual void grpc_completion_queue_destroy(grpc_completion_queue* cq) = 0; virtual grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag, @@ -104,9 +104,9 @@ class CoreCodegenInterface { virtual grpc_slice grpc_slice_new_with_len(void* p, size_t len, void (*destroy)(void*, size_t)) = 0; - virtual grpc_call_error grpc_call_start_batch(grpc_call* call, - const grpc_op* ops, size_t nops, - void* tag, void* reserved) = 0; + virtual grpc_call_error grpc_call_start_batch(grpc_call* call, + const grpc_op* ops, size_t nops, + void* tag, void* reserved) = 0; virtual grpc_call_error grpc_call_cancel_with_status(grpc_call* call, grpc_status_code status, const char* description, @@ -150,15 +150,15 @@ extern CoreCodegenInterface* g_core_codegen_interface; } \ } while (0) -/// Codegen specific version of \a GPR_DEBUG_ASSERT. -#ifndef NDEBUG -#define GPR_CODEGEN_DEBUG_ASSERT(x) GPR_CODEGEN_ASSERT(x) -#else -#define GPR_CODEGEN_DEBUG_ASSERT(x) \ - do { \ - } while (0) -#endif - +/// Codegen specific version of \a GPR_DEBUG_ASSERT. +#ifndef NDEBUG +#define GPR_CODEGEN_DEBUG_ASSERT(x) GPR_CODEGEN_ASSERT(x) +#else +#define GPR_CODEGEN_DEBUG_ASSERT(x) \ + do { \ + } while (0) +#endif + } // namespace grpc #endif // GRPCPP_IMPL_CODEGEN_CORE_CODEGEN_INTERFACE_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/intercepted_channel.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/intercepted_channel.h index d3472737ba..c729970ca8 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/intercepted_channel.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/intercepted_channel.h @@ -1,84 +1,84 @@ -/* - * - * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H -#define GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H - -#include <grpcpp/impl/codegen/channel_interface.h> - +/* + * + * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H +#define GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H + +#include <grpcpp/impl/codegen/channel_interface.h> + namespace grpc { class CompletionQueue; -namespace internal { - -class InterceptorBatchMethodsImpl; - -/// An InterceptedChannel is available to client Interceptors. An -/// InterceptedChannel is unique to an interceptor, and when an RPC is started -/// on this channel, only those interceptors that come after this interceptor -/// see the RPC. -class InterceptedChannel : public ChannelInterface { - public: - virtual ~InterceptedChannel() { channel_ = nullptr; } - - /// Get the current channel state. If the channel is in IDLE and - /// \a try_to_connect is set to true, try to connect. - grpc_connectivity_state GetState(bool try_to_connect) override { - return channel_->GetState(try_to_connect); - } - - private: - InterceptedChannel(ChannelInterface* channel, size_t pos) - : channel_(channel), interceptor_pos_(pos) {} - +namespace internal { + +class InterceptorBatchMethodsImpl; + +/// An InterceptedChannel is available to client Interceptors. An +/// InterceptedChannel is unique to an interceptor, and when an RPC is started +/// on this channel, only those interceptors that come after this interceptor +/// see the RPC. +class InterceptedChannel : public ChannelInterface { + public: + virtual ~InterceptedChannel() { channel_ = nullptr; } + + /// Get the current channel state. If the channel is in IDLE and + /// \a try_to_connect is set to true, try to connect. + grpc_connectivity_state GetState(bool try_to_connect) override { + return channel_->GetState(try_to_connect); + } + + private: + InterceptedChannel(ChannelInterface* channel, size_t pos) + : channel_(channel), interceptor_pos_(pos) {} + Call CreateCall(const RpcMethod& method, ::grpc::ClientContext* context, ::grpc::CompletionQueue* cq) override { - return channel_->CreateCallInternal(method, context, cq, interceptor_pos_); - } - - void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) override { - return channel_->PerformOpsOnCall(ops, call); - } - void* RegisterMethod(const char* method) override { - return channel_->RegisterMethod(method); - } - - void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed, + return channel_->CreateCallInternal(method, context, cq, interceptor_pos_); + } + + void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) override { + return channel_->PerformOpsOnCall(ops, call); + } + void* RegisterMethod(const char* method) override { + return channel_->RegisterMethod(method); + } + + void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed, gpr_timespec deadline, ::grpc::CompletionQueue* cq, - void* tag) override { - return channel_->NotifyOnStateChangeImpl(last_observed, deadline, cq, tag); - } - bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, - gpr_timespec deadline) override { - return channel_->WaitForStateChangeImpl(last_observed, deadline); - } - + void* tag) override { + return channel_->NotifyOnStateChangeImpl(last_observed, deadline, cq, tag); + } + bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, + gpr_timespec deadline) override { + return channel_->WaitForStateChangeImpl(last_observed, deadline); + } + ::grpc::CompletionQueue* CallbackCQ() override { return channel_->CallbackCQ(); } - - ChannelInterface* channel_; - size_t interceptor_pos_; - - friend class InterceptorBatchMethodsImpl; -}; -} // namespace internal -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H + + ChannelInterface* channel_; + size_t interceptor_pos_; + + friend class InterceptorBatchMethodsImpl; +}; +} // namespace internal +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h index 5c9cb78db5..d0afa03a17 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h @@ -1,228 +1,228 @@ -/* - * - * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H -#define GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H - +/* + * + * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H +#define GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H + #include <memory> -#include <grpc/impl/codegen/grpc_types.h> -#include <grpcpp/impl/codegen/byte_buffer.h> -#include <grpcpp/impl/codegen/config.h> -#include <grpcpp/impl/codegen/core_codegen_interface.h> -#include <grpcpp/impl/codegen/metadata_map.h> - -namespace grpc { - -class ChannelInterface; -class Status; - -namespace experimental { - -/// An enumeration of different possible points at which the \a Intercept -/// method of the \a Interceptor interface may be called. Any given call -/// to \a Intercept will include one or more of these hook points, and -/// each hook point makes certain types of information available to the -/// interceptor. -/// In these enumeration names, PRE_SEND means that an interception has taken -/// place between the time the application provided a certain type of data -/// (e.g., initial metadata, status) and the time that that data goes to the -/// other side. POST_SEND means that the data has been committed for going to -/// the other side (even if it has not yet been received at the other side). -/// PRE_RECV means an interception between the time that a certain -/// operation has been requested and it is available. POST_RECV means that a -/// result is available but has not yet been passed back to the application. -/// A batch of interception points will only contain either PRE or POST hooks -/// but not both types. For example, a batch with PRE_SEND hook points will not -/// contain POST_RECV or POST_SEND ops. Likewise, a batch with POST_* ops can -/// not contain PRE_* ops. -enum class InterceptionHookPoints { - /// The first three in this list are for clients and servers - PRE_SEND_INITIAL_METADATA, - PRE_SEND_MESSAGE, - POST_SEND_MESSAGE, - PRE_SEND_STATUS, // server only - PRE_SEND_CLOSE, // client only: WritesDone for stream; after write in unary - /// The following three are for hijacked clients only. A batch with PRE_RECV_* - /// hook points will never contain hook points of other types. - PRE_RECV_INITIAL_METADATA, - PRE_RECV_MESSAGE, - PRE_RECV_STATUS, - /// The following two are for all clients and servers - POST_RECV_INITIAL_METADATA, - POST_RECV_MESSAGE, - POST_RECV_STATUS, // client only - POST_RECV_CLOSE, // server only - /// This is a special hook point available to both clients and servers when - /// TryCancel() is performed. - /// - No other hook points will be present along with this. - /// - It is illegal for an interceptor to block/delay this operation. - /// - ALL interceptors see this hook point irrespective of whether the - /// RPC was hijacked or not. - PRE_SEND_CANCEL, - NUM_INTERCEPTION_HOOKS -}; - -/// Class that is passed as an argument to the \a Intercept method -/// of the application's \a Interceptor interface implementation. It has five -/// purposes: -/// 1. Indicate which hook points are present at a specific interception -/// 2. Allow an interceptor to inform the library that an RPC should -/// continue to the next stage of its processing (which may be another -/// interceptor or the main path of the library) -/// 3. Allow an interceptor to hijack the processing of the RPC (only for -/// client-side RPCs with PRE_SEND_INITIAL_METADATA) so that it does not -/// proceed with normal processing beyond that stage -/// 4. Access the relevant fields of an RPC at each interception point -/// 5. Set some fields of an RPC at each interception point, when possible -class InterceptorBatchMethods { - public: +#include <grpc/impl/codegen/grpc_types.h> +#include <grpcpp/impl/codegen/byte_buffer.h> +#include <grpcpp/impl/codegen/config.h> +#include <grpcpp/impl/codegen/core_codegen_interface.h> +#include <grpcpp/impl/codegen/metadata_map.h> + +namespace grpc { + +class ChannelInterface; +class Status; + +namespace experimental { + +/// An enumeration of different possible points at which the \a Intercept +/// method of the \a Interceptor interface may be called. Any given call +/// to \a Intercept will include one or more of these hook points, and +/// each hook point makes certain types of information available to the +/// interceptor. +/// In these enumeration names, PRE_SEND means that an interception has taken +/// place between the time the application provided a certain type of data +/// (e.g., initial metadata, status) and the time that that data goes to the +/// other side. POST_SEND means that the data has been committed for going to +/// the other side (even if it has not yet been received at the other side). +/// PRE_RECV means an interception between the time that a certain +/// operation has been requested and it is available. POST_RECV means that a +/// result is available but has not yet been passed back to the application. +/// A batch of interception points will only contain either PRE or POST hooks +/// but not both types. For example, a batch with PRE_SEND hook points will not +/// contain POST_RECV or POST_SEND ops. Likewise, a batch with POST_* ops can +/// not contain PRE_* ops. +enum class InterceptionHookPoints { + /// The first three in this list are for clients and servers + PRE_SEND_INITIAL_METADATA, + PRE_SEND_MESSAGE, + POST_SEND_MESSAGE, + PRE_SEND_STATUS, // server only + PRE_SEND_CLOSE, // client only: WritesDone for stream; after write in unary + /// The following three are for hijacked clients only. A batch with PRE_RECV_* + /// hook points will never contain hook points of other types. + PRE_RECV_INITIAL_METADATA, + PRE_RECV_MESSAGE, + PRE_RECV_STATUS, + /// The following two are for all clients and servers + POST_RECV_INITIAL_METADATA, + POST_RECV_MESSAGE, + POST_RECV_STATUS, // client only + POST_RECV_CLOSE, // server only + /// This is a special hook point available to both clients and servers when + /// TryCancel() is performed. + /// - No other hook points will be present along with this. + /// - It is illegal for an interceptor to block/delay this operation. + /// - ALL interceptors see this hook point irrespective of whether the + /// RPC was hijacked or not. + PRE_SEND_CANCEL, + NUM_INTERCEPTION_HOOKS +}; + +/// Class that is passed as an argument to the \a Intercept method +/// of the application's \a Interceptor interface implementation. It has five +/// purposes: +/// 1. Indicate which hook points are present at a specific interception +/// 2. Allow an interceptor to inform the library that an RPC should +/// continue to the next stage of its processing (which may be another +/// interceptor or the main path of the library) +/// 3. Allow an interceptor to hijack the processing of the RPC (only for +/// client-side RPCs with PRE_SEND_INITIAL_METADATA) so that it does not +/// proceed with normal processing beyond that stage +/// 4. Access the relevant fields of an RPC at each interception point +/// 5. Set some fields of an RPC at each interception point, when possible +class InterceptorBatchMethods { + public: virtual ~InterceptorBatchMethods() {} - /// Determine whether the current batch has an interception hook point - /// of type \a type - virtual bool QueryInterceptionHookPoint(InterceptionHookPoints type) = 0; - /// Signal that the interceptor is done intercepting the current batch of the - /// RPC. Every interceptor must either call Proceed or Hijack on each - /// interception. In most cases, only Proceed will be used. Explicit use of - /// Proceed is what enables interceptors to delay the processing of RPCs - /// while they perform other work. - /// Proceed is a no-op if the batch contains PRE_SEND_CANCEL. Simply returning - /// from the Intercept method does the job of continuing the RPC in this case. - /// This is because PRE_SEND_CANCEL is always in a separate batch and is not - /// allowed to be delayed. - virtual void Proceed() = 0; - /// Indicate that the interceptor has hijacked the RPC (only valid if the - /// batch contains send_initial_metadata on the client side). Later - /// interceptors in the interceptor list will not be called. Later batches - /// on the same RPC will go through interception, but only up to the point - /// of the hijacking interceptor. - virtual void Hijack() = 0; - - /// Send Message Methods - /// GetSerializedSendMessage and GetSendMessage/ModifySendMessage are the - /// available methods to view and modify the request payload. An interceptor - /// can access the payload in either serialized form or non-serialized form - /// but not both at the same time. - /// gRPC performs serialization in a lazy manner, which means - /// that a call to GetSerializedSendMessage will result in a serialization - /// operation if the payload stored is not in the serialized form already; the - /// non-serialized form will be lost and GetSendMessage will no longer return - /// a valid pointer, and this will remain true for later interceptors too. - /// This can change however if ModifySendMessage is used to replace the - /// current payload. Note that ModifySendMessage requires a new payload - /// message in the non-serialized form. This will overwrite the existing - /// payload irrespective of whether it had been serialized earlier. Also note - /// that gRPC Async API requires early serialization of the payload which - /// means that the payload would be available in the serialized form only - /// unless an interceptor replaces the payload with ModifySendMessage. - - /// Returns a modifable ByteBuffer holding the serialized form of the message - /// that is going to be sent. Valid for PRE_SEND_MESSAGE interceptions. - /// A return value of nullptr indicates that this ByteBuffer is not valid. - virtual ByteBuffer* GetSerializedSendMessage() = 0; - - /// Returns a non-modifiable pointer to the non-serialized form of the message - /// to be sent. Valid for PRE_SEND_MESSAGE interceptions. A return value of - /// nullptr indicates that this field is not valid. - virtual const void* GetSendMessage() = 0; - - /// Overwrites the message to be sent with \a message. \a message should be in - /// the non-serialized form expected by the method. Valid for PRE_SEND_MESSAGE - /// interceptions. Note that the interceptor is responsible for maintaining - /// the life of the message till it is serialized or it receives the - /// POST_SEND_MESSAGE interception point, whichever happens earlier. The - /// modifying interceptor may itself force early serialization by calling - /// GetSerializedSendMessage. - virtual void ModifySendMessage(const void* message) = 0; - - /// Checks whether the SEND MESSAGE op succeeded. Valid for POST_SEND_MESSAGE - /// interceptions. - virtual bool GetSendMessageStatus() = 0; - - /// Returns a modifiable multimap of the initial metadata to be sent. Valid - /// for PRE_SEND_INITIAL_METADATA interceptions. A value of nullptr indicates - /// that this field is not valid. + /// Determine whether the current batch has an interception hook point + /// of type \a type + virtual bool QueryInterceptionHookPoint(InterceptionHookPoints type) = 0; + /// Signal that the interceptor is done intercepting the current batch of the + /// RPC. Every interceptor must either call Proceed or Hijack on each + /// interception. In most cases, only Proceed will be used. Explicit use of + /// Proceed is what enables interceptors to delay the processing of RPCs + /// while they perform other work. + /// Proceed is a no-op if the batch contains PRE_SEND_CANCEL. Simply returning + /// from the Intercept method does the job of continuing the RPC in this case. + /// This is because PRE_SEND_CANCEL is always in a separate batch and is not + /// allowed to be delayed. + virtual void Proceed() = 0; + /// Indicate that the interceptor has hijacked the RPC (only valid if the + /// batch contains send_initial_metadata on the client side). Later + /// interceptors in the interceptor list will not be called. Later batches + /// on the same RPC will go through interception, but only up to the point + /// of the hijacking interceptor. + virtual void Hijack() = 0; + + /// Send Message Methods + /// GetSerializedSendMessage and GetSendMessage/ModifySendMessage are the + /// available methods to view and modify the request payload. An interceptor + /// can access the payload in either serialized form or non-serialized form + /// but not both at the same time. + /// gRPC performs serialization in a lazy manner, which means + /// that a call to GetSerializedSendMessage will result in a serialization + /// operation if the payload stored is not in the serialized form already; the + /// non-serialized form will be lost and GetSendMessage will no longer return + /// a valid pointer, and this will remain true for later interceptors too. + /// This can change however if ModifySendMessage is used to replace the + /// current payload. Note that ModifySendMessage requires a new payload + /// message in the non-serialized form. This will overwrite the existing + /// payload irrespective of whether it had been serialized earlier. Also note + /// that gRPC Async API requires early serialization of the payload which + /// means that the payload would be available in the serialized form only + /// unless an interceptor replaces the payload with ModifySendMessage. + + /// Returns a modifable ByteBuffer holding the serialized form of the message + /// that is going to be sent. Valid for PRE_SEND_MESSAGE interceptions. + /// A return value of nullptr indicates that this ByteBuffer is not valid. + virtual ByteBuffer* GetSerializedSendMessage() = 0; + + /// Returns a non-modifiable pointer to the non-serialized form of the message + /// to be sent. Valid for PRE_SEND_MESSAGE interceptions. A return value of + /// nullptr indicates that this field is not valid. + virtual const void* GetSendMessage() = 0; + + /// Overwrites the message to be sent with \a message. \a message should be in + /// the non-serialized form expected by the method. Valid for PRE_SEND_MESSAGE + /// interceptions. Note that the interceptor is responsible for maintaining + /// the life of the message till it is serialized or it receives the + /// POST_SEND_MESSAGE interception point, whichever happens earlier. The + /// modifying interceptor may itself force early serialization by calling + /// GetSerializedSendMessage. + virtual void ModifySendMessage(const void* message) = 0; + + /// Checks whether the SEND MESSAGE op succeeded. Valid for POST_SEND_MESSAGE + /// interceptions. + virtual bool GetSendMessageStatus() = 0; + + /// Returns a modifiable multimap of the initial metadata to be sent. Valid + /// for PRE_SEND_INITIAL_METADATA interceptions. A value of nullptr indicates + /// that this field is not valid. virtual std::multimap<TString, TString>* GetSendInitialMetadata() = 0; - - /// Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions. - virtual Status GetSendStatus() = 0; - - /// Overwrites the status with \a status. Valid for PRE_SEND_STATUS - /// interceptions. - virtual void ModifySendStatus(const Status& status) = 0; - - /// Returns a modifiable multimap of the trailing metadata to be sent. Valid - /// for PRE_SEND_STATUS interceptions. A value of nullptr indicates - /// that this field is not valid. + + /// Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions. + virtual Status GetSendStatus() = 0; + + /// Overwrites the status with \a status. Valid for PRE_SEND_STATUS + /// interceptions. + virtual void ModifySendStatus(const Status& status) = 0; + + /// Returns a modifiable multimap of the trailing metadata to be sent. Valid + /// for PRE_SEND_STATUS interceptions. A value of nullptr indicates + /// that this field is not valid. virtual std::multimap<TString, TString>* - GetSendTrailingMetadata() = 0; - - /// Returns a pointer to the modifiable received message. Note that the - /// message is already deserialized but the type is not set; the interceptor - /// should static_cast to the appropriate type before using it. This is valid + GetSendTrailingMetadata() = 0; + + /// Returns a pointer to the modifiable received message. Note that the + /// message is already deserialized but the type is not set; the interceptor + /// should static_cast to the appropriate type before using it. This is valid /// for PRE_RECV_MESSAGE and POST_RECV_MESSAGE interceptions; nullptr for not /// valid - virtual void* GetRecvMessage() = 0; - - /// Returns a modifiable multimap of the received initial metadata. + virtual void* GetRecvMessage() = 0; + + /// Returns a modifiable multimap of the received initial metadata. /// Valid for PRE_RECV_INITIAL_METADATA and POST_RECV_INITIAL_METADATA /// interceptions; nullptr if not valid - virtual std::multimap<grpc::string_ref, grpc::string_ref>* - GetRecvInitialMetadata() = 0; - + virtual std::multimap<grpc::string_ref, grpc::string_ref>* + GetRecvInitialMetadata() = 0; + /// Returns a modifiable view of the received status on PRE_RECV_STATUS and /// POST_RECV_STATUS interceptions; nullptr if not valid. - virtual Status* GetRecvStatus() = 0; - - /// Returns a modifiable multimap of the received trailing metadata on + virtual Status* GetRecvStatus() = 0; + + /// Returns a modifiable multimap of the received trailing metadata on /// PRE_RECV_STATUS and POST_RECV_STATUS interceptions; nullptr if not valid - virtual std::multimap<grpc::string_ref, grpc::string_ref>* - GetRecvTrailingMetadata() = 0; - - /// Gets an intercepted channel. When a call is started on this interceptor, - /// only interceptors after the current interceptor are created from the - /// factory objects registered with the channel. This allows calls to be - /// started from interceptors without infinite regress through the interceptor - /// list. - virtual std::unique_ptr<ChannelInterface> GetInterceptedChannel() = 0; - - /// On a hijacked RPC, an interceptor can decide to fail a PRE_RECV_MESSAGE - /// op. This would be a signal to the reader that there will be no more - /// messages, or the stream has failed or been cancelled. - virtual void FailHijackedRecvMessage() = 0; - - /// On a hijacked RPC/ to-be hijacked RPC, this can be called to fail a SEND - /// MESSAGE op - virtual void FailHijackedSendMessage() = 0; -}; - -/// Interface for an interceptor. Interceptor authors must create a class -/// that derives from this parent class. -class Interceptor { - public: - virtual ~Interceptor() {} - - /// The one public method of an Interceptor interface. Override this to - /// trigger the desired actions at the hook points described above. - virtual void Intercept(InterceptorBatchMethods* methods) = 0; -}; - -} // namespace experimental -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H + virtual std::multimap<grpc::string_ref, grpc::string_ref>* + GetRecvTrailingMetadata() = 0; + + /// Gets an intercepted channel. When a call is started on this interceptor, + /// only interceptors after the current interceptor are created from the + /// factory objects registered with the channel. This allows calls to be + /// started from interceptors without infinite regress through the interceptor + /// list. + virtual std::unique_ptr<ChannelInterface> GetInterceptedChannel() = 0; + + /// On a hijacked RPC, an interceptor can decide to fail a PRE_RECV_MESSAGE + /// op. This would be a signal to the reader that there will be no more + /// messages, or the stream has failed or been cancelled. + virtual void FailHijackedRecvMessage() = 0; + + /// On a hijacked RPC/ to-be hijacked RPC, this can be called to fail a SEND + /// MESSAGE op + virtual void FailHijackedSendMessage() = 0; +}; + +/// Interface for an interceptor. Interceptor authors must create a class +/// that derives from this parent class. +class Interceptor { + public: + virtual ~Interceptor() {} + + /// The one public method of an Interceptor interface. Override this to + /// trigger the desired actions at the hook points described above. + virtual void Intercept(InterceptorBatchMethods* methods) = 0; +}; + +} // namespace experimental +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor_common.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor_common.h index 62c879fdec..714351f543 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor_common.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor_common.h @@ -1,558 +1,558 @@ -/* - * - * Copyright 2018 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. - * - */ - -#if defined(__GNUC__) -#pragma GCC system_header -#endif - -#ifndef GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H -#define GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H - -#include <array> -#include <functional> - -#include <grpcpp/impl/codegen/call.h> -#include <grpcpp/impl/codegen/call_op_set_interface.h> -#include <grpcpp/impl/codegen/client_interceptor.h> -#include <grpcpp/impl/codegen/intercepted_channel.h> -#include <grpcpp/impl/codegen/server_interceptor.h> - -#include <grpc/impl/codegen/grpc_types.h> - -namespace grpc { -namespace internal { - -class InterceptorBatchMethodsImpl - : public experimental::InterceptorBatchMethods { - public: - InterceptorBatchMethodsImpl() { - for (auto i = static_cast<experimental::InterceptionHookPoints>(0); - i < experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS; - i = static_cast<experimental::InterceptionHookPoints>( - static_cast<size_t>(i) + 1)) { - hooks_[static_cast<size_t>(i)] = false; - } - } - - ~InterceptorBatchMethodsImpl() {} - - bool QueryInterceptionHookPoint( - experimental::InterceptionHookPoints type) override { - return hooks_[static_cast<size_t>(type)]; - } - - void Proceed() override { - if (call_->client_rpc_info() != nullptr) { - return ProceedClient(); - } - GPR_CODEGEN_ASSERT(call_->server_rpc_info() != nullptr); - ProceedServer(); - } - - void Hijack() override { - // Only the client can hijack when sending down initial metadata - GPR_CODEGEN_ASSERT(!reverse_ && ops_ != nullptr && - call_->client_rpc_info() != nullptr); - // It is illegal to call Hijack twice - GPR_CODEGEN_ASSERT(!ran_hijacking_interceptor_); - auto* rpc_info = call_->client_rpc_info(); - rpc_info->hijacked_ = true; - rpc_info->hijacked_interceptor_ = current_interceptor_index_; - ClearHookPoints(); - ops_->SetHijackingState(); - ran_hijacking_interceptor_ = true; - rpc_info->RunInterceptor(this, current_interceptor_index_); - } - - void AddInterceptionHookPoint(experimental::InterceptionHookPoints type) { - hooks_[static_cast<size_t>(type)] = true; - } - - ByteBuffer* GetSerializedSendMessage() override { - GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); - if (*orig_send_message_ != nullptr) { - GPR_CODEGEN_ASSERT(serializer_(*orig_send_message_).ok()); - *orig_send_message_ = nullptr; - } - return send_message_; - } - - const void* GetSendMessage() override { - GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); - return *orig_send_message_; - } - - void ModifySendMessage(const void* message) override { - GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); - *orig_send_message_ = message; - } - - bool GetSendMessageStatus() override { return !*fail_send_message_; } - +/* + * + * Copyright 2018 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. + * + */ + +#if defined(__GNUC__) +#pragma GCC system_header +#endif + +#ifndef GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H +#define GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H + +#include <array> +#include <functional> + +#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/codegen/call_op_set_interface.h> +#include <grpcpp/impl/codegen/client_interceptor.h> +#include <grpcpp/impl/codegen/intercepted_channel.h> +#include <grpcpp/impl/codegen/server_interceptor.h> + +#include <grpc/impl/codegen/grpc_types.h> + +namespace grpc { +namespace internal { + +class InterceptorBatchMethodsImpl + : public experimental::InterceptorBatchMethods { + public: + InterceptorBatchMethodsImpl() { + for (auto i = static_cast<experimental::InterceptionHookPoints>(0); + i < experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS; + i = static_cast<experimental::InterceptionHookPoints>( + static_cast<size_t>(i) + 1)) { + hooks_[static_cast<size_t>(i)] = false; + } + } + + ~InterceptorBatchMethodsImpl() {} + + bool QueryInterceptionHookPoint( + experimental::InterceptionHookPoints type) override { + return hooks_[static_cast<size_t>(type)]; + } + + void Proceed() override { + if (call_->client_rpc_info() != nullptr) { + return ProceedClient(); + } + GPR_CODEGEN_ASSERT(call_->server_rpc_info() != nullptr); + ProceedServer(); + } + + void Hijack() override { + // Only the client can hijack when sending down initial metadata + GPR_CODEGEN_ASSERT(!reverse_ && ops_ != nullptr && + call_->client_rpc_info() != nullptr); + // It is illegal to call Hijack twice + GPR_CODEGEN_ASSERT(!ran_hijacking_interceptor_); + auto* rpc_info = call_->client_rpc_info(); + rpc_info->hijacked_ = true; + rpc_info->hijacked_interceptor_ = current_interceptor_index_; + ClearHookPoints(); + ops_->SetHijackingState(); + ran_hijacking_interceptor_ = true; + rpc_info->RunInterceptor(this, current_interceptor_index_); + } + + void AddInterceptionHookPoint(experimental::InterceptionHookPoints type) { + hooks_[static_cast<size_t>(type)] = true; + } + + ByteBuffer* GetSerializedSendMessage() override { + GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); + if (*orig_send_message_ != nullptr) { + GPR_CODEGEN_ASSERT(serializer_(*orig_send_message_).ok()); + *orig_send_message_ = nullptr; + } + return send_message_; + } + + const void* GetSendMessage() override { + GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); + return *orig_send_message_; + } + + void ModifySendMessage(const void* message) override { + GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); + *orig_send_message_ = message; + } + + bool GetSendMessageStatus() override { return !*fail_send_message_; } + std::multimap<TString, TString>* GetSendInitialMetadata() override { - return send_initial_metadata_; - } - - Status GetSendStatus() override { - return Status(static_cast<StatusCode>(*code_), *error_message_, - *error_details_); - } - - void ModifySendStatus(const Status& status) override { - *code_ = static_cast<grpc_status_code>(status.error_code()); - *error_details_ = status.error_details(); - *error_message_ = status.error_message(); - } - + return send_initial_metadata_; + } + + Status GetSendStatus() override { + return Status(static_cast<StatusCode>(*code_), *error_message_, + *error_details_); + } + + void ModifySendStatus(const Status& status) override { + *code_ = static_cast<grpc_status_code>(status.error_code()); + *error_details_ = status.error_details(); + *error_message_ = status.error_message(); + } + std::multimap<TString, TString>* GetSendTrailingMetadata() override { - return send_trailing_metadata_; - } - - void* GetRecvMessage() override { return recv_message_; } - - std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvInitialMetadata() - override { - return recv_initial_metadata_->map(); - } - - Status* GetRecvStatus() override { return recv_status_; } - - void FailHijackedSendMessage() override { - GPR_CODEGEN_ASSERT(hooks_[static_cast<size_t>( - experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)]); - *fail_send_message_ = true; - } - - std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvTrailingMetadata() - override { - return recv_trailing_metadata_->map(); - } - - void SetSendMessage(ByteBuffer* buf, const void** msg, - bool* fail_send_message, - std::function<Status(const void*)> serializer) { - send_message_ = buf; - orig_send_message_ = msg; - fail_send_message_ = fail_send_message; - serializer_ = serializer; - } - - void SetSendInitialMetadata( + return send_trailing_metadata_; + } + + void* GetRecvMessage() override { return recv_message_; } + + std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvInitialMetadata() + override { + return recv_initial_metadata_->map(); + } + + Status* GetRecvStatus() override { return recv_status_; } + + void FailHijackedSendMessage() override { + GPR_CODEGEN_ASSERT(hooks_[static_cast<size_t>( + experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)]); + *fail_send_message_ = true; + } + + std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvTrailingMetadata() + override { + return recv_trailing_metadata_->map(); + } + + void SetSendMessage(ByteBuffer* buf, const void** msg, + bool* fail_send_message, + std::function<Status(const void*)> serializer) { + send_message_ = buf; + orig_send_message_ = msg; + fail_send_message_ = fail_send_message; + serializer_ = serializer; + } + + void SetSendInitialMetadata( std::multimap<TString, TString>* metadata) { - send_initial_metadata_ = metadata; - } - + send_initial_metadata_ = metadata; + } + void SetSendStatus(grpc_status_code* code, TString* error_details, TString* error_message) { - code_ = code; - error_details_ = error_details; - error_message_ = error_message; - } - - void SetSendTrailingMetadata( + code_ = code; + error_details_ = error_details; + error_message_ = error_message; + } + + void SetSendTrailingMetadata( std::multimap<TString, TString>* metadata) { - send_trailing_metadata_ = metadata; - } - + send_trailing_metadata_ = metadata; + } + void SetRecvMessage(void* message, bool* hijacked_recv_message_failed) { - recv_message_ = message; + recv_message_ = message; hijacked_recv_message_failed_ = hijacked_recv_message_failed; - } - - void SetRecvInitialMetadata(MetadataMap* map) { - recv_initial_metadata_ = map; - } - - void SetRecvStatus(Status* status) { recv_status_ = status; } - - void SetRecvTrailingMetadata(MetadataMap* map) { - recv_trailing_metadata_ = map; - } - - std::unique_ptr<ChannelInterface> GetInterceptedChannel() override { - auto* info = call_->client_rpc_info(); - if (info == nullptr) { - return std::unique_ptr<ChannelInterface>(nullptr); - } - // The intercepted channel starts from the interceptor just after the - // current interceptor - return std::unique_ptr<ChannelInterface>(new InterceptedChannel( - info->channel(), current_interceptor_index_ + 1)); - } - - void FailHijackedRecvMessage() override { - GPR_CODEGEN_ASSERT(hooks_[static_cast<size_t>( - experimental::InterceptionHookPoints::PRE_RECV_MESSAGE)]); + } + + void SetRecvInitialMetadata(MetadataMap* map) { + recv_initial_metadata_ = map; + } + + void SetRecvStatus(Status* status) { recv_status_ = status; } + + void SetRecvTrailingMetadata(MetadataMap* map) { + recv_trailing_metadata_ = map; + } + + std::unique_ptr<ChannelInterface> GetInterceptedChannel() override { + auto* info = call_->client_rpc_info(); + if (info == nullptr) { + return std::unique_ptr<ChannelInterface>(nullptr); + } + // The intercepted channel starts from the interceptor just after the + // current interceptor + return std::unique_ptr<ChannelInterface>(new InterceptedChannel( + info->channel(), current_interceptor_index_ + 1)); + } + + void FailHijackedRecvMessage() override { + GPR_CODEGEN_ASSERT(hooks_[static_cast<size_t>( + experimental::InterceptionHookPoints::PRE_RECV_MESSAGE)]); *hijacked_recv_message_failed_ = true; - } - - // Clears all state - void ClearState() { - reverse_ = false; - ran_hijacking_interceptor_ = false; - ClearHookPoints(); - } - - // Prepares for Post_recv operations - void SetReverse() { - reverse_ = true; - ran_hijacking_interceptor_ = false; - ClearHookPoints(); - } - - // This needs to be set before interceptors are run - void SetCall(Call* call) { call_ = call; } - - // This needs to be set before interceptors are run using RunInterceptors(). - // Alternatively, RunInterceptors(std::function<void(void)> f) can be used. - void SetCallOpSetInterface(CallOpSetInterface* ops) { ops_ = ops; } - - // SetCall should have been called before this. - // Returns true if the interceptors list is empty - bool InterceptorsListEmpty() { - auto* client_rpc_info = call_->client_rpc_info(); - if (client_rpc_info != nullptr) { - if (client_rpc_info->interceptors_.size() == 0) { - return true; - } else { - return false; - } - } - - auto* server_rpc_info = call_->server_rpc_info(); - if (server_rpc_info == nullptr || - server_rpc_info->interceptors_.size() == 0) { - return true; - } - return false; - } - - // This should be used only by subclasses of CallOpSetInterface. SetCall and - // SetCallOpSetInterface should have been called before this. After all the - // interceptors are done running, either ContinueFillOpsAfterInterception or - // ContinueFinalizeOpsAfterInterception will be called. Note that neither of - // them is invoked if there were no interceptors registered. - bool RunInterceptors() { - GPR_CODEGEN_ASSERT(ops_); - auto* client_rpc_info = call_->client_rpc_info(); - if (client_rpc_info != nullptr) { - if (client_rpc_info->interceptors_.size() == 0) { - return true; - } else { - RunClientInterceptors(); - return false; - } - } - - auto* server_rpc_info = call_->server_rpc_info(); - if (server_rpc_info == nullptr || - server_rpc_info->interceptors_.size() == 0) { - return true; - } - RunServerInterceptors(); - return false; - } - - // Returns true if no interceptors are run. Returns false otherwise if there - // are interceptors registered. After the interceptors are done running \a f - // will be invoked. This is to be used only by BaseAsyncRequest and - // SyncRequest. - bool RunInterceptors(std::function<void(void)> f) { - // This is used only by the server for initial call request - GPR_CODEGEN_ASSERT(reverse_ == true); - GPR_CODEGEN_ASSERT(call_->client_rpc_info() == nullptr); - auto* server_rpc_info = call_->server_rpc_info(); - if (server_rpc_info == nullptr || - server_rpc_info->interceptors_.size() == 0) { - return true; - } - callback_ = std::move(f); - RunServerInterceptors(); - return false; - } - - private: - void RunClientInterceptors() { - auto* rpc_info = call_->client_rpc_info(); - if (!reverse_) { - current_interceptor_index_ = 0; - } else { - if (rpc_info->hijacked_) { - current_interceptor_index_ = rpc_info->hijacked_interceptor_; - } else { - current_interceptor_index_ = rpc_info->interceptors_.size() - 1; - } - } - rpc_info->RunInterceptor(this, current_interceptor_index_); - } - - void RunServerInterceptors() { - auto* rpc_info = call_->server_rpc_info(); - if (!reverse_) { - current_interceptor_index_ = 0; - } else { - current_interceptor_index_ = rpc_info->interceptors_.size() - 1; - } - rpc_info->RunInterceptor(this, current_interceptor_index_); - } - - void ProceedClient() { - auto* rpc_info = call_->client_rpc_info(); - if (rpc_info->hijacked_ && !reverse_ && - current_interceptor_index_ == rpc_info->hijacked_interceptor_ && - !ran_hijacking_interceptor_) { - // We now need to provide hijacked recv ops to this interceptor - ClearHookPoints(); - ops_->SetHijackingState(); - ran_hijacking_interceptor_ = true; - rpc_info->RunInterceptor(this, current_interceptor_index_); - return; - } - if (!reverse_) { - current_interceptor_index_++; - // We are going down the stack of interceptors - if (current_interceptor_index_ < rpc_info->interceptors_.size()) { - if (rpc_info->hijacked_ && - current_interceptor_index_ > rpc_info->hijacked_interceptor_) { - // This is a hijacked RPC and we are done with hijacking - ops_->ContinueFillOpsAfterInterception(); - } else { - rpc_info->RunInterceptor(this, current_interceptor_index_); - } - } else { - // we are done running all the interceptors without any hijacking - ops_->ContinueFillOpsAfterInterception(); - } - } else { - // We are going up the stack of interceptors - if (current_interceptor_index_ > 0) { - // Continue running interceptors - current_interceptor_index_--; - rpc_info->RunInterceptor(this, current_interceptor_index_); - } else { - // we are done running all the interceptors without any hijacking - ops_->ContinueFinalizeResultAfterInterception(); - } - } - } - - void ProceedServer() { - auto* rpc_info = call_->server_rpc_info(); - if (!reverse_) { - current_interceptor_index_++; - if (current_interceptor_index_ < rpc_info->interceptors_.size()) { - return rpc_info->RunInterceptor(this, current_interceptor_index_); - } else if (ops_) { - return ops_->ContinueFillOpsAfterInterception(); - } - } else { - // We are going up the stack of interceptors - if (current_interceptor_index_ > 0) { - // Continue running interceptors - current_interceptor_index_--; - return rpc_info->RunInterceptor(this, current_interceptor_index_); - } else if (ops_) { - return ops_->ContinueFinalizeResultAfterInterception(); - } - } - GPR_CODEGEN_ASSERT(callback_); - callback_(); - } - - void ClearHookPoints() { - for (auto i = static_cast<experimental::InterceptionHookPoints>(0); - i < experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS; - i = static_cast<experimental::InterceptionHookPoints>( - static_cast<size_t>(i) + 1)) { - hooks_[static_cast<size_t>(i)] = false; - } - } - - std::array<bool, - static_cast<size_t>( - experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS)> - hooks_; - - size_t current_interceptor_index_ = 0; // Current iterator - bool reverse_ = false; - bool ran_hijacking_interceptor_ = false; - Call* call_ = nullptr; // The Call object is present along with CallOpSet - // object/callback - CallOpSetInterface* ops_ = nullptr; - std::function<void(void)> callback_; - - ByteBuffer* send_message_ = nullptr; - bool* fail_send_message_ = nullptr; - const void** orig_send_message_ = nullptr; - std::function<Status(const void*)> serializer_; - + } + + // Clears all state + void ClearState() { + reverse_ = false; + ran_hijacking_interceptor_ = false; + ClearHookPoints(); + } + + // Prepares for Post_recv operations + void SetReverse() { + reverse_ = true; + ran_hijacking_interceptor_ = false; + ClearHookPoints(); + } + + // This needs to be set before interceptors are run + void SetCall(Call* call) { call_ = call; } + + // This needs to be set before interceptors are run using RunInterceptors(). + // Alternatively, RunInterceptors(std::function<void(void)> f) can be used. + void SetCallOpSetInterface(CallOpSetInterface* ops) { ops_ = ops; } + + // SetCall should have been called before this. + // Returns true if the interceptors list is empty + bool InterceptorsListEmpty() { + auto* client_rpc_info = call_->client_rpc_info(); + if (client_rpc_info != nullptr) { + if (client_rpc_info->interceptors_.size() == 0) { + return true; + } else { + return false; + } + } + + auto* server_rpc_info = call_->server_rpc_info(); + if (server_rpc_info == nullptr || + server_rpc_info->interceptors_.size() == 0) { + return true; + } + return false; + } + + // This should be used only by subclasses of CallOpSetInterface. SetCall and + // SetCallOpSetInterface should have been called before this. After all the + // interceptors are done running, either ContinueFillOpsAfterInterception or + // ContinueFinalizeOpsAfterInterception will be called. Note that neither of + // them is invoked if there were no interceptors registered. + bool RunInterceptors() { + GPR_CODEGEN_ASSERT(ops_); + auto* client_rpc_info = call_->client_rpc_info(); + if (client_rpc_info != nullptr) { + if (client_rpc_info->interceptors_.size() == 0) { + return true; + } else { + RunClientInterceptors(); + return false; + } + } + + auto* server_rpc_info = call_->server_rpc_info(); + if (server_rpc_info == nullptr || + server_rpc_info->interceptors_.size() == 0) { + return true; + } + RunServerInterceptors(); + return false; + } + + // Returns true if no interceptors are run. Returns false otherwise if there + // are interceptors registered. After the interceptors are done running \a f + // will be invoked. This is to be used only by BaseAsyncRequest and + // SyncRequest. + bool RunInterceptors(std::function<void(void)> f) { + // This is used only by the server for initial call request + GPR_CODEGEN_ASSERT(reverse_ == true); + GPR_CODEGEN_ASSERT(call_->client_rpc_info() == nullptr); + auto* server_rpc_info = call_->server_rpc_info(); + if (server_rpc_info == nullptr || + server_rpc_info->interceptors_.size() == 0) { + return true; + } + callback_ = std::move(f); + RunServerInterceptors(); + return false; + } + + private: + void RunClientInterceptors() { + auto* rpc_info = call_->client_rpc_info(); + if (!reverse_) { + current_interceptor_index_ = 0; + } else { + if (rpc_info->hijacked_) { + current_interceptor_index_ = rpc_info->hijacked_interceptor_; + } else { + current_interceptor_index_ = rpc_info->interceptors_.size() - 1; + } + } + rpc_info->RunInterceptor(this, current_interceptor_index_); + } + + void RunServerInterceptors() { + auto* rpc_info = call_->server_rpc_info(); + if (!reverse_) { + current_interceptor_index_ = 0; + } else { + current_interceptor_index_ = rpc_info->interceptors_.size() - 1; + } + rpc_info->RunInterceptor(this, current_interceptor_index_); + } + + void ProceedClient() { + auto* rpc_info = call_->client_rpc_info(); + if (rpc_info->hijacked_ && !reverse_ && + current_interceptor_index_ == rpc_info->hijacked_interceptor_ && + !ran_hijacking_interceptor_) { + // We now need to provide hijacked recv ops to this interceptor + ClearHookPoints(); + ops_->SetHijackingState(); + ran_hijacking_interceptor_ = true; + rpc_info->RunInterceptor(this, current_interceptor_index_); + return; + } + if (!reverse_) { + current_interceptor_index_++; + // We are going down the stack of interceptors + if (current_interceptor_index_ < rpc_info->interceptors_.size()) { + if (rpc_info->hijacked_ && + current_interceptor_index_ > rpc_info->hijacked_interceptor_) { + // This is a hijacked RPC and we are done with hijacking + ops_->ContinueFillOpsAfterInterception(); + } else { + rpc_info->RunInterceptor(this, current_interceptor_index_); + } + } else { + // we are done running all the interceptors without any hijacking + ops_->ContinueFillOpsAfterInterception(); + } + } else { + // We are going up the stack of interceptors + if (current_interceptor_index_ > 0) { + // Continue running interceptors + current_interceptor_index_--; + rpc_info->RunInterceptor(this, current_interceptor_index_); + } else { + // we are done running all the interceptors without any hijacking + ops_->ContinueFinalizeResultAfterInterception(); + } + } + } + + void ProceedServer() { + auto* rpc_info = call_->server_rpc_info(); + if (!reverse_) { + current_interceptor_index_++; + if (current_interceptor_index_ < rpc_info->interceptors_.size()) { + return rpc_info->RunInterceptor(this, current_interceptor_index_); + } else if (ops_) { + return ops_->ContinueFillOpsAfterInterception(); + } + } else { + // We are going up the stack of interceptors + if (current_interceptor_index_ > 0) { + // Continue running interceptors + current_interceptor_index_--; + return rpc_info->RunInterceptor(this, current_interceptor_index_); + } else if (ops_) { + return ops_->ContinueFinalizeResultAfterInterception(); + } + } + GPR_CODEGEN_ASSERT(callback_); + callback_(); + } + + void ClearHookPoints() { + for (auto i = static_cast<experimental::InterceptionHookPoints>(0); + i < experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS; + i = static_cast<experimental::InterceptionHookPoints>( + static_cast<size_t>(i) + 1)) { + hooks_[static_cast<size_t>(i)] = false; + } + } + + std::array<bool, + static_cast<size_t>( + experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS)> + hooks_; + + size_t current_interceptor_index_ = 0; // Current iterator + bool reverse_ = false; + bool ran_hijacking_interceptor_ = false; + Call* call_ = nullptr; // The Call object is present along with CallOpSet + // object/callback + CallOpSetInterface* ops_ = nullptr; + std::function<void(void)> callback_; + + ByteBuffer* send_message_ = nullptr; + bool* fail_send_message_ = nullptr; + const void** orig_send_message_ = nullptr; + std::function<Status(const void*)> serializer_; + std::multimap<TString, TString>* send_initial_metadata_; - - grpc_status_code* code_ = nullptr; + + grpc_status_code* code_ = nullptr; TString* error_details_ = nullptr; TString* error_message_ = nullptr; - + std::multimap<TString, TString>* send_trailing_metadata_ = nullptr; - - void* recv_message_ = nullptr; + + void* recv_message_ = nullptr; bool* hijacked_recv_message_failed_ = nullptr; - - MetadataMap* recv_initial_metadata_ = nullptr; - - Status* recv_status_ = nullptr; - - MetadataMap* recv_trailing_metadata_ = nullptr; -}; - -// A special implementation of InterceptorBatchMethods to send a Cancel -// notification down the interceptor stack -class CancelInterceptorBatchMethods - : public experimental::InterceptorBatchMethods { - public: - bool QueryInterceptionHookPoint( - experimental::InterceptionHookPoints type) override { - if (type == experimental::InterceptionHookPoints::PRE_SEND_CANCEL) { - return true; - } else { - return false; - } - } - - void Proceed() override { - // This is a no-op. For actual continuation of the RPC simply needs to - // return from the Intercept method - } - - void Hijack() override { - // Only the client can hijack when sending down initial metadata - GPR_CODEGEN_ASSERT(false && - "It is illegal to call Hijack on a method which has a " - "Cancel notification"); - } - - ByteBuffer* GetSerializedSendMessage() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetSendMessage on a method which " - "has a Cancel notification"); - return nullptr; - } - - bool GetSendMessageStatus() override { - GPR_CODEGEN_ASSERT( - false && - "It is illegal to call GetSendMessageStatus on a method which " - "has a Cancel notification"); - return false; - } - - const void* GetSendMessage() override { - GPR_CODEGEN_ASSERT( - false && - "It is illegal to call GetOriginalSendMessage on a method which " - "has a Cancel notification"); - return nullptr; - } - + + MetadataMap* recv_initial_metadata_ = nullptr; + + Status* recv_status_ = nullptr; + + MetadataMap* recv_trailing_metadata_ = nullptr; +}; + +// A special implementation of InterceptorBatchMethods to send a Cancel +// notification down the interceptor stack +class CancelInterceptorBatchMethods + : public experimental::InterceptorBatchMethods { + public: + bool QueryInterceptionHookPoint( + experimental::InterceptionHookPoints type) override { + if (type == experimental::InterceptionHookPoints::PRE_SEND_CANCEL) { + return true; + } else { + return false; + } + } + + void Proceed() override { + // This is a no-op. For actual continuation of the RPC simply needs to + // return from the Intercept method + } + + void Hijack() override { + // Only the client can hijack when sending down initial metadata + GPR_CODEGEN_ASSERT(false && + "It is illegal to call Hijack on a method which has a " + "Cancel notification"); + } + + ByteBuffer* GetSerializedSendMessage() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetSendMessage on a method which " + "has a Cancel notification"); + return nullptr; + } + + bool GetSendMessageStatus() override { + GPR_CODEGEN_ASSERT( + false && + "It is illegal to call GetSendMessageStatus on a method which " + "has a Cancel notification"); + return false; + } + + const void* GetSendMessage() override { + GPR_CODEGEN_ASSERT( + false && + "It is illegal to call GetOriginalSendMessage on a method which " + "has a Cancel notification"); + return nullptr; + } + void ModifySendMessage(const void* /*message*/) override { - GPR_CODEGEN_ASSERT( - false && - "It is illegal to call ModifySendMessage on a method which " - "has a Cancel notification"); - } - + GPR_CODEGEN_ASSERT( + false && + "It is illegal to call ModifySendMessage on a method which " + "has a Cancel notification"); + } + std::multimap<TString, TString>* GetSendInitialMetadata() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetSendInitialMetadata on a " - "method which has a Cancel notification"); - return nullptr; - } - - Status GetSendStatus() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetSendStatus on a method which " - "has a Cancel notification"); - return Status(); - } - + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetSendInitialMetadata on a " + "method which has a Cancel notification"); + return nullptr; + } + + Status GetSendStatus() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetSendStatus on a method which " + "has a Cancel notification"); + return Status(); + } + void ModifySendStatus(const Status& /*status*/) override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call ModifySendStatus on a method " - "which has a Cancel notification"); - return; - } - + GPR_CODEGEN_ASSERT(false && + "It is illegal to call ModifySendStatus on a method " + "which has a Cancel notification"); + return; + } + std::multimap<TString, TString>* GetSendTrailingMetadata() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetSendTrailingMetadata on a " - "method which has a Cancel notification"); - return nullptr; - } - - void* GetRecvMessage() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetRecvMessage on a method which " - "has a Cancel notification"); - return nullptr; - } - - std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvInitialMetadata() - override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetRecvInitialMetadata on a " - "method which has a Cancel notification"); - return nullptr; - } - - Status* GetRecvStatus() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetRecvStatus on a method which " - "has a Cancel notification"); - return nullptr; - } - - std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvTrailingMetadata() - override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetRecvTrailingMetadata on a " - "method which has a Cancel notification"); - return nullptr; - } - - std::unique_ptr<ChannelInterface> GetInterceptedChannel() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetInterceptedChannel on a " - "method which has a Cancel notification"); - return std::unique_ptr<ChannelInterface>(nullptr); - } - - void FailHijackedRecvMessage() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call FailHijackedRecvMessage on a " - "method which has a Cancel notification"); - } - - void FailHijackedSendMessage() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call FailHijackedSendMessage on a " - "method which has a Cancel notification"); - } -}; -} // namespace internal -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetSendTrailingMetadata on a " + "method which has a Cancel notification"); + return nullptr; + } + + void* GetRecvMessage() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetRecvMessage on a method which " + "has a Cancel notification"); + return nullptr; + } + + std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvInitialMetadata() + override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetRecvInitialMetadata on a " + "method which has a Cancel notification"); + return nullptr; + } + + Status* GetRecvStatus() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetRecvStatus on a method which " + "has a Cancel notification"); + return nullptr; + } + + std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvTrailingMetadata() + override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetRecvTrailingMetadata on a " + "method which has a Cancel notification"); + return nullptr; + } + + std::unique_ptr<ChannelInterface> GetInterceptedChannel() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetInterceptedChannel on a " + "method which has a Cancel notification"); + return std::unique_ptr<ChannelInterface>(nullptr); + } + + void FailHijackedRecvMessage() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call FailHijackedRecvMessage on a " + "method which has a Cancel notification"); + } + + void FailHijackedSendMessage() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call FailHijackedSendMessage on a " + "method which has a Cancel notification"); + } +}; +} // namespace internal +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/metadata_map.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/metadata_map.h index 4ad0727ef8..03afc0781a 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/metadata_map.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/metadata_map.h @@ -19,77 +19,77 @@ #ifndef GRPCPP_IMPL_CODEGEN_METADATA_MAP_H #define GRPCPP_IMPL_CODEGEN_METADATA_MAP_H -#include <map> - -#include <grpc/impl/codegen/log.h> +#include <map> + +#include <grpc/impl/codegen/log.h> #include <grpcpp/impl/codegen/slice.h> namespace grpc { namespace internal { - -const char kBinaryErrorDetailsKey[] = "grpc-status-details-bin"; - + +const char kBinaryErrorDetailsKey[] = "grpc-status-details-bin"; + class MetadataMap { public: - MetadataMap() { Setup(); } + MetadataMap() { Setup(); } + + ~MetadataMap() { Destroy(); } - ~MetadataMap() { Destroy(); } - TString GetBinaryErrorDetails() { - // if filled_, extract from the multimap for O(log(n)) - if (filled_) { - auto iter = map_.find(kBinaryErrorDetailsKey); - if (iter != map_.end()) { + // if filled_, extract from the multimap for O(log(n)) + if (filled_) { + auto iter = map_.find(kBinaryErrorDetailsKey); + if (iter != map_.end()) { return TString(iter->second.begin(), iter->second.length()); - } - } - // if not yet filled, take the O(n) lookup to avoid allocating the - // multimap until it is requested. - // TODO(ncteisen): plumb this through core as a first class object, just - // like code and message. - else { - for (size_t i = 0; i < arr_.count; i++) { - if (strncmp(reinterpret_cast<const char*>( - GRPC_SLICE_START_PTR(arr_.metadata[i].key)), - kBinaryErrorDetailsKey, - GRPC_SLICE_LENGTH(arr_.metadata[i].key)) == 0) { + } + } + // if not yet filled, take the O(n) lookup to avoid allocating the + // multimap until it is requested. + // TODO(ncteisen): plumb this through core as a first class object, just + // like code and message. + else { + for (size_t i = 0; i < arr_.count; i++) { + if (strncmp(reinterpret_cast<const char*>( + GRPC_SLICE_START_PTR(arr_.metadata[i].key)), + kBinaryErrorDetailsKey, + GRPC_SLICE_LENGTH(arr_.metadata[i].key)) == 0) { return TString(reinterpret_cast<const char*>( GRPC_SLICE_START_PTR(arr_.metadata[i].value)), GRPC_SLICE_LENGTH(arr_.metadata[i].value)); - } - } - } + } + } + } return TString(); - } - - std::multimap<grpc::string_ref, grpc::string_ref>* map() { - FillMap(); - return &map_; - } - grpc_metadata_array* arr() { return &arr_; } - - void Reset() { - filled_ = false; - map_.clear(); - Destroy(); - Setup(); - } - - private: - bool filled_ = false; - grpc_metadata_array arr_; - std::multimap<grpc::string_ref, grpc::string_ref> map_; - - void Destroy() { + } + + std::multimap<grpc::string_ref, grpc::string_ref>* map() { + FillMap(); + return &map_; + } + grpc_metadata_array* arr() { return &arr_; } + + void Reset() { + filled_ = false; + map_.clear(); + Destroy(); + Setup(); + } + + private: + bool filled_ = false; + grpc_metadata_array arr_; + std::multimap<grpc::string_ref, grpc::string_ref> map_; + + void Destroy() { g_core_codegen_interface->grpc_metadata_array_destroy(&arr_); } - void Setup() { memset(&arr_, 0, sizeof(arr_)); } - + void Setup() { memset(&arr_, 0, sizeof(arr_)); } + void FillMap() { - if (filled_) return; - filled_ = true; + if (filled_) return; + filled_ = true; for (size_t i = 0; i < arr_.count; i++) { // TODO(yangg) handle duplicates? map_.insert(std::pair<grpc::string_ref, grpc::string_ref>( diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/rpc_service_method.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/rpc_service_method.h index e0f65fccf1..4fcc211243 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/rpc_service_method.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/rpc_service_method.h @@ -25,7 +25,7 @@ #include <memory> #include <vector> -#include <grpc/impl/codegen/log.h> +#include <grpc/impl/codegen/log.h> #include <grpcpp/impl/codegen/byte_buffer.h> #include <grpcpp/impl/codegen/config.h> #include <grpcpp/impl/codegen/rpc_method.h> @@ -39,26 +39,26 @@ class MethodHandler { public: virtual ~MethodHandler() {} struct HandlerParameter { - /// Constructor for HandlerParameter - /// - /// \param c : the gRPC Call structure for this server call - /// \param context : the ServerContext structure for this server call - /// \param req : the request payload, if appropriate for this RPC - /// \param req_status : the request status after any interceptors have run + /// Constructor for HandlerParameter + /// + /// \param c : the gRPC Call structure for this server call + /// \param context : the ServerContext structure for this server call + /// \param req : the request payload, if appropriate for this RPC + /// \param req_status : the request status after any interceptors have run /// \param handler_data: internal data for the handler. /// \param requester : used only by the callback API. It is a function - /// called by the RPC Controller to request another RPC (and also - /// to set up the state required to make that request possible) + /// called by the RPC Controller to request another RPC (and also + /// to set up the state required to make that request possible) HandlerParameter(Call* c, ::grpc::ServerContextBase* context, void* req, Status req_status, void* handler_data, std::function<void()> requester) - : call(c), - server_context(context), - request(req), - status(req_status), + : call(c), + server_context(context), + request(req), + status(req_status), internal_data(handler_data), - call_requester(std::move(requester)) {} - ~HandlerParameter() {} + call_requester(std::move(requester)) {} + ~HandlerParameter() {} Call* const call; ::grpc::ServerContextBase* const server_context; void* const request; @@ -67,17 +67,17 @@ class MethodHandler { const std::function<void()> call_requester; }; virtual void RunHandler(const HandlerParameter& param) = 0; - - /* Returns a pointer to the deserialized request. \a status reflects the - result of deserialization. This pointer and the status should be filled in - a HandlerParameter and passed to RunHandler. It is illegal to access the - pointer after calling RunHandler. Ownership of the deserialized request is - retained by the handler. Returns nullptr if deserialization failed. */ + + /* Returns a pointer to the deserialized request. \a status reflects the + result of deserialization. This pointer and the status should be filled in + a HandlerParameter and passed to RunHandler. It is illegal to access the + pointer after calling RunHandler. Ownership of the deserialized request is + retained by the handler. Returns nullptr if deserialization failed. */ virtual void* Deserialize(grpc_call* /*call*/, grpc_byte_buffer* req, Status* /*status*/, void** /*handler_data*/) { - GPR_CODEGEN_ASSERT(req == nullptr); - return nullptr; - } + GPR_CODEGEN_ASSERT(req == nullptr); + return nullptr; + } }; /// Server side rpc method class @@ -86,65 +86,65 @@ class RpcServiceMethod : public RpcMethod { /// Takes ownership of the handler RpcServiceMethod(const char* name, RpcMethod::RpcType type, MethodHandler* handler) - : RpcMethod(name, type), - server_tag_(nullptr), - api_type_(ApiType::SYNC), - handler_(handler) {} + : RpcMethod(name, type), + server_tag_(nullptr), + api_type_(ApiType::SYNC), + handler_(handler) {} + + enum class ApiType { + SYNC, + ASYNC, + RAW, + CALL_BACK, // not CALLBACK because that is reserved in Windows + RAW_CALL_BACK, + }; - enum class ApiType { - SYNC, - ASYNC, - RAW, - CALL_BACK, // not CALLBACK because that is reserved in Windows - RAW_CALL_BACK, - }; - void set_server_tag(void* tag) { server_tag_ = tag; } void* server_tag() const { return server_tag_; } /// if MethodHandler is nullptr, then this is an async method MethodHandler* handler() const { return handler_.get(); } - ApiType api_type() const { return api_type_; } + ApiType api_type() const { return api_type_; } void SetHandler(MethodHandler* handler) { handler_.reset(handler); } - void SetServerApiType(RpcServiceMethod::ApiType type) { - if ((api_type_ == ApiType::SYNC) && - (type == ApiType::ASYNC || type == ApiType::RAW)) { - // this marks this method as async - handler_.reset(); - } else if (api_type_ != ApiType::SYNC) { - // this is not an error condition, as it allows users to declare a server - // like WithRawMethod_foo<AsyncService>. However since it - // overwrites behavior, it should be logged. - gpr_log( - GPR_INFO, - "You are marking method %s as '%s', even though it was " - "previously marked '%s'. This behavior will overwrite the original " - "behavior. If you expected this then ignore this message.", - name(), TypeToString(api_type_), TypeToString(type)); - } - api_type_ = type; - } + void SetServerApiType(RpcServiceMethod::ApiType type) { + if ((api_type_ == ApiType::SYNC) && + (type == ApiType::ASYNC || type == ApiType::RAW)) { + // this marks this method as async + handler_.reset(); + } else if (api_type_ != ApiType::SYNC) { + // this is not an error condition, as it allows users to declare a server + // like WithRawMethod_foo<AsyncService>. However since it + // overwrites behavior, it should be logged. + gpr_log( + GPR_INFO, + "You are marking method %s as '%s', even though it was " + "previously marked '%s'. This behavior will overwrite the original " + "behavior. If you expected this then ignore this message.", + name(), TypeToString(api_type_), TypeToString(type)); + } + api_type_ = type; + } private: void* server_tag_; - ApiType api_type_; + ApiType api_type_; std::unique_ptr<MethodHandler> handler_; - - const char* TypeToString(RpcServiceMethod::ApiType type) { - switch (type) { - case ApiType::SYNC: - return "sync"; - case ApiType::ASYNC: - return "async"; - case ApiType::RAW: - return "raw"; - case ApiType::CALL_BACK: - return "callback"; - case ApiType::RAW_CALL_BACK: - return "raw_callback"; - default: - GPR_UNREACHABLE_CODE(return "unknown"); - } - } + + const char* TypeToString(RpcServiceMethod::ApiType type) { + switch (type) { + case ApiType::SYNC: + return "sync"; + case ApiType::ASYNC: + return "async"; + case ApiType::RAW: + return "raw"; + case ApiType::CALL_BACK: + return "callback"; + case ApiType::RAW_CALL_BACK: + return "raw_callback"; + default: + GPR_UNREACHABLE_CODE(return "unknown"); + } + } }; } // namespace internal diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_callback.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_callback.h index cb46e4dec7..3794a9ffa7 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_callback.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_callback.h @@ -1,27 +1,27 @@ -/* - * +/* + * * Copyright 2019 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 GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H -#define GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H - + * + * 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 GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H +#define GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H + #include <atomic> #include <functional> #include <type_traits> - + #include <grpcpp/impl/codegen/call.h> #include <grpcpp/impl/codegen/call_op_set.h> #include <grpcpp/impl/codegen/callback_common.h> @@ -30,7 +30,7 @@ #include <grpcpp/impl/codegen/message_allocator.h> #include <grpcpp/impl/codegen/status.h> -namespace grpc { +namespace grpc { // Declare base class of all reactors as internal namespace internal { @@ -774,21 +774,21 @@ using UnimplementedBidiReactor = } // namespace internal // TODO(vjpai): Remove namespace experimental when de-experimentalized fully. -namespace experimental { +namespace experimental { -template <class Request> +template <class Request> using ServerReadReactor = ::grpc::ServerReadReactor<Request>; - -template <class Response> + +template <class Response> using ServerWriteReactor = ::grpc::ServerWriteReactor<Response>; - -template <class Request, class Response> + +template <class Request, class Response> using ServerBidiReactor = ::grpc::ServerBidiReactor<Request, Response>; - + using ServerUnaryReactor = ::grpc::ServerUnaryReactor; - -} // namespace experimental -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H +} // namespace experimental + +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interceptor.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interceptor.h index 0f176f8132..7598e72a40 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interceptor.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interceptor.h @@ -1,139 +1,139 @@ -/* - * - * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H -#define GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H - -#include <atomic> -#include <vector> - -#include <grpcpp/impl/codegen/interceptor.h> -#include <grpcpp/impl/codegen/rpc_method.h> -#include <grpcpp/impl/codegen/string_ref.h> - +/* + * + * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H +#define GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H + +#include <atomic> +#include <vector> + +#include <grpcpp/impl/codegen/interceptor.h> +#include <grpcpp/impl/codegen/rpc_method.h> +#include <grpcpp/impl/codegen/string_ref.h> + namespace grpc { class ServerContextBase; -namespace internal { -class InterceptorBatchMethodsImpl; -} - -namespace experimental { -class ServerRpcInfo; - -// A factory interface for creation of server interceptors. A vector of -// factories can be provided to ServerBuilder which will be used to create a new -// vector of server interceptors per RPC. Server interceptor authors should -// create a subclass of ServerInterceptorFactorInterface which creates objects -// of their interceptors. -class ServerInterceptorFactoryInterface { - public: - virtual ~ServerInterceptorFactoryInterface() {} - // Returns a pointer to an Interceptor object on successful creation, nullptr - // otherwise. If nullptr is returned, this server interceptor factory is - // ignored for the purposes of that RPC. - virtual Interceptor* CreateServerInterceptor(ServerRpcInfo* info) = 0; -}; - -/// ServerRpcInfo represents the state of a particular RPC as it -/// appears to an interceptor. It is created and owned by the library and -/// passed to the CreateServerInterceptor method of the application's -/// ServerInterceptorFactoryInterface implementation -class ServerRpcInfo { - public: - /// Type categorizes RPCs by unary or streaming type - enum class Type { UNARY, CLIENT_STREAMING, SERVER_STREAMING, BIDI_STREAMING }; - +namespace internal { +class InterceptorBatchMethodsImpl; +} + +namespace experimental { +class ServerRpcInfo; + +// A factory interface for creation of server interceptors. A vector of +// factories can be provided to ServerBuilder which will be used to create a new +// vector of server interceptors per RPC. Server interceptor authors should +// create a subclass of ServerInterceptorFactorInterface which creates objects +// of their interceptors. +class ServerInterceptorFactoryInterface { + public: + virtual ~ServerInterceptorFactoryInterface() {} + // Returns a pointer to an Interceptor object on successful creation, nullptr + // otherwise. If nullptr is returned, this server interceptor factory is + // ignored for the purposes of that RPC. + virtual Interceptor* CreateServerInterceptor(ServerRpcInfo* info) = 0; +}; + +/// ServerRpcInfo represents the state of a particular RPC as it +/// appears to an interceptor. It is created and owned by the library and +/// passed to the CreateServerInterceptor method of the application's +/// ServerInterceptorFactoryInterface implementation +class ServerRpcInfo { + public: + /// Type categorizes RPCs by unary or streaming type + enum class Type { UNARY, CLIENT_STREAMING, SERVER_STREAMING, BIDI_STREAMING }; + ~ServerRpcInfo() {} - - // Delete all copy and move constructors and assignments - ServerRpcInfo(const ServerRpcInfo&) = delete; - ServerRpcInfo& operator=(const ServerRpcInfo&) = delete; - ServerRpcInfo(ServerRpcInfo&&) = delete; - ServerRpcInfo& operator=(ServerRpcInfo&&) = delete; - - // Getter methods - - /// Return the fully-specified method name - const char* method() const { return method_; } - - /// Return the type of the RPC (unary or a streaming flavor) - Type type() const { return type_; } - - /// Return a pointer to the underlying ServerContext structure associated - /// with the RPC to support features that apply to it + + // Delete all copy and move constructors and assignments + ServerRpcInfo(const ServerRpcInfo&) = delete; + ServerRpcInfo& operator=(const ServerRpcInfo&) = delete; + ServerRpcInfo(ServerRpcInfo&&) = delete; + ServerRpcInfo& operator=(ServerRpcInfo&&) = delete; + + // Getter methods + + /// Return the fully-specified method name + const char* method() const { return method_; } + + /// Return the type of the RPC (unary or a streaming flavor) + Type type() const { return type_; } + + /// Return a pointer to the underlying ServerContext structure associated + /// with the RPC to support features that apply to it ServerContextBase* server_context() { return ctx_; } - - private: - static_assert(Type::UNARY == - static_cast<Type>(internal::RpcMethod::NORMAL_RPC), - "violated expectation about Type enum"); - static_assert(Type::CLIENT_STREAMING == - static_cast<Type>(internal::RpcMethod::CLIENT_STREAMING), - "violated expectation about Type enum"); - static_assert(Type::SERVER_STREAMING == - static_cast<Type>(internal::RpcMethod::SERVER_STREAMING), - "violated expectation about Type enum"); - static_assert(Type::BIDI_STREAMING == - static_cast<Type>(internal::RpcMethod::BIDI_STREAMING), - "violated expectation about Type enum"); - + + private: + static_assert(Type::UNARY == + static_cast<Type>(internal::RpcMethod::NORMAL_RPC), + "violated expectation about Type enum"); + static_assert(Type::CLIENT_STREAMING == + static_cast<Type>(internal::RpcMethod::CLIENT_STREAMING), + "violated expectation about Type enum"); + static_assert(Type::SERVER_STREAMING == + static_cast<Type>(internal::RpcMethod::SERVER_STREAMING), + "violated expectation about Type enum"); + static_assert(Type::BIDI_STREAMING == + static_cast<Type>(internal::RpcMethod::BIDI_STREAMING), + "violated expectation about Type enum"); + ServerRpcInfo(ServerContextBase* ctx, const char* method, - internal::RpcMethod::RpcType type) + internal::RpcMethod::RpcType type) : ctx_(ctx), method_(method), type_(static_cast<Type>(type)) {} - - // Runs interceptor at pos \a pos. - void RunInterceptor( - experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { - GPR_CODEGEN_ASSERT(pos < interceptors_.size()); - interceptors_[pos]->Intercept(interceptor_methods); - } - - void RegisterInterceptors( - const std::vector< - std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>& - creators) { - for (const auto& creator : creators) { - auto* interceptor = creator->CreateServerInterceptor(this); - if (interceptor != nullptr) { - interceptors_.push_back( - std::unique_ptr<experimental::Interceptor>(interceptor)); - } - } - } - + + // Runs interceptor at pos \a pos. + void RunInterceptor( + experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { + GPR_CODEGEN_ASSERT(pos < interceptors_.size()); + interceptors_[pos]->Intercept(interceptor_methods); + } + + void RegisterInterceptors( + const std::vector< + std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>& + creators) { + for (const auto& creator : creators) { + auto* interceptor = creator->CreateServerInterceptor(this); + if (interceptor != nullptr) { + interceptors_.push_back( + std::unique_ptr<experimental::Interceptor>(interceptor)); + } + } + } + void Ref() { ref_.fetch_add(1, std::memory_order_relaxed); } - void Unref() { + void Unref() { if (GPR_UNLIKELY(ref_.fetch_sub(1, std::memory_order_acq_rel) == 1)) { - delete this; - } - } - + delete this; + } + } + ServerContextBase* ctx_ = nullptr; - const char* method_ = nullptr; - const Type type_; + const char* method_ = nullptr; + const Type type_; std::atomic<intptr_t> ref_{1}; - std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; - - friend class internal::InterceptorBatchMethodsImpl; + std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; + + friend class internal::InterceptorBatchMethodsImpl; friend class grpc::ServerContextBase; -}; - -} // namespace experimental -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H +}; + +} // namespace experimental +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interface.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interface.h index 6b538812ed..d97b725025 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interface.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interface.h @@ -23,7 +23,7 @@ #include <grpc/impl/codegen/grpc_types.h> #include <grpcpp/impl/codegen/byte_buffer.h> -#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/codegen/call.h> #include <grpcpp/impl/codegen/call_hook.h> #include <grpcpp/impl/codegen/completion_queue_tag.h> #include <grpcpp/impl/codegen/core_codegen_interface.h> @@ -66,35 +66,35 @@ class ServerInterface : public internal::CallHook { public: virtual ~ServerInterface() {} - /// \a Shutdown does the following things: + /// \a Shutdown does the following things: + /// + /// 1. Shutdown the server: deactivate all listening ports, mark it in + /// "shutdown mode" so that further call Request's or incoming RPC matches + /// are no longer allowed. Also return all Request'ed-but-not-yet-active + /// calls as failed (!ok). This refers to calls that have been requested + /// at the server by the server-side library or application code but that + /// have not yet been matched to incoming RPCs from the client. Note that + /// this would even include default calls added automatically by the gRPC + /// C++ API without the user's input (e.g., "Unimplemented RPC method") + /// + /// 2. Block until all rpc method handlers invoked automatically by the sync + /// API finish. + /// + /// 3. If all pending calls complete (and all their operations are + /// retrieved by Next) before \a deadline expires, this finishes + /// gracefully. Otherwise, forcefully cancel all pending calls associated + /// with the server after \a deadline expires. In the case of the sync API, + /// if the RPC function for a streaming call has already been started and + /// takes a week to complete, the RPC function won't be forcefully + /// terminated (since that would leave state corrupt and incomplete) and + /// the method handler will just keep running (which will prevent the + /// server from completing the "join" operation that it needs to do at + /// shutdown time). /// - /// 1. Shutdown the server: deactivate all listening ports, mark it in - /// "shutdown mode" so that further call Request's or incoming RPC matches - /// are no longer allowed. Also return all Request'ed-but-not-yet-active - /// calls as failed (!ok). This refers to calls that have been requested - /// at the server by the server-side library or application code but that - /// have not yet been matched to incoming RPCs from the client. Note that - /// this would even include default calls added automatically by the gRPC - /// C++ API without the user's input (e.g., "Unimplemented RPC method") - /// - /// 2. Block until all rpc method handlers invoked automatically by the sync - /// API finish. - /// - /// 3. If all pending calls complete (and all their operations are - /// retrieved by Next) before \a deadline expires, this finishes - /// gracefully. Otherwise, forcefully cancel all pending calls associated - /// with the server after \a deadline expires. In the case of the sync API, - /// if the RPC function for a streaming call has already been started and - /// takes a week to complete, the RPC function won't be forcefully - /// terminated (since that would leave state corrupt and incomplete) and - /// the method handler will just keep running (which will prevent the - /// server from completing the "join" operation that it needs to do at - /// shutdown time). - /// /// All completion queue associated with the server (for example, for async /// serving) must be shutdown *after* this method has returned: /// See \a ServerBuilder::AddCompletionQueue for details. - /// They must also be drained (by repeated Next) after being shutdown. + /// They must also be drained (by repeated Next) after being shutdown. /// /// \param deadline How long to wait until pending rpcs are forcefully /// terminated. @@ -103,7 +103,7 @@ class ServerInterface : public internal::CallHook { ShutdownInternal(TimePoint<T>(deadline).raw_time()); } - /// Shutdown the server without a deadline and forced cancellation. + /// Shutdown the server without a deadline and forced cancellation. /// /// All completion queue associated with the server (for example, for async /// serving) must be shutdown *after* this method has returned: @@ -200,9 +200,9 @@ class ServerInterface : public internal::CallHook { bool FinalizeResult(void** tag, bool* status) override; - private: - void ContinueFinalizeResultAfterInterception(); - + private: + void ContinueFinalizeResultAfterInterception(); + protected: ServerInterface* const server_; ::grpc::ServerContext* const context_; @@ -212,12 +212,12 @@ class ServerInterface : public internal::CallHook { void* const tag_; const bool delete_on_finalize_; grpc_call* call_; - internal::Call call_wrapper_; - internal::InterceptorBatchMethodsImpl interceptor_methods_; - bool done_intercepting_; + internal::Call call_wrapper_; + internal::InterceptorBatchMethodsImpl interceptor_methods_; + bool done_intercepting_; }; - /// RegisteredAsyncRequest is not part of the C++ API + /// RegisteredAsyncRequest is not part of the C++ API class RegisteredAsyncRequest : public BaseAsyncRequest { public: RegisteredAsyncRequest(ServerInterface* server, @@ -228,38 +228,38 @@ class ServerInterface : public internal::CallHook { void* tag, const char* name, internal::RpcMethod::RpcType type); - virtual bool FinalizeResult(void** tag, bool* status) override { - /* If we are done intercepting, then there is nothing more for us to do */ - if (done_intercepting_) { - return BaseAsyncRequest::FinalizeResult(tag, status); - } + virtual bool FinalizeResult(void** tag, bool* status) override { + /* If we are done intercepting, then there is nothing more for us to do */ + if (done_intercepting_) { + return BaseAsyncRequest::FinalizeResult(tag, status); + } call_wrapper_ = ::grpc::internal::Call( - call_, server_, call_cq_, server_->max_receive_message_size(), - context_->set_server_rpc_info(name_, type_, - *server_->interceptor_creators())); - return BaseAsyncRequest::FinalizeResult(tag, status); - } + call_, server_, call_cq_, server_->max_receive_message_size(), + context_->set_server_rpc_info(name_, type_, + *server_->interceptor_creators())); + return BaseAsyncRequest::FinalizeResult(tag, status); + } protected: void IssueRequest(void* registered_method, grpc_byte_buffer** payload, ::grpc::ServerCompletionQueue* notification_cq); - const char* name_; - const internal::RpcMethod::RpcType type_; + const char* name_; + const internal::RpcMethod::RpcType type_; }; class NoPayloadAsyncRequest final : public RegisteredAsyncRequest { public: - NoPayloadAsyncRequest(internal::RpcServiceMethod* registered_method, + NoPayloadAsyncRequest(internal::RpcServiceMethod* registered_method, ServerInterface* server, ::grpc::ServerContext* context, internal::ServerAsyncStreamingInterface* stream, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) - : RegisteredAsyncRequest( - server, context, stream, call_cq, notification_cq, tag, - registered_method->name(), registered_method->method_type()) { - IssueRequest(registered_method->server_tag(), nullptr, notification_cq); + : RegisteredAsyncRequest( + server, context, stream, call_cq, notification_cq, tag, + registered_method->name(), registered_method->method_type()) { + IssueRequest(registered_method->server_tag(), nullptr, notification_cq); } // uses RegisteredAsyncRequest::FinalizeResult @@ -268,19 +268,19 @@ class ServerInterface : public internal::CallHook { template <class Message> class PayloadAsyncRequest final : public RegisteredAsyncRequest { public: - PayloadAsyncRequest(internal::RpcServiceMethod* registered_method, + PayloadAsyncRequest(internal::RpcServiceMethod* registered_method, ServerInterface* server, ::grpc::ServerContext* context, internal::ServerAsyncStreamingInterface* stream, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag, Message* request) - : RegisteredAsyncRequest( - server, context, stream, call_cq, notification_cq, tag, - registered_method->name(), registered_method->method_type()), + : RegisteredAsyncRequest( + server, context, stream, call_cq, notification_cq, tag, + registered_method->name(), registered_method->method_type()), registered_method_(registered_method), request_(request) { - IssueRequest(registered_method->server_tag(), payload_.bbuf_ptr(), - notification_cq); + IssueRequest(registered_method->server_tag(), payload_.bbuf_ptr(), + notification_cq); } ~PayloadAsyncRequest() { @@ -288,10 +288,10 @@ class ServerInterface : public internal::CallHook { } bool FinalizeResult(void** tag, bool* status) override { - /* If we are done intercepting, then there is nothing more for us to do */ - if (done_intercepting_) { - return RegisteredAsyncRequest::FinalizeResult(tag, status); - } + /* If we are done intercepting, then there is nothing more for us to do */ + if (done_intercepting_) { + return RegisteredAsyncRequest::FinalizeResult(tag, status); + } if (*status) { if (!payload_.Valid() || !SerializationTraits<Message>::Deserialize( payload_.bbuf_ptr(), request_) @@ -310,15 +310,15 @@ class ServerInterface : public internal::CallHook { return false; } } - /* Set interception point for recv message */ - interceptor_methods_.AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_RECV_MESSAGE); - interceptor_methods_.SetRecvMessage(request_, nullptr); + /* Set interception point for recv message */ + interceptor_methods_.AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_RECV_MESSAGE); + interceptor_methods_.SetRecvMessage(request_, nullptr); return RegisteredAsyncRequest::FinalizeResult(tag, status); } private: - internal::RpcServiceMethod* const registered_method_; + internal::RpcServiceMethod* const registered_method_; Message* const request_; ByteBuffer payload_; }; @@ -345,8 +345,8 @@ class ServerInterface : public internal::CallHook { ::grpc::ServerCompletionQueue* notification_cq, void* tag, Message* message) { GPR_CODEGEN_ASSERT(method); - new PayloadAsyncRequest<Message>(method, this, context, stream, call_cq, - notification_cq, tag, message); + new PayloadAsyncRequest<Message>(method, this, context, stream, call_cq, + notification_cq, tag, message); } void RequestAsyncCall(internal::RpcServiceMethod* method, @@ -356,8 +356,8 @@ class ServerInterface : public internal::CallHook { ::grpc::ServerCompletionQueue* notification_cq, void* tag) { GPR_CODEGEN_ASSERT(method); - new NoPayloadAsyncRequest(method, this, context, stream, call_cq, - notification_cq, tag); + new NoPayloadAsyncRequest(method, this, context, stream, call_cq, + notification_cq, tag); } void RequestAsyncGenericCall(GenericServerContext* context, @@ -368,27 +368,27 @@ class ServerInterface : public internal::CallHook { new GenericAsyncRequest(this, context, stream, call_cq, notification_cq, tag, true); } - - private: - // EXPERIMENTAL - // Getter method for the vector of interceptor factory objects. - // Returns a nullptr (rather than being pure) since this is a post-1.0 method - // and adding a new pure method to an interface would be a breaking change - // (even though this is private and non-API) - virtual std::vector< - std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>* - interceptor_creators() { - return nullptr; - } - - // EXPERIMENTAL - // A method to get the callbackable completion queue associated with this - // server. If the return value is nullptr, this server doesn't support - // callback operations. - // TODO(vjpai): Consider a better default like using a global CQ - // Returns nullptr (rather than being pure) since this is a post-1.0 method - // and adding a new pure method to an interface would be a breaking change - // (even though this is private and non-API) + + private: + // EXPERIMENTAL + // Getter method for the vector of interceptor factory objects. + // Returns a nullptr (rather than being pure) since this is a post-1.0 method + // and adding a new pure method to an interface would be a breaking change + // (even though this is private and non-API) + virtual std::vector< + std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>* + interceptor_creators() { + return nullptr; + } + + // EXPERIMENTAL + // A method to get the callbackable completion queue associated with this + // server. If the return value is nullptr, this server doesn't support + // callback operations. + // TODO(vjpai): Consider a better default like using a global CQ + // Returns nullptr (rather than being pure) since this is a post-1.0 method + // and adding a new pure method to an interface would be a breaking change + // (even though this is private and non-API) virtual ::grpc::CompletionQueue* CallbackCQ() { return nullptr; } }; diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/service_type.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/service_type.h index 5875fa5294..30be904a3c 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/service_type.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/service_type.h @@ -77,18 +77,18 @@ class Service { return false; } - bool has_callback_methods() const { + bool has_callback_methods() const { for (const auto& method : methods_) { if (method && (method->api_type() == internal::RpcServiceMethod::ApiType::CALL_BACK || method->api_type() == internal::RpcServiceMethod::ApiType::RAW_CALL_BACK)) { - return true; - } - } - return false; - } - + return true; + } + } + return false; + } + bool has_generic_methods() const { for (const auto& method : methods_) { if (method.get() == nullptr) { @@ -99,29 +99,29 @@ class Service { } protected: - // TODO(vjpai): Promote experimental contents once callback API is accepted - class experimental_type { - public: - explicit experimental_type(Service* service) : service_(service) {} - - void MarkMethodCallback(int index, internal::MethodHandler* handler) { + // TODO(vjpai): Promote experimental contents once callback API is accepted + class experimental_type { + public: + explicit experimental_type(Service* service) : service_(service) {} + + void MarkMethodCallback(int index, internal::MethodHandler* handler) { service_->MarkMethodCallbackInternal(index, handler); - } - - void MarkMethodRawCallback(int index, internal::MethodHandler* handler) { + } + + void MarkMethodRawCallback(int index, internal::MethodHandler* handler) { service_->MarkMethodRawCallbackInternal(index, handler); - } - + } + internal::MethodHandler* GetHandler(int index) { return service_->GetHandlerInternal(index); } - private: - Service* service_; - }; - - experimental_type experimental() { return experimental_type(this); } - + private: + Service* service_; + }; + + experimental_type experimental() { return experimental_type(this); } + template <class Message> void RequestAsyncUnary(int index, ::grpc::ServerContext* context, Message* request, @@ -129,11 +129,11 @@ class Service { ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) { - // Typecast the index to size_t for indexing into a vector - // while preserving the API that existed before a compiler - // warning was first seen (grpc/grpc#11664) - size_t idx = static_cast<size_t>(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + // Typecast the index to size_t for indexing into a vector + // while preserving the API that existed before a compiler + // warning was first seen (grpc/grpc#11664) + size_t idx = static_cast<size_t>(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, notification_cq, tag, request); } void RequestAsyncClientStreaming( @@ -141,8 +141,8 @@ class Service { internal::ServerAsyncStreamingInterface* stream, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) { - size_t idx = static_cast<size_t>(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + size_t idx = static_cast<size_t>(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, notification_cq, tag); } template <class Message> @@ -151,8 +151,8 @@ class Service { internal::ServerAsyncStreamingInterface* stream, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) { - size_t idx = static_cast<size_t>(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + size_t idx = static_cast<size_t>(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, notification_cq, tag, request); } void RequestAsyncBidiStreaming( @@ -160,8 +160,8 @@ class Service { internal::ServerAsyncStreamingInterface* stream, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) { - size_t idx = static_cast<size_t>(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + size_t idx = static_cast<size_t>(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, notification_cq, tag); } @@ -170,50 +170,50 @@ class Service { } void MarkMethodAsync(int index) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast<size_t>(index); + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast<size_t>(index); GPR_CODEGEN_ASSERT( - methods_[idx].get() != nullptr && + methods_[idx].get() != nullptr && "Cannot mark the method as 'async' because it has already been " "marked as 'generic'."); - methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::ASYNC); + methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::ASYNC); + } + + void MarkMethodRaw(int index) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast<size_t>(index); + GPR_CODEGEN_ASSERT(methods_[idx].get() != nullptr && + "Cannot mark the method as 'raw' because it has already " + "been marked as 'generic'."); + methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::RAW); } - void MarkMethodRaw(int index) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast<size_t>(index); - GPR_CODEGEN_ASSERT(methods_[idx].get() != nullptr && - "Cannot mark the method as 'raw' because it has already " - "been marked as 'generic'."); - methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::RAW); - } - void MarkMethodGeneric(int index) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast<size_t>(index); + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast<size_t>(index); GPR_CODEGEN_ASSERT( - methods_[idx]->handler() != nullptr && + methods_[idx]->handler() != nullptr && "Cannot mark the method as 'generic' because it has already been " - "marked as 'async' or 'raw'."); - methods_[idx].reset(); + "marked as 'async' or 'raw'."); + methods_[idx].reset(); } void MarkMethodStreamed(int index, internal::MethodHandler* streamed_method) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast<size_t>(index); - GPR_CODEGEN_ASSERT(methods_[idx] && methods_[idx]->handler() && + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast<size_t>(index); + GPR_CODEGEN_ASSERT(methods_[idx] && methods_[idx]->handler() && "Cannot mark an async or generic method Streamed"); - methods_[idx]->SetHandler(streamed_method); + methods_[idx]->SetHandler(streamed_method); // From the server's point of view, streamed unary is a special // case of BIDI_STREAMING that has 1 read and 1 write, in that order, // and split server-side streaming is BIDI_STREAMING with 1 read and // any number of writes, in that order. - methods_[idx]->SetMethodType(internal::RpcMethod::BIDI_STREAMING); + methods_[idx]->SetMethodType(internal::RpcMethod::BIDI_STREAMING); } #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL diff --git a/contrib/libs/grpc/include/grpcpp/impl/grpc_library.h b/contrib/libs/grpc/include/grpcpp/impl/grpc_library.h index eb6fc56c44..3711c09879 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/grpc_library.h +++ b/contrib/libs/grpc/include/grpcpp/impl/grpc_library.h @@ -40,12 +40,12 @@ class GrpcLibraryInitializer final { public: GrpcLibraryInitializer() { if (grpc::g_glip == nullptr) { - static auto* const g_gli = new GrpcLibrary(); - grpc::g_glip = g_gli; + static auto* const g_gli = new GrpcLibrary(); + grpc::g_glip = g_gli; } if (grpc::g_core_codegen_interface == nullptr) { - static auto* const g_core_codegen = new CoreCodegen(); - grpc::g_core_codegen_interface = g_core_codegen; + static auto* const g_core_codegen = new CoreCodegen(); + grpc::g_core_codegen_interface = g_core_codegen; } } diff --git a/contrib/libs/grpc/include/grpcpp/impl/server_builder_plugin.h b/contrib/libs/grpc/include/grpcpp/impl/server_builder_plugin.h index 8703e9d75b..8fedca2b14 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/server_builder_plugin.h +++ b/contrib/libs/grpc/include/grpcpp/impl/server_builder_plugin.h @@ -41,9 +41,9 @@ class ServerBuilderPlugin { virtual ~ServerBuilderPlugin() {} virtual TString name() = 0; - /// UpdateServerBuilder will be called at an early stage in - /// ServerBuilder::BuildAndStart(), right after the ServerBuilderOptions have - /// done their updates. + /// UpdateServerBuilder will be called at an early stage in + /// ServerBuilder::BuildAndStart(), right after the ServerBuilderOptions have + /// done their updates. virtual void UpdateServerBuilder(ServerBuilder* /*builder*/) {} /// InitServer will be called in ServerBuilder::BuildAndStart(), after the |