diff options
author | leonidlazarev <leonidlazarev@yandex-team.com> | 2023-06-02 15:07:38 +0300 |
---|---|---|
committer | leonidlazarev <leonidlazarev@yandex-team.com> | 2023-06-02 15:07:38 +0300 |
commit | 59e0045a61e61c2ac38878f2adc7ec91ca914cc1 (patch) | |
tree | b6b64c51025630a7d40923d4aa7b7b882e1a8848 /contrib/libs/grpc/include/grpcpp/impl/codegen | |
parent | 7506c5c295065b4360d617393af34203f037946d (diff) | |
download | ydb-59e0045a61e61c2ac38878f2adc7ec91ca914cc1.tar.gz |
feat grpc: update to grpc 1.50.2
update grpc to 1.50.2
update grpcio to 1.50.0
Удаленные патчи:
06-flow_control.patch - логика в upstream удалена
10-fix-crash-on-fork.patch - логика в upstream удалена
12-coverity-fix.patch - логика в upstream удалена
20-P2166-string-nullptr.patch - в upstream временный объект вместо nullptr
PR29209-fix-heap-use-after-free.patch - решение есть в upstream
Добавленные патчи:
pr33085_fix_epoll1_engine_reinit.patch
21-windows_build.patch
Diffstat (limited to 'contrib/libs/grpc/include/grpcpp/impl/codegen')
27 files changed, 92 insertions, 2169 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 8aaeb2b824b..03a096c52be 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 @@ -19,119 +19,9 @@ #ifndef GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H #define GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H -// IWYU pragma: private, include <grpcpp/generic/async_generic_service.h> +// IWYU pragma: private -#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/server_callback.h> -#include <grpcpp/impl/codegen/server_callback_handlers.h> - -struct grpc_server; - -namespace grpc { - -typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer> - GenericServerAsyncReaderWriter; -typedef ServerAsyncResponseWriter<ByteBuffer> GenericServerAsyncResponseWriter; -typedef ServerAsyncReader<ByteBuffer, ByteBuffer> GenericServerAsyncReader; -typedef ServerAsyncWriter<ByteBuffer> GenericServerAsyncWriter; - -class GenericServerContext final : public ServerContext { - public: - const TString& method() const { return method_; } - const TString& host() const { return host_; } - - 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, - grpc::CompletionQueue* call_cq, - grpc::ServerCompletionQueue* notification_cq, void* tag); - - private: - friend class grpc::Server; - grpc::Server* server_; -}; - -/// \a ServerGenericBidiReactor is the reactor class for bidi streaming RPCs -/// invoked on a CallbackGenericService. It is just a ServerBidi reactor with -/// ByteBuffer arguments. -using ServerGenericBidiReactor = ServerBidiReactor<ByteBuffer, ByteBuffer>; - -class GenericCallbackServerContext final : public grpc::CallbackServerContext { - public: - const TString& method() const { return method_; } - const TString& host() const { return host_; } - - private: - friend class grpc::Server; - - TString method_; - TString host_; -}; - -/// \a CallbackGenericService is the base class for generic services implemented -/// using the callback API and registered through the ServerBuilder using -/// RegisterCallbackGenericService. -class CallbackGenericService { - public: - CallbackGenericService() {} - virtual ~CallbackGenericService() {} - - /// The "method handler" for the generic API. This function should be - /// overridden to provide a ServerGenericBidiReactor that implements the - /// application-level interface for this RPC. Unimplemented by default. - virtual ServerGenericBidiReactor* CreateReactor( - GenericCallbackServerContext* /*ctx*/) { - class Reactor : public ServerGenericBidiReactor { - public: - Reactor() { this->Finish(Status(StatusCode::UNIMPLEMENTED, "")); } - void OnDone() override { delete this; } - }; - return new Reactor; - } - - private: - friend class grpc::Server; - - internal::CallbackBidiHandler<ByteBuffer, ByteBuffer>* Handler() { - return new internal::CallbackBidiHandler<ByteBuffer, ByteBuffer>( - [this](grpc::CallbackServerContext* ctx) { - return CreateReactor(static_cast<GenericCallbackServerContext*>(ctx)); - }); - } - - grpc::Server* server_{nullptr}; -}; - -} // namespace grpc +/// TODO(chengyuc): Remove this file after solving compatibility. +#include <grpcpp/generic/async_generic_service.h> #endif // GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/async_stream.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/async_stream.h index 5b63c30173e..524f619f815 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/async_stream.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/async_stream.h @@ -18,1115 +18,9 @@ #ifndef GRPCPP_IMPL_CODEGEN_ASYNC_STREAM_H #define GRPCPP_IMPL_CODEGEN_ASYNC_STREAM_H -// IWYU pragma: private, include <grpcpp/support/async_stream.h> +// IWYU pragma: private -#include <grpcpp/impl/codegen/call.h> -#include <grpcpp/impl/codegen/channel_interface.h> -#include <grpcpp/impl/codegen/core_codegen_interface.h> -#include <grpcpp/impl/codegen/server_context.h> -#include <grpcpp/impl/codegen/service_type.h> -#include <grpcpp/impl/codegen/status.h> +/// TODO(chengyuc): Remove this file after solving compatibility. +#include <grpcpp/support/async_stream.h> -namespace grpc { - -namespace internal { -/// Common interface for all client side asynchronous streaming. -class ClientAsyncStreamingInterface { - public: - virtual ~ClientAsyncStreamingInterface() {} - - /// Start the call that was set up by the constructor, but only if the - /// constructor was invoked through the "Prepare" API which doesn't actually - /// start the call - virtual void StartCall(void* tag) = 0; - - /// Request notification of the reading of the initial metadata. Completion - /// will be notified by \a tag on the associated completion queue. - /// This call is optional, but if it is used, it cannot be used concurrently - /// with or after the \a AsyncReaderInterface::Read method. - /// - /// \param[in] tag Tag identifying this request. - virtual void ReadInitialMetadata(void* tag) = 0; - - /// Indicate that the stream is to be finished and request notification for - /// when the call has been ended. - /// Should not be used concurrently with other operations. - /// - /// It is appropriate to call this method exactly once when both: - /// * the client side has no more message to send - /// (this can be declared implicitly by calling this method, or - /// explicitly through an earlier call to the <i>WritesDone</i> method - /// of the class in use, e.g. \a ClientAsyncWriterInterface::WritesDone or - /// \a ClientAsyncReaderWriterInterface::WritesDone). - /// * there are no more messages to be received from the server (this can - /// be known implicitly by the calling code, or explicitly from an - /// earlier call to \a AsyncReaderInterface::Read that yielded a failed - /// result, e.g. cq->Next(&read_tag, &ok) filled in 'ok' with 'false'). - /// - /// The tag will be returned when either: - /// - all incoming messages have been read and the server has returned - /// a status. - /// - the server has returned a non-OK status. - /// - the call failed for some reason and the library generated a - /// status. - /// - /// Note that implementations of this method attempt to receive initial - /// metadata from the server if initial metadata hasn't yet been received. - /// - /// \param[in] tag Tag identifying this request. - /// \param[out] status To be updated with the operation status. - virtual void Finish(grpc::Status* status, void* tag) = 0; -}; - -/// An interface that yields a sequence of messages of type \a R. -template <class R> -class AsyncReaderInterface { - public: - virtual ~AsyncReaderInterface() {} - - /// Read a message of type \a R into \a msg. Completion will be notified by \a - /// tag on the associated completion queue. - /// This is thread-safe with respect to \a Write or \a WritesDone methods. It - /// should not be called concurrently with other streaming APIs - /// on the same stream. It is not meaningful to call it concurrently - /// with another \a AsyncReaderInterface::Read on the same stream since reads - /// on the same stream are delivered in order. - /// - /// \param[out] msg Where to eventually store the read message. - /// \param[in] tag The tag identifying the operation. - /// - /// Side effect: note that this method attempt to receive initial metadata for - /// a stream if it hasn't yet been received. - virtual void Read(R* msg, void* tag) = 0; -}; - -/// An interface that can be fed a sequence of messages of type \a W. -template <class W> -class AsyncWriterInterface { - public: - virtual ~AsyncWriterInterface() {} - - /// Request the writing of \a msg with identifying tag \a tag. - /// - /// Only one write may be outstanding at any given time. This means that - /// after calling Write, one must wait to receive \a tag from the completion - /// queue BEFORE calling Write again. - /// This is thread-safe with respect to \a AsyncReaderInterface::Read - /// - /// gRPC doesn't take ownership or a reference to \a msg, so it is safe to - /// to deallocate once Write returns. - /// - /// \param[in] msg The message to be written. - /// \param[in] tag The tag identifying the operation. - virtual void Write(const W& msg, void* tag) = 0; - - /// Request the writing of \a msg using WriteOptions \a options with - /// identifying tag \a tag. - /// - /// Only one write may be outstanding at any given time. This means that - /// after calling Write, one must wait to receive \a tag from the completion - /// queue BEFORE calling Write again. - /// WriteOptions \a options is used to set the write options of this message. - /// This is thread-safe with respect to \a AsyncReaderInterface::Read - /// - /// gRPC doesn't take ownership or a reference to \a msg, so it is safe to - /// to deallocate once Write returns. - /// - /// \param[in] msg The message to be written. - /// \param[in] options The WriteOptions to be used to write this message. - /// \param[in] tag The tag identifying the operation. - virtual void Write(const W& msg, grpc::WriteOptions options, void* tag) = 0; - - /// Request the writing of \a msg and coalesce it with the writing - /// of trailing metadata, using WriteOptions \a options with - /// identifying tag \a tag. - /// - /// For client, WriteLast is equivalent of performing Write and - /// WritesDone in a single step. - /// For server, WriteLast buffers the \a msg. The writing of \a msg is held - /// until Finish is called, where \a msg and trailing metadata are coalesced - /// and write is initiated. Note that WriteLast can only buffer \a msg up to - /// the flow control window size. If \a msg size is larger than the window - /// size, it will be sent on wire without buffering. - /// - /// gRPC doesn't take ownership or a reference to \a msg, so it is safe to - /// to deallocate once Write returns. - /// - /// \param[in] msg The message to be written. - /// \param[in] options The WriteOptions to be used to write this message. - /// \param[in] tag The tag identifying the operation. - void WriteLast(const W& msg, grpc::WriteOptions options, void* tag) { - Write(msg, options.set_last_message(), tag); - } -}; - -} // namespace internal - -template <class R> -class ClientAsyncReaderInterface - : public internal::ClientAsyncStreamingInterface, - public internal::AsyncReaderInterface<R> {}; - -namespace internal { -template <class R> -class ClientAsyncReaderFactory { - public: - /// Create a stream object. - /// Write the first request out if \a start is set. - /// \a tag will be notified on \a cq when the call has been started and - /// \a request has been written out. If \a start is not set, \a tag must be - /// nullptr and the actual call must be initiated by StartCall - /// Note that \a context will be used to fill in custom initial metadata - /// used to send to the server when starting the call. - template <class W> - static ClientAsyncReader<R>* Create(grpc::ChannelInterface* channel, - grpc::CompletionQueue* cq, - const grpc::internal::RpcMethod& method, - grpc::ClientContext* context, - const W& request, bool start, void* tag) { - grpc::internal::Call call = channel->CreateCall(method, context, cq); - return new (grpc::g_core_codegen_interface->grpc_call_arena_alloc( - call.call(), sizeof(ClientAsyncReader<R>))) - ClientAsyncReader<R>(call, context, request, start, tag); - } -}; -} // namespace internal - -/// Async client-side API for doing server-streaming RPCs, -/// where the incoming message stream coming from the server has -/// messages of type \a R. -template <class R> -class ClientAsyncReader final : public ClientAsyncReaderInterface<R> { - 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(ClientAsyncReader)); - } - - // 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); } - - void StartCall(void* tag) override { - GPR_CODEGEN_ASSERT(!started_); - started_ = true; - StartCallInternal(tag); - } - - /// See the \a ClientAsyncStreamingInterface.ReadInitialMetadata - /// method for semantics. - /// - /// Side effect: - /// - upon receiving initial metadata from the server, - /// the \a ClientContext associated with this call is updated, and the - /// calling code can access the received metadata through the - /// \a ClientContext. - void ReadInitialMetadata(void* tag) override { - GPR_CODEGEN_ASSERT(started_); - GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_); - - meta_ops_.set_output_tag(tag); - meta_ops_.RecvInitialMetadata(context_); - call_.PerformOps(&meta_ops_); - } - - void Read(R* msg, void* tag) override { - GPR_CODEGEN_ASSERT(started_); - read_ops_.set_output_tag(tag); - if (!context_->initial_metadata_received_) { - read_ops_.RecvInitialMetadata(context_); - } - read_ops_.RecvMessage(msg); - call_.PerformOps(&read_ops_); - } - - /// See the \a ClientAsyncStreamingInterface.Finish method for semantics. - /// - /// Side effect: - /// - the \a ClientContext associated with this call is updated with - /// possible initial and trailing metadata received from the server. - void Finish(grpc::Status* status, void* tag) override { - GPR_CODEGEN_ASSERT(started_); - finish_ops_.set_output_tag(tag); - if (!context_->initial_metadata_received_) { - finish_ops_.RecvInitialMetadata(context_); - } - finish_ops_.ClientRecvStatus(context_, status); - call_.PerformOps(&finish_ops_); - } - - private: - friend class internal::ClientAsyncReaderFactory<R>; - template <class W> - ClientAsyncReader(grpc::internal::Call call, grpc::ClientContext* context, - const W& request, bool start, void* tag) - : context_(context), call_(call), started_(start) { - // TODO(ctiller): don't assert - GPR_CODEGEN_ASSERT(init_ops_.SendMessage(request).ok()); - init_ops_.ClientSendClose(); - if (start) { - StartCallInternal(tag); - } else { - GPR_CODEGEN_ASSERT(tag == nullptr); - } - } - - void StartCallInternal(void* tag) { - init_ops_.SendInitialMetadata(&context_->send_initial_metadata_, - context_->initial_metadata_flags()); - init_ops_.set_output_tag(tag); - call_.PerformOps(&init_ops_); - } - - grpc::ClientContext* context_; - grpc::internal::Call call_; - bool started_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata, - grpc::internal::CallOpSendMessage, - grpc::internal::CallOpClientSendClose> - init_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata> - meta_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata, - grpc::internal::CallOpRecvMessage<R>> - read_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata, - grpc::internal::CallOpClientRecvStatus> - finish_ops_; -}; - -/// Common interface for client side asynchronous writing. -template <class W> -class ClientAsyncWriterInterface - : public internal::ClientAsyncStreamingInterface, - public internal::AsyncWriterInterface<W> { - public: - /// Signal the client is done with the writes (half-close the client stream). - /// Thread-safe with respect to \a AsyncReaderInterface::Read - /// - /// \param[in] tag The tag identifying the operation. - virtual void WritesDone(void* tag) = 0; -}; - -namespace internal { -template <class W> -class ClientAsyncWriterFactory { - public: - /// Create a stream object. - /// Start the RPC if \a start is set - /// \a tag will be notified on \a cq when the call has been started (i.e. - /// intitial metadata sent) and \a request has been written out. - /// If \a start is not set, \a tag must be nullptr and the actual call - /// must be initiated by StartCall - /// Note that \a context will be used to fill in custom initial metadata - /// used to send to the server when starting the call. - /// \a response will be filled in with the single expected response - /// message from the server upon a successful call to the \a Finish - /// method of this instance. - template <class R> - static ClientAsyncWriter<W>* Create(grpc::ChannelInterface* channel, - grpc::CompletionQueue* cq, - const grpc::internal::RpcMethod& method, - grpc::ClientContext* context, R* response, - bool start, void* tag) { - grpc::internal::Call call = channel->CreateCall(method, context, cq); - return new (grpc::g_core_codegen_interface->grpc_call_arena_alloc( - call.call(), sizeof(ClientAsyncWriter<W>))) - ClientAsyncWriter<W>(call, context, response, start, tag); - } -}; -} // namespace internal - -/// Async API on the client side for doing client-streaming RPCs, -/// where the outgoing message stream going to the server contains -/// messages of type \a W. -template <class W> -class ClientAsyncWriter final : public ClientAsyncWriterInterface<W> { - 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(ClientAsyncWriter)); - } - - // 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); } - - void StartCall(void* tag) override { - GPR_CODEGEN_ASSERT(!started_); - started_ = true; - StartCallInternal(tag); - } - - /// See the \a ClientAsyncStreamingInterface.ReadInitialMetadata method for - /// semantics. - /// - /// Side effect: - /// - upon receiving initial metadata from the server, the \a ClientContext - /// associated with this call is updated, and the calling code can access - /// the received metadata through the \a ClientContext. - void ReadInitialMetadata(void* tag) override { - GPR_CODEGEN_ASSERT(started_); - GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_); - - meta_ops_.set_output_tag(tag); - meta_ops_.RecvInitialMetadata(context_); - call_.PerformOps(&meta_ops_); - } - - void Write(const W& msg, void* tag) override { - GPR_CODEGEN_ASSERT(started_); - write_ops_.set_output_tag(tag); - // TODO(ctiller): don't assert - GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok()); - call_.PerformOps(&write_ops_); - } - - void Write(const W& msg, grpc::WriteOptions options, void* tag) override { - GPR_CODEGEN_ASSERT(started_); - write_ops_.set_output_tag(tag); - if (options.is_last_message()) { - options.set_buffer_hint(); - write_ops_.ClientSendClose(); - } - // TODO(ctiller): don't assert - GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg, options).ok()); - call_.PerformOps(&write_ops_); - } - - void WritesDone(void* tag) override { - GPR_CODEGEN_ASSERT(started_); - write_ops_.set_output_tag(tag); - write_ops_.ClientSendClose(); - call_.PerformOps(&write_ops_); - } - - /// See the \a ClientAsyncStreamingInterface.Finish method for semantics. - /// - /// Side effect: - /// - the \a ClientContext associated with this call is updated with - /// possible initial and trailing metadata received from the server. - /// - attempts to fill in the \a response parameter passed to this class's - /// constructor with the server's response message. - void Finish(grpc::Status* status, void* tag) override { - GPR_CODEGEN_ASSERT(started_); - finish_ops_.set_output_tag(tag); - if (!context_->initial_metadata_received_) { - finish_ops_.RecvInitialMetadata(context_); - } - finish_ops_.ClientRecvStatus(context_, status); - call_.PerformOps(&finish_ops_); - } - - private: - friend class internal::ClientAsyncWriterFactory<W>; - template <class R> - ClientAsyncWriter(grpc::internal::Call call, grpc::ClientContext* context, - R* response, bool start, void* tag) - : context_(context), call_(call), started_(start) { - finish_ops_.RecvMessage(response); - finish_ops_.AllowNoMessage(); - if (start) { - StartCallInternal(tag); - } else { - GPR_CODEGEN_ASSERT(tag == nullptr); - } - } - - void StartCallInternal(void* tag) { - write_ops_.SendInitialMetadata(&context_->send_initial_metadata_, - context_->initial_metadata_flags()); - // if corked bit is set in context, we just keep the initial metadata - // buffered up to coalesce with later message send. No op is performed. - if (!context_->initial_metadata_corked_) { - write_ops_.set_output_tag(tag); - call_.PerformOps(&write_ops_); - } - } - - grpc::ClientContext* context_; - grpc::internal::Call call_; - bool started_; - grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata> - meta_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata, - grpc::internal::CallOpSendMessage, - grpc::internal::CallOpClientSendClose> - write_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata, - grpc::internal::CallOpGenericRecvMessage, - grpc::internal::CallOpClientRecvStatus> - finish_ops_; -}; - -/// Async client-side interface for bi-directional streaming, -/// where the client-to-server message stream has messages of type \a W, -/// and the server-to-client message stream has messages of type \a R. -template <class W, class R> -class ClientAsyncReaderWriterInterface - : public internal::ClientAsyncStreamingInterface, - public internal::AsyncWriterInterface<W>, - public internal::AsyncReaderInterface<R> { - public: - /// Signal the client is done with the writes (half-close the client stream). - /// Thread-safe with respect to \a AsyncReaderInterface::Read - /// - /// \param[in] tag The tag identifying the operation. - virtual void WritesDone(void* tag) = 0; -}; - -namespace internal { -template <class W, class R> -class ClientAsyncReaderWriterFactory { - public: - /// Create a stream object. - /// Start the RPC request if \a start is set. - /// \a tag will be notified on \a cq when the call has been started (i.e. - /// intitial metadata sent). If \a start is not set, \a tag must be - /// nullptr and the actual call must be initiated by StartCall - /// Note that \a context will be used to fill in custom initial metadata - /// used to send to the server when starting the call. - static ClientAsyncReaderWriter<W, R>* Create( - grpc::ChannelInterface* channel, grpc::CompletionQueue* cq, - const grpc::internal::RpcMethod& method, grpc::ClientContext* context, - bool start, void* tag) { - grpc::internal::Call call = channel->CreateCall(method, context, cq); - - return new (grpc::g_core_codegen_interface->grpc_call_arena_alloc( - call.call(), sizeof(ClientAsyncReaderWriter<W, R>))) - ClientAsyncReaderWriter<W, R>(call, context, start, tag); - } -}; -} // namespace internal - -/// Async client-side interface for bi-directional streaming, -/// where the outgoing message stream going to the server -/// has messages of type \a W, and the incoming message stream coming -/// from the server has messages of type \a R. -template <class W, class R> -class ClientAsyncReaderWriter final - : public ClientAsyncReaderWriterInterface<W, R> { - 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(ClientAsyncReaderWriter)); - } - - // 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); } - - void StartCall(void* tag) override { - GPR_CODEGEN_ASSERT(!started_); - started_ = true; - StartCallInternal(tag); - } - - /// See the \a ClientAsyncStreamingInterface.ReadInitialMetadata method - /// for semantics of this method. - /// - /// Side effect: - /// - upon receiving initial metadata from the server, the \a ClientContext - /// is updated with it, and then the receiving initial metadata can - /// be accessed through this \a ClientContext. - void ReadInitialMetadata(void* tag) override { - GPR_CODEGEN_ASSERT(started_); - GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_); - - meta_ops_.set_output_tag(tag); - meta_ops_.RecvInitialMetadata(context_); - call_.PerformOps(&meta_ops_); - } - - void Read(R* msg, void* tag) override { - GPR_CODEGEN_ASSERT(started_); - read_ops_.set_output_tag(tag); - if (!context_->initial_metadata_received_) { - read_ops_.RecvInitialMetadata(context_); - } - read_ops_.RecvMessage(msg); - call_.PerformOps(&read_ops_); - } - - void Write(const W& msg, void* tag) override { - GPR_CODEGEN_ASSERT(started_); - write_ops_.set_output_tag(tag); - // TODO(ctiller): don't assert - GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok()); - call_.PerformOps(&write_ops_); - } - - void Write(const W& msg, grpc::WriteOptions options, void* tag) override { - GPR_CODEGEN_ASSERT(started_); - write_ops_.set_output_tag(tag); - if (options.is_last_message()) { - options.set_buffer_hint(); - write_ops_.ClientSendClose(); - } - // TODO(ctiller): don't assert - GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg, options).ok()); - call_.PerformOps(&write_ops_); - } - - void WritesDone(void* tag) override { - GPR_CODEGEN_ASSERT(started_); - write_ops_.set_output_tag(tag); - write_ops_.ClientSendClose(); - call_.PerformOps(&write_ops_); - } - - /// See the \a ClientAsyncStreamingInterface.Finish method for semantics. - /// Side effect - /// - the \a ClientContext associated with this call is updated with - /// possible initial and trailing metadata sent from the server. - void Finish(grpc::Status* status, void* tag) override { - GPR_CODEGEN_ASSERT(started_); - finish_ops_.set_output_tag(tag); - if (!context_->initial_metadata_received_) { - finish_ops_.RecvInitialMetadata(context_); - } - finish_ops_.ClientRecvStatus(context_, status); - call_.PerformOps(&finish_ops_); - } - - private: - friend class internal::ClientAsyncReaderWriterFactory<W, R>; - ClientAsyncReaderWriter(grpc::internal::Call call, - grpc::ClientContext* context, bool start, void* tag) - : context_(context), call_(call), started_(start) { - if (start) { - StartCallInternal(tag); - } else { - GPR_CODEGEN_ASSERT(tag == nullptr); - } - } - - void StartCallInternal(void* tag) { - write_ops_.SendInitialMetadata(&context_->send_initial_metadata_, - context_->initial_metadata_flags()); - // if corked bit is set in context, we just keep the initial metadata - // buffered up to coalesce with later message send. No op is performed. - if (!context_->initial_metadata_corked_) { - write_ops_.set_output_tag(tag); - call_.PerformOps(&write_ops_); - } - } - - grpc::ClientContext* context_; - grpc::internal::Call call_; - bool started_; - grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata> - meta_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata, - grpc::internal::CallOpRecvMessage<R>> - read_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata, - grpc::internal::CallOpSendMessage, - grpc::internal::CallOpClientSendClose> - write_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata, - grpc::internal::CallOpClientRecvStatus> - finish_ops_; -}; - -template <class W, class R> -class ServerAsyncReaderInterface - : public grpc::internal::ServerAsyncStreamingInterface, - public internal::AsyncReaderInterface<R> { - public: - /// Indicate that the stream is to be finished with a certain status code - /// and also send out \a msg response to the client. - /// Request notification for when the server has sent the response and the - /// appropriate signals to the client to end the call. - /// Should not be used concurrently with other operations. - /// - /// It is appropriate to call this method when: - /// * all messages from the client have been received (either known - /// implictly, or explicitly because a previous - /// \a AsyncReaderInterface::Read operation with a non-ok result, - /// e.g., cq->Next(&read_tag, &ok) filled in 'ok' with 'false'). - /// - /// This operation will end when the server has finished sending out initial - /// metadata (if not sent already), response message, and status, or if - /// some failure occurred when trying to do so. - /// - /// gRPC doesn't take ownership or a reference to \a msg or \a status, so it - /// is safe to deallocate once Finish returns. - /// - /// \param[in] tag Tag identifying this request. - /// \param[in] status To be sent to the client as the result of this call. - /// \param[in] msg To be sent to the client as the response for this call. - virtual void Finish(const W& msg, const grpc::Status& status, void* tag) = 0; - - /// Indicate that the stream is to be finished with a certain - /// non-OK status code. - /// Request notification for when the server has sent the appropriate - /// signals to the client to end the call. - /// Should not be used concurrently with other operations. - /// - /// This call is meant to end the call with some error, and can be called at - /// any point that the server would like to "fail" the call (though note - /// this shouldn't be called concurrently with any other "sending" call, like - /// \a AsyncWriterInterface::Write). - /// - /// This operation will end when the server has finished sending out initial - /// metadata (if not sent already), and status, or if some failure occurred - /// when trying to do so. - /// - /// gRPC doesn't take ownership or a reference to \a status, so it is safe to - /// to deallocate once FinishWithError returns. - /// - /// \param[in] tag Tag identifying this request. - /// \param[in] status To be sent to the client as the result of this call. - /// - Note: \a status must have a non-OK code. - virtual void FinishWithError(const grpc::Status& status, void* tag) = 0; -}; - -/// Async server-side API for doing client-streaming RPCs, -/// where the incoming message stream from the client has messages of type \a R, -/// and the single response message sent from the server is type \a W. -template <class W, class R> -class ServerAsyncReader final : public ServerAsyncReaderInterface<W, R> { - public: - explicit ServerAsyncReader(grpc::ServerContext* ctx) - : call_(nullptr, nullptr, nullptr), ctx_(ctx) {} - - /// See \a ServerAsyncStreamingInterface::SendInitialMetadata for semantics. - /// - /// Implicit input parameter: - /// - The initial metadata that will be sent to the client from this op will - /// be taken from the \a ServerContext associated with the call. - void SendInitialMetadata(void* tag) override { - GPR_CODEGEN_ASSERT(!ctx_->sent_initial_metadata_); - - meta_ops_.set_output_tag(tag); - meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_, - ctx_->initial_metadata_flags()); - if (ctx_->compression_level_set()) { - meta_ops_.set_compression_level(ctx_->compression_level()); - } - ctx_->sent_initial_metadata_ = true; - call_.PerformOps(&meta_ops_); - } - - void Read(R* msg, void* tag) override { - read_ops_.set_output_tag(tag); - read_ops_.RecvMessage(msg); - call_.PerformOps(&read_ops_); - } - - /// See the \a ServerAsyncReaderInterface.Read method for semantics - /// - /// Side effect: - /// - also sends initial metadata if not alreay sent. - /// - uses the \a ServerContext associated with this call to send possible - /// initial and trailing metadata. - /// - /// Note: \a msg is not sent if \a status has a non-OK code. - /// - /// gRPC doesn't take ownership or a reference to \a msg and \a status, so it - /// is safe to deallocate once Finish returns. - void Finish(const W& msg, const grpc::Status& status, void* tag) override { - finish_ops_.set_output_tag(tag); - if (!ctx_->sent_initial_metadata_) { - finish_ops_.SendInitialMetadata(&ctx_->initial_metadata_, - ctx_->initial_metadata_flags()); - if (ctx_->compression_level_set()) { - finish_ops_.set_compression_level(ctx_->compression_level()); - } - ctx_->sent_initial_metadata_ = true; - } - // The response is dropped if the status is not OK. - if (status.ok()) { - finish_ops_.ServerSendStatus(&ctx_->trailing_metadata_, - finish_ops_.SendMessage(msg)); - } else { - finish_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status); - } - call_.PerformOps(&finish_ops_); - } - - /// See the \a ServerAsyncReaderInterface.Read method for semantics - /// - /// Side effect: - /// - also sends initial metadata if not alreay sent. - /// - uses the \a ServerContext associated with this call to send possible - /// initial and trailing metadata. - /// - /// gRPC doesn't take ownership or a reference to \a status, so it is safe to - /// to deallocate once FinishWithError returns. - void FinishWithError(const grpc::Status& status, void* tag) override { - GPR_CODEGEN_ASSERT(!status.ok()); - finish_ops_.set_output_tag(tag); - if (!ctx_->sent_initial_metadata_) { - finish_ops_.SendInitialMetadata(&ctx_->initial_metadata_, - ctx_->initial_metadata_flags()); - if (ctx_->compression_level_set()) { - finish_ops_.set_compression_level(ctx_->compression_level()); - } - ctx_->sent_initial_metadata_ = true; - } - finish_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status); - call_.PerformOps(&finish_ops_); - } - - private: - void BindCall(grpc::internal::Call* call) override { call_ = *call; } - - grpc::internal::Call call_; - grpc::ServerContext* ctx_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata> - meta_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpRecvMessage<R>> read_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata, - grpc::internal::CallOpSendMessage, - grpc::internal::CallOpServerSendStatus> - finish_ops_; -}; - -template <class W> -class ServerAsyncWriterInterface - : public grpc::internal::ServerAsyncStreamingInterface, - public internal::AsyncWriterInterface<W> { - public: - /// Indicate that the stream is to be finished with a certain status code. - /// Request notification for when the server has sent the appropriate - /// signals to the client to end the call. - /// Should not be used concurrently with other operations. - /// - /// It is appropriate to call this method when either: - /// * all messages from the client have been received (either known - /// implictly, or explicitly because a previous \a - /// AsyncReaderInterface::Read operation with a non-ok - /// result (e.g., cq->Next(&read_tag, &ok) filled in 'ok' with 'false'. - /// * it is desired to end the call early with some non-OK status code. - /// - /// This operation will end when the server has finished sending out initial - /// metadata (if not sent already), response message, and status, or if - /// some failure occurred when trying to do so. - /// - /// gRPC doesn't take ownership or a reference to \a status, so it is safe to - /// to deallocate once Finish returns. - /// - /// \param[in] tag Tag identifying this request. - /// \param[in] status To be sent to the client as the result of this call. - virtual void Finish(const grpc::Status& status, void* tag) = 0; - - /// Request the writing of \a msg and coalesce it with trailing metadata which - /// contains \a status, using WriteOptions options with - /// identifying tag \a tag. - /// - /// WriteAndFinish is equivalent of performing WriteLast and Finish - /// in a single step. - /// - /// gRPC doesn't take ownership or a reference to \a msg and \a status, so it - /// is safe to deallocate once WriteAndFinish returns. - /// - /// \param[in] msg The message to be written. - /// \param[in] options The WriteOptions to be used to write this message. - /// \param[in] status The Status that server returns to client. - /// \param[in] tag The tag identifying the operation. - virtual void WriteAndFinish(const W& msg, grpc::WriteOptions options, - const grpc::Status& status, void* tag) = 0; -}; - -/// Async server-side API for doing server streaming RPCs, -/// where the outgoing message stream from the server has messages of type \a W. -template <class W> -class ServerAsyncWriter final : public ServerAsyncWriterInterface<W> { - public: - explicit ServerAsyncWriter(grpc::ServerContext* ctx) - : call_(nullptr, nullptr, nullptr), ctx_(ctx) {} - - /// See \a ServerAsyncStreamingInterface::SendInitialMetadata for semantics. - /// - /// Implicit input parameter: - /// - The initial metadata that will be sent to the client from this op will - /// be taken from the \a ServerContext associated with the call. - /// - /// \param[in] tag Tag identifying this request. - void SendInitialMetadata(void* tag) override { - GPR_CODEGEN_ASSERT(!ctx_->sent_initial_metadata_); - - meta_ops_.set_output_tag(tag); - meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_, - ctx_->initial_metadata_flags()); - if (ctx_->compression_level_set()) { - meta_ops_.set_compression_level(ctx_->compression_level()); - } - ctx_->sent_initial_metadata_ = true; - call_.PerformOps(&meta_ops_); - } - - void Write(const W& msg, void* tag) override { - write_ops_.set_output_tag(tag); - EnsureInitialMetadataSent(&write_ops_); - // TODO(ctiller): don't assert - GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok()); - call_.PerformOps(&write_ops_); - } - - void Write(const W& msg, grpc::WriteOptions options, void* tag) override { - write_ops_.set_output_tag(tag); - if (options.is_last_message()) { - options.set_buffer_hint(); - } - - EnsureInitialMetadataSent(&write_ops_); - // TODO(ctiller): don't assert - GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg, options).ok()); - call_.PerformOps(&write_ops_); - } - - /// See the \a ServerAsyncWriterInterface.WriteAndFinish method for semantics. - /// - /// Implicit input parameter: - /// - the \a ServerContext associated with this call is used - /// for sending trailing (and initial) metadata to the client. - /// - /// Note: \a status must have an OK code. - /// - /// gRPC doesn't take ownership or a reference to \a msg and \a status, so it - /// is safe to deallocate once WriteAndFinish returns. - void WriteAndFinish(const W& msg, grpc::WriteOptions options, - const grpc::Status& status, void* tag) override { - write_ops_.set_output_tag(tag); - EnsureInitialMetadataSent(&write_ops_); - options.set_buffer_hint(); - GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg, options).ok()); - write_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status); - call_.PerformOps(&write_ops_); - } - - /// See the \a ServerAsyncWriterInterface.Finish method for semantics. - /// - /// Implicit input parameter: - /// - the \a ServerContext associated with this call is used for sending - /// trailing (and initial if not already sent) metadata to the client. - /// - /// Note: there are no restrictions are the code of - /// \a status,it may be non-OK - /// - /// gRPC doesn't take ownership or a reference to \a status, so it is safe to - /// to deallocate once Finish returns. - void Finish(const grpc::Status& status, void* tag) override { - finish_ops_.set_output_tag(tag); - EnsureInitialMetadataSent(&finish_ops_); - finish_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status); - call_.PerformOps(&finish_ops_); - } - - private: - void BindCall(grpc::internal::Call* call) override { call_ = *call; } - - template <class T> - void EnsureInitialMetadataSent(T* ops) { - if (!ctx_->sent_initial_metadata_) { - ops->SendInitialMetadata(&ctx_->initial_metadata_, - ctx_->initial_metadata_flags()); - if (ctx_->compression_level_set()) { - ops->set_compression_level(ctx_->compression_level()); - } - ctx_->sent_initial_metadata_ = true; - } - } - - grpc::internal::Call call_; - grpc::ServerContext* ctx_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata> - meta_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata, - grpc::internal::CallOpSendMessage, - grpc::internal::CallOpServerSendStatus> - write_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata, - grpc::internal::CallOpServerSendStatus> - finish_ops_; -}; - -/// Server-side interface for asynchronous bi-directional streaming. -template <class W, class R> -class ServerAsyncReaderWriterInterface - : public grpc::internal::ServerAsyncStreamingInterface, - public internal::AsyncWriterInterface<W>, - public internal::AsyncReaderInterface<R> { - public: - /// Indicate that the stream is to be finished with a certain status code. - /// Request notification for when the server has sent the appropriate - /// signals to the client to end the call. - /// Should not be used concurrently with other operations. - /// - /// It is appropriate to call this method when either: - /// * all messages from the client have been received (either known - /// implictly, or explicitly because a previous \a - /// AsyncReaderInterface::Read operation - /// with a non-ok result (e.g., cq->Next(&read_tag, &ok) filled in 'ok' - /// with 'false'. - /// * it is desired to end the call early with some non-OK status code. - /// - /// This operation will end when the server has finished sending out initial - /// metadata (if not sent already), response message, and status, or if some - /// failure occurred when trying to do so. - /// - /// gRPC doesn't take ownership or a reference to \a status, so it is safe to - /// to deallocate once Finish returns. - /// - /// \param[in] tag Tag identifying this request. - /// \param[in] status To be sent to the client as the result of this call. - virtual void Finish(const grpc::Status& status, void* tag) = 0; - - /// Request the writing of \a msg and coalesce it with trailing metadata which - /// contains \a status, using WriteOptions options with - /// identifying tag \a tag. - /// - /// WriteAndFinish is equivalent of performing WriteLast and Finish in a - /// single step. - /// - /// gRPC doesn't take ownership or a reference to \a msg and \a status, so it - /// is safe to deallocate once WriteAndFinish returns. - /// - /// \param[in] msg The message to be written. - /// \param[in] options The WriteOptions to be used to write this message. - /// \param[in] status The Status that server returns to client. - /// \param[in] tag The tag identifying the operation. - virtual void WriteAndFinish(const W& msg, grpc::WriteOptions options, - const grpc::Status& status, void* tag) = 0; -}; - -/// Async server-side API for doing bidirectional streaming RPCs, -/// where the incoming message stream coming from the client has messages of -/// type \a R, and the outgoing message stream coming from the server has -/// messages of type \a W. -template <class W, class R> -class ServerAsyncReaderWriter final - : public ServerAsyncReaderWriterInterface<W, R> { - public: - explicit ServerAsyncReaderWriter(grpc::ServerContext* ctx) - : call_(nullptr, nullptr, nullptr), ctx_(ctx) {} - - /// See \a ServerAsyncStreamingInterface::SendInitialMetadata for semantics. - /// - /// Implicit input parameter: - /// - The initial metadata that will be sent to the client from this op will - /// be taken from the \a ServerContext associated with the call. - /// - /// \param[in] tag Tag identifying this request. - void SendInitialMetadata(void* tag) override { - GPR_CODEGEN_ASSERT(!ctx_->sent_initial_metadata_); - - meta_ops_.set_output_tag(tag); - meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_, - ctx_->initial_metadata_flags()); - if (ctx_->compression_level_set()) { - meta_ops_.set_compression_level(ctx_->compression_level()); - } - ctx_->sent_initial_metadata_ = true; - call_.PerformOps(&meta_ops_); - } - - void Read(R* msg, void* tag) override { - read_ops_.set_output_tag(tag); - read_ops_.RecvMessage(msg); - call_.PerformOps(&read_ops_); - } - - void Write(const W& msg, void* tag) override { - write_ops_.set_output_tag(tag); - EnsureInitialMetadataSent(&write_ops_); - // TODO(ctiller): don't assert - GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok()); - call_.PerformOps(&write_ops_); - } - - void Write(const W& msg, grpc::WriteOptions options, void* tag) override { - write_ops_.set_output_tag(tag); - if (options.is_last_message()) { - options.set_buffer_hint(); - } - EnsureInitialMetadataSent(&write_ops_); - GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg, options).ok()); - call_.PerformOps(&write_ops_); - } - - /// See the \a ServerAsyncReaderWriterInterface.WriteAndFinish - /// method for semantics. - /// - /// Implicit input parameter: - /// - the \a ServerContext associated with this call is used - /// for sending trailing (and initial) metadata to the client. - /// - /// Note: \a status must have an OK code. - // - /// gRPC doesn't take ownership or a reference to \a msg and \a status, so it - /// is safe to deallocate once WriteAndFinish returns. - void WriteAndFinish(const W& msg, grpc::WriteOptions options, - const grpc::Status& status, void* tag) override { - write_ops_.set_output_tag(tag); - EnsureInitialMetadataSent(&write_ops_); - options.set_buffer_hint(); - GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg, options).ok()); - write_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status); - call_.PerformOps(&write_ops_); - } - - /// See the \a ServerAsyncReaderWriterInterface.Finish method for semantics. - /// - /// Implicit input parameter: - /// - the \a ServerContext associated with this call is used for sending - /// trailing (and initial if not already sent) metadata to the client. - /// - /// Note: there are no restrictions are the code of \a status, - /// it may be non-OK - // - /// gRPC doesn't take ownership or a reference to \a status, so it is safe to - /// to deallocate once Finish returns. - void Finish(const grpc::Status& status, void* tag) override { - finish_ops_.set_output_tag(tag); - EnsureInitialMetadataSent(&finish_ops_); - - finish_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status); - call_.PerformOps(&finish_ops_); - } - - private: - friend class grpc::Server; - - void BindCall(grpc::internal::Call* call) override { call_ = *call; } - - template <class T> - void EnsureInitialMetadataSent(T* ops) { - if (!ctx_->sent_initial_metadata_) { - ops->SendInitialMetadata(&ctx_->initial_metadata_, - ctx_->initial_metadata_flags()); - if (ctx_->compression_level_set()) { - ops->set_compression_level(ctx_->compression_level()); - } - ctx_->sent_initial_metadata_ = true; - } - } - - grpc::internal::Call call_; - grpc::ServerContext* ctx_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata> - meta_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpRecvMessage<R>> read_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata, - grpc::internal::CallOpSendMessage, - grpc::internal::CallOpServerSendStatus> - write_ops_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata, - grpc::internal::CallOpServerSendStatus> - finish_ops_; -}; - -} // namespace grpc #endif // GRPCPP_IMPL_CODEGEN_ASYNC_STREAM_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/async_unary_call.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/async_unary_call.h index 0034d21058f..55227b2e4a8 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/async_unary_call.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/async_unary_call.h @@ -19,402 +19,9 @@ #ifndef GRPCPP_IMPL_CODEGEN_ASYNC_UNARY_CALL_H #define GRPCPP_IMPL_CODEGEN_ASYNC_UNARY_CALL_H -// IWYU pragma: private, include <grpcpp/support/async_unary_call.h> +// IWYU pragma: private -#include <grpcpp/impl/codegen/call.h> -#include <grpcpp/impl/codegen/call_op_set.h> -#include <grpcpp/impl/codegen/call_op_set_interface.h> -#include <grpcpp/impl/codegen/channel_interface.h> -#include <grpcpp/impl/codegen/client_context.h> -#include <grpcpp/impl/codegen/server_context.h> -#include <grpcpp/impl/codegen/service_type.h> -#include <grpcpp/impl/codegen/status.h> - -namespace grpc { - -// Forward declaration for use in Helper class -template <class R> -class ClientAsyncResponseReader; - -/// An interface relevant for async client side unary RPCs (which send -/// one request message to a server and receive one response message). -template <class R> -class ClientAsyncResponseReaderInterface { - public: - virtual ~ClientAsyncResponseReaderInterface() {} - - /// Start the call that was set up by the constructor, but only if the - /// constructor was invoked through the "Prepare" API which doesn't actually - /// start the call - virtual void StartCall() = 0; - - /// Request notification of the reading of initial metadata. Completion - /// will be notified by \a tag on the associated completion queue. - /// This call is optional, but if it is used, it cannot be used concurrently - /// with or after the \a Finish method. - /// - /// \param[in] tag Tag identifying this request. - virtual void ReadInitialMetadata(void* tag) = 0; - - /// Request to receive the server's response \a msg and final \a status for - /// the call, and to notify \a tag on this call's completion queue when - /// finished. - /// - /// This function will return when either: - /// - when the server's response message and status have been received. - /// - when the server has returned a non-OK status (no message expected in - /// this case). - /// - when the call failed for some reason and the library generated a - /// non-OK status. - /// - /// \param[in] tag Tag identifying this request. - /// \param[out] status To be updated with the operation status. - /// \param[out] msg To be filled in with the server's response message. - virtual void Finish(R* msg, grpc::Status* status, void* tag) = 0; -}; - -namespace internal { - -class ClientAsyncResponseReaderHelper { - public: - /// Start a call and write the request out if \a start is set. - /// \a tag will be notified on \a cq when the call has been started (i.e. - /// intitial metadata sent) and \a request has been written out. - /// If \a start is not set, the actual call must be initiated by StartCall - /// Note that \a context will be used to fill in custom initial metadata - /// used to send to the server when starting the call. - /// - /// Optionally pass in a base class for request and response types so that the - /// internal functions and structs can be templated based on that, allowing - /// reuse across RPCs (e.g., MessageLite for protobuf). Since constructors - /// can't have an explicit template parameter, the last argument is an - /// extraneous parameter just to provide the needed type information. - template <class R, class W, class BaseR = R, class BaseW = W> - static ClientAsyncResponseReader<R>* Create( - grpc::ChannelInterface* channel, grpc::CompletionQueue* cq, - const grpc::internal::RpcMethod& method, grpc::ClientContext* context, - const W& request) /* __attribute__((noinline)) */ { - grpc::internal::Call call = channel->CreateCall(method, context, cq); - ClientAsyncResponseReader<R>* result = - new (grpc::g_core_codegen_interface->grpc_call_arena_alloc( - call.call(), sizeof(ClientAsyncResponseReader<R>))) - ClientAsyncResponseReader<R>(call, context); - SetupRequest<BaseR, BaseW>( - call.call(), &result->single_buf_, &result->read_initial_metadata_, - &result->finish_, static_cast<const BaseW&>(request)); - - return result; - } - - // Various helper functions to reduce templating use - - template <class R, class W> - static void SetupRequest( - grpc_call* call, - grpc::internal::CallOpSendInitialMetadata** single_buf_ptr, - std::function<void(ClientContext*, internal::Call*, - internal::CallOpSendInitialMetadata*, void*)>* - read_initial_metadata, - std::function< - void(ClientContext*, internal::Call*, bool initial_metadata_read, - internal::CallOpSendInitialMetadata*, - internal::CallOpSetInterface**, void*, Status*, void*)>* finish, - const W& request) { - using SingleBufType = - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata, - grpc::internal::CallOpSendMessage, - grpc::internal::CallOpClientSendClose, - grpc::internal::CallOpRecvInitialMetadata, - grpc::internal::CallOpRecvMessage<R>, - grpc::internal::CallOpClientRecvStatus>; - SingleBufType* single_buf = - new (grpc::g_core_codegen_interface->grpc_call_arena_alloc( - call, sizeof(SingleBufType))) SingleBufType; - *single_buf_ptr = single_buf; - // TODO(ctiller): don't assert - GPR_CODEGEN_ASSERT(single_buf->SendMessage(request).ok()); - single_buf->ClientSendClose(); - - // The purpose of the following functions is to type-erase the actual - // templated type of the CallOpSet being used by hiding that type inside the - // function definition rather than specifying it as an argument of the - // function or a member of the class. The type-erased CallOpSet will get - // static_cast'ed back to the real type so that it can be used properly. - *read_initial_metadata = - [](ClientContext* context, internal::Call* call, - internal::CallOpSendInitialMetadata* single_buf_view, void* tag) { - auto* single_buf = static_cast<SingleBufType*>(single_buf_view); - single_buf->set_output_tag(tag); - single_buf->RecvInitialMetadata(context); - call->PerformOps(single_buf); - }; - - // Note that this function goes one step further than the previous one - // because it type-erases the message being written down to a void*. This - // will be static-cast'ed back to the class specified here by hiding that - // class information inside the function definition. Note that this feature - // expects the class being specified here for R to be a base-class of the - // "real" R without any multiple-inheritance (as applies in protbuf wrt - // MessageLite) - *finish = [](ClientContext* context, internal::Call* call, - bool initial_metadata_read, - internal::CallOpSendInitialMetadata* single_buf_view, - internal::CallOpSetInterface** finish_buf_ptr, void* msg, - Status* status, void* tag) { - if (initial_metadata_read) { - using FinishBufType = - grpc::internal::CallOpSet<grpc::internal::CallOpRecvMessage<R>, - grpc::internal::CallOpClientRecvStatus>; - FinishBufType* finish_buf = - new (grpc::g_core_codegen_interface->grpc_call_arena_alloc( - call->call(), sizeof(FinishBufType))) FinishBufType; - *finish_buf_ptr = finish_buf; - finish_buf->set_output_tag(tag); - finish_buf->RecvMessage(static_cast<R*>(msg)); - finish_buf->AllowNoMessage(); - finish_buf->ClientRecvStatus(context, status); - call->PerformOps(finish_buf); - } else { - auto* single_buf = static_cast<SingleBufType*>(single_buf_view); - single_buf->set_output_tag(tag); - single_buf->RecvInitialMetadata(context); - single_buf->RecvMessage(static_cast<R*>(msg)); - single_buf->AllowNoMessage(); - single_buf->ClientRecvStatus(context, status); - call->PerformOps(single_buf); - } - }; - } - - static void StartCall(grpc::ClientContext* context, - grpc::internal::CallOpSendInitialMetadata* single_buf) { - single_buf->SendInitialMetadata(&context->send_initial_metadata_, - context->initial_metadata_flags()); - } -}; - -// TODO(vjpai): This templated factory is deprecated and will be replaced by -//. the non-templated helper as soon as possible. -template <class R> -class ClientAsyncResponseReaderFactory { - public: - template <class W> - static ClientAsyncResponseReader<R>* Create( - grpc::ChannelInterface* channel, grpc::CompletionQueue* cq, - const grpc::internal::RpcMethod& method, grpc::ClientContext* context, - const W& request, bool start) { - auto* result = ClientAsyncResponseReaderHelper::Create<R>( - channel, cq, method, context, request); - if (start) { - result->StartCall(); - } - return result; - } -}; - -} // namespace internal - -/// Async API for client-side unary RPCs, where the message response -/// received from the server is of type \a R. -template <class R> -class ClientAsyncResponseReader final - : public ClientAsyncResponseReaderInterface<R> { - 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(ClientAsyncResponseReader)); - } - - // 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); } - - void StartCall() override { - GPR_CODEGEN_DEBUG_ASSERT(!started_); - started_ = true; - internal::ClientAsyncResponseReaderHelper::StartCall(context_, single_buf_); - } - - /// See \a ClientAsyncResponseReaderInterface::ReadInitialMetadata for - /// semantics. - /// - /// Side effect: - /// - the \a ClientContext associated with this call is updated with - /// possible initial and trailing metadata sent from the server. - void ReadInitialMetadata(void* tag) override { - GPR_CODEGEN_DEBUG_ASSERT(started_); - GPR_CODEGEN_DEBUG_ASSERT(!context_->initial_metadata_received_); - read_initial_metadata_(context_, &call_, single_buf_, tag); - initial_metadata_read_ = true; - } - - /// See \a ClientAsyncResponseReaderInterface::Finish for semantics. - /// - /// Side effect: - /// - the \a ClientContext associated with this call is updated with - /// possible initial and trailing metadata sent from the server. - void Finish(R* msg, grpc::Status* status, void* tag) override { - GPR_CODEGEN_DEBUG_ASSERT(started_); - finish_(context_, &call_, initial_metadata_read_, single_buf_, &finish_buf_, - static_cast<void*>(msg), status, tag); - } - - private: - friend class internal::ClientAsyncResponseReaderHelper; - grpc::ClientContext* const context_; - grpc::internal::Call call_; - bool started_ = false; - bool initial_metadata_read_ = false; - - ClientAsyncResponseReader(grpc::internal::Call call, - grpc::ClientContext* context) - : context_(context), call_(call) {} - - // disable operator new - static void* operator new(std::size_t size); - static void* operator new(std::size_t /*size*/, void* p) { return p; } - - internal::CallOpSendInitialMetadata* single_buf_; - internal::CallOpSetInterface* finish_buf_ = nullptr; - std::function<void(ClientContext*, internal::Call*, - internal::CallOpSendInitialMetadata*, void*)> - read_initial_metadata_; - std::function<void(ClientContext*, internal::Call*, - bool initial_metadata_read, - internal::CallOpSendInitialMetadata*, - internal::CallOpSetInterface**, void*, Status*, void*)> - finish_; -}; - -/// Async server-side API for handling unary calls, where the single -/// response message sent to the client is of type \a W. -template <class W> -class ServerAsyncResponseWriter final - : public grpc::internal::ServerAsyncStreamingInterface { - public: - explicit ServerAsyncResponseWriter(grpc::ServerContext* ctx) - : call_(nullptr, nullptr, nullptr), ctx_(ctx) {} - - /// See \a ServerAsyncStreamingInterface::SendInitialMetadata for semantics. - /// - /// Side effect: - /// The initial metadata that will be sent to the client from this op will - /// be taken from the \a ServerContext associated with the call. - /// - /// \param[in] tag Tag identifying this request. - void SendInitialMetadata(void* tag) override { - GPR_CODEGEN_ASSERT(!ctx_->sent_initial_metadata_); - - meta_buf_.set_output_tag(tag); - meta_buf_.SendInitialMetadata(&ctx_->initial_metadata_, - ctx_->initial_metadata_flags()); - if (ctx_->compression_level_set()) { - meta_buf_.set_compression_level(ctx_->compression_level()); - } - ctx_->sent_initial_metadata_ = true; - call_.PerformOps(&meta_buf_); - } - - /// Indicate that the stream is to be finished and request notification - /// when the server has sent the appropriate signals to the client to - /// end the call. Should not be used concurrently with other operations. - /// - /// \param[in] tag Tag identifying this request. - /// \param[in] status To be sent to the client as the result of the call. - /// \param[in] msg Message to be sent to the client. - /// - /// Side effect: - /// - also sends initial metadata if not already sent (using the - /// \a ServerContext associated with this call). - /// - /// Note: if \a status has a non-OK code, then \a msg will not be sent, - /// and the client will receive only the status with possible trailing - /// metadata. - /// - /// gRPC doesn't take ownership or a reference to msg and status, so it is - /// safe to deallocate them once the Finish operation is complete (i.e. a - /// result arrives in the completion queue). - void Finish(const W& msg, const grpc::Status& status, void* tag) { - finish_buf_.set_output_tag(tag); - finish_buf_.set_core_cq_tag(&finish_buf_); - if (!ctx_->sent_initial_metadata_) { - finish_buf_.SendInitialMetadata(&ctx_->initial_metadata_, - ctx_->initial_metadata_flags()); - if (ctx_->compression_level_set()) { - finish_buf_.set_compression_level(ctx_->compression_level()); - } - ctx_->sent_initial_metadata_ = true; - } - // The response is dropped if the status is not OK. - if (status.ok()) { - finish_buf_.ServerSendStatus(&ctx_->trailing_metadata_, - finish_buf_.SendMessage(msg)); - } else { - finish_buf_.ServerSendStatus(&ctx_->trailing_metadata_, status); - } - call_.PerformOps(&finish_buf_); - } - - /// Indicate that the stream is to be finished with a non-OK status, - /// and request notification for when the server has finished sending the - /// appropriate signals to the client to end the call. - /// Should not be used concurrently with other operations. - /// - /// \param[in] tag Tag identifying this request. - /// \param[in] status To be sent to the client as the result of the call. - /// - Note: \a status must have a non-OK code. - /// - /// Side effect: - /// - also sends initial metadata if not already sent (using the - /// \a ServerContext associated with this call). - /// - /// gRPC doesn't take ownership or a reference to status, so it is safe to - /// deallocate them once the Finish operation is complete (i.e. a result - /// arrives in the completion queue). - void FinishWithError(const grpc::Status& status, void* tag) { - GPR_CODEGEN_ASSERT(!status.ok()); - finish_buf_.set_output_tag(tag); - if (!ctx_->sent_initial_metadata_) { - finish_buf_.SendInitialMetadata(&ctx_->initial_metadata_, - ctx_->initial_metadata_flags()); - if (ctx_->compression_level_set()) { - finish_buf_.set_compression_level(ctx_->compression_level()); - } - ctx_->sent_initial_metadata_ = true; - } - finish_buf_.ServerSendStatus(&ctx_->trailing_metadata_, status); - call_.PerformOps(&finish_buf_); - } - - private: - void BindCall(grpc::internal::Call* call) override { call_ = *call; } - - grpc::internal::Call call_; - grpc::ServerContext* ctx_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata> - meta_buf_; - grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata, - grpc::internal::CallOpSendMessage, - grpc::internal::CallOpServerSendStatus> - finish_buf_; -}; - -} // namespace grpc - -namespace std { -template <class R> -class default_delete<grpc::ClientAsyncResponseReader<R>> { - public: - void operator()(void* /*p*/) {} -}; -template <class R> -class default_delete<grpc::ClientAsyncResponseReaderInterface<R>> { - public: - void operator()(void* /*p*/) {} -}; -} // namespace std +/// TODO(chengyuc): Remove this file after solving compatibility. +#include <grpcpp/support/async_unary_call.h> #endif // GRPCPP_IMPL_CODEGEN_ASYNC_UNARY_CALL_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 a9ba7d16fca..d1969953929 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/byte_buffer.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/byte_buffer.h @@ -19,221 +19,9 @@ #ifndef GRPCPP_IMPL_CODEGEN_BYTE_BUFFER_H #define GRPCPP_IMPL_CODEGEN_BYTE_BUFFER_H -// IWYU pragma: private, include <grpcpp/support/byte_buffer.h> +// IWYU pragma: private -#include <vector> - -#include <grpc/impl/codegen/byte_buffer.h> -#include <grpcpp/impl/codegen/config.h> -#include <grpcpp/impl/codegen/core_codegen_interface.h> -#include <grpcpp/impl/codegen/serialization_traits.h> -#include <grpcpp/impl/codegen/slice.h> -#include <grpcpp/impl/codegen/status.h> - -namespace grpc { - -class ServerInterface; -class ByteBuffer; -class ServerInterface; - -namespace internal { -template <class RequestType, class ResponseType> -class CallbackUnaryHandler; -template <class RequestType, class ResponseType> -class CallbackServerStreamingHandler; -template <class RequestType> -void* UnaryDeserializeHelper(grpc_byte_buffer*, grpc::Status*, RequestType*); -template <class ServiceType, class RequestType, class ResponseType> -class ServerStreamingHandler; -template <grpc::StatusCode code> -class ErrorMethodHandler; -class CallOpSendMessage; -template <class R> -class CallOpRecvMessage; -class CallOpGenericRecvMessage; -class ExternalConnectionAcceptorImpl; -template <class R> -class DeserializeFuncType; -class GrpcByteBufferPeer; - -} // namespace internal -/// A sequence of bytes. -class ByteBuffer final { - public: - /// Constuct an empty buffer. - ByteBuffer() : buffer_(nullptr) {} - - /// Construct buffer from \a slices, of which there are \a nslices. - ByteBuffer(const Slice* slices, size_t nslices) { - // The following assertions check that the representation of a grpc::Slice - // is identical to that of a grpc_slice: it has a grpc_slice field, and - // nothing else. - static_assert(std::is_same<decltype(slices[0].slice_), grpc_slice>::value, - "Slice must have same representation as grpc_slice"); - static_assert(sizeof(Slice) == sizeof(grpc_slice), - "Slice must have same representation as grpc_slice"); - // The following assertions check that the representation of a ByteBuffer is - // identical to grpc_byte_buffer*: it has a grpc_byte_buffer* field, - // and nothing else. - static_assert(std::is_same<decltype(buffer_), grpc_byte_buffer*>::value, - "ByteBuffer must have same representation as " - "grpc_byte_buffer*"); - static_assert(sizeof(ByteBuffer) == sizeof(grpc_byte_buffer*), - "ByteBuffer must have same representation as " - "grpc_byte_buffer*"); - // The const_cast is legal if grpc_raw_byte_buffer_create() does no more - // than its advertised side effect of increasing the reference count of the - // slices it processes, and such an increase does not affect the semantics - // seen by the caller of this constructor. - buffer_ = g_core_codegen_interface->grpc_raw_byte_buffer_create( - reinterpret_cast<grpc_slice*>(const_cast<Slice*>(slices)), nslices); - } - - /// 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. - ByteBuffer(const ByteBuffer& buf) : buffer_(nullptr) { operator=(buf); } - - ~ByteBuffer() { - if (buffer_) { - g_core_codegen_interface->grpc_byte_buffer_destroy(buffer_); - } - } - - /// 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 - } - if (buf.buffer_) { - // then copy - buffer_ = g_core_codegen_interface->grpc_byte_buffer_copy(buf.buffer_); - } - return *this; - } - - // If this ByteBuffer's representation is a single flat slice, returns a - // slice referencing that array. - Status TrySingleSlice(Slice* slice) const; - - /// Dump (read) the buffer contents into \a slics. - Status DumpToSingleSlice(Slice* slice) const; - - /// Dump (read) the buffer contents into \a slices. - Status Dump(std::vector<Slice>* slices) const; - - /// Remove all data. - void Clear() { - if (buffer_) { - g_core_codegen_interface->grpc_byte_buffer_destroy(buffer_); - buffer_ = nullptr; - } - } - - /// 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. - void Duplicate() { - buffer_ = g_core_codegen_interface->grpc_byte_buffer_copy(buffer_); - } - - /// Forget underlying byte buffer without destroying - /// Use this only for un-owned byte buffers - void Release() { buffer_ = nullptr; } - - /// Buffer size in bytes. - size_t Length() const { - return buffer_ == nullptr - ? 0 - : g_core_codegen_interface->grpc_byte_buffer_length(buffer_); - } - - /// Swap the state of *this and *other. - void Swap(ByteBuffer* other) { - grpc_byte_buffer* tmp = other->buffer_; - other->buffer_ = buffer_; - buffer_ = tmp; - } - - /// Is this ByteBuffer valid? - bool Valid() const { return (buffer_ != nullptr); } - - private: - friend class SerializationTraits<ByteBuffer, void>; - friend class ServerInterface; - friend class internal::CallOpSendMessage; - template <class R> - friend class internal::CallOpRecvMessage; - friend class internal::CallOpGenericRecvMessage; - template <class RequestType> - friend void* internal::UnaryDeserializeHelper(grpc_byte_buffer*, - grpc::Status*, RequestType*); - template <class ServiceType, class RequestType, class ResponseType> - friend class internal::ServerStreamingHandler; - template <class RequestType, class ResponseType> - friend class internal::CallbackUnaryHandler; - template <class RequestType, class ResponseType> - friend class internal::CallbackServerStreamingHandler; - template <StatusCode code> - friend class internal::ErrorMethodHandler; - template <class R> - friend class internal::DeserializeFuncType; - friend class ProtoBufferReader; - friend class ProtoBufferWriter; - friend class internal::GrpcByteBufferPeer; - friend class internal::ExternalConnectionAcceptorImpl; - - grpc_byte_buffer* buffer_; - - // takes ownership - void set_buffer(grpc_byte_buffer* buf) { - if (buffer_) { - Clear(); - } - buffer_ = buf; - } - - grpc_byte_buffer* c_buffer() { return buffer_; } - grpc_byte_buffer** c_buffer_ptr() { return &buffer_; } - - class ByteBufferPointer { - public: - /* NOLINTNEXTLINE(google-explicit-constructor) */ - ByteBufferPointer(const ByteBuffer* b) - : bbuf_(const_cast<ByteBuffer*>(b)) {} - /* NOLINTNEXTLINE(google-explicit-constructor) */ - operator ByteBuffer*() { return bbuf_; } - /* NOLINTNEXTLINE(google-explicit-constructor) */ - operator grpc_byte_buffer*() { return bbuf_->buffer_; } - /* NOLINTNEXTLINE(google-explicit-constructor) */ - operator grpc_byte_buffer**() { return &bbuf_->buffer_; } - - private: - ByteBuffer* bbuf_; - }; - ByteBufferPointer bbuf_ptr() const { return ByteBufferPointer(this); } -}; - -template <> -class SerializationTraits<ByteBuffer, void> { - public: - static Status Deserialize(ByteBuffer* byte_buffer, ByteBuffer* dest) { - dest->set_buffer(byte_buffer->buffer_); - return Status::OK; - } - static Status Serialize(const ByteBuffer& source, ByteBuffer* buffer, - bool* own_buffer) { - *buffer = source; - *own_buffer = true; - return g_core_codegen_interface->ok(); - } -}; - -} // namespace grpc +/// TODO(chengyuc): Remove this file after solving compatibility. +#include <grpcpp/support/byte_buffer.h> #endif // GRPCPP_IMPL_CODEGEN_BYTE_BUFFER_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h index 90d54bc5d8f..71f6cb8e4e8 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h @@ -18,78 +18,9 @@ #ifndef GRPCPP_IMPL_CODEGEN_CALL_H #define GRPCPP_IMPL_CODEGEN_CALL_H -// IWYU pragma: private, include <grpcpp/impl/call.h> +// IWYU pragma: private -#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 internal { -class CallHook; -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 is owned by the caller */ - Call(grpc_call* call, CallHook* call_hook, grpc::CompletionQueue* cq) - : call_hook_(call_hook), - cq_(cq), - call_(call), - max_receive_message_size_(-1) {} - - Call(grpc_call* call, CallHook* call_hook, grpc::CompletionQueue* cq, - experimental::ClientRpcInfo* rpc_info) - : call_hook_(call_hook), - cq_(cq), - call_(call), - 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) {} - - void PerformOps(CallOpSetInterface* ops) { - call_hook_->PerformOpsOnCall(ops, this); - } - - grpc_call* call() const { return call_; } - grpc::CompletionQueue* cq() const { return cq_; } - - 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_; - } - - 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; -}; -} // namespace internal -} // namespace grpc +/// TODO(chengyuc): Remove this file after solving compatibility. +#include <grpcpp/impl/call.h> #endif // GRPCPP_IMPL_CODEGEN_CALL_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/call_hook.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/call_hook.h index 8c4278e7dc1..db10a0fc2b5 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/call_hook.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/call_hook.h @@ -21,21 +21,7 @@ // IWYU pragma: private -namespace grpc { - -namespace internal { -class CallOpSetInterface; -class Call; - -/// This is an interface that Channel and Server implement to allow them to hook -/// performing ops. -class CallHook { - public: - virtual ~CallHook() {} - virtual void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) = 0; -}; -} // namespace internal - -} // namespace grpc +/// TODO(chengyuc): Remove this file after solving compatibility. +#include <grpcpp/impl/call_hook.h> #endif // GRPCPP_IMPL_CODEGEN_CALL_HOOK_H 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 283f299f950..ce8b363d6a7 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 @@ -31,7 +31,6 @@ #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> @@ -45,6 +44,7 @@ #include <grpcpp/impl/codegen/serialization_traits.h> #include <grpcpp/impl/codegen/slice.h> #include <grpcpp/impl/codegen/string_ref.h> +#include <grpcpp/support/byte_buffer.h> namespace grpc { 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 a8eed9f6193..ce5f2036d1b 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 @@ -21,41 +21,6 @@ // IWYU pragma: private -#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 +#include <grpcpp/impl/call_op_set_interface.h> #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 f0ce27ae8fe..9280289d5ed 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/callback_common.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/callback_common.h @@ -28,7 +28,7 @@ #include <functional> #include <grpc/impl/codegen/grpc_types.h> -#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/call.h> #include <grpcpp/impl/codegen/channel_interface.h> #include <grpcpp/impl/codegen/completion_queue_tag.h> #include <grpcpp/impl/codegen/config.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 106dd56c93d..a3f162cc87c 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/channel_interface.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/channel_interface.h @@ -26,7 +26,7 @@ // IWYU pragma: private #include <grpc/impl/codegen/connectivity_state.h> -#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/call.h> #include <grpcpp/impl/codegen/status.h> #include <grpcpp/impl/codegen/time.h> diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_context.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_context.h index fc4d09a2972..d24dd38b3c1 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_context.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_context.h @@ -277,18 +277,6 @@ class ClientContext { deadline_ = deadline_tp.raw_time(); } - /// EXPERIMENTAL: Indicate that this request is idempotent. - /// By default, RPCs are assumed to <i>not</i> be idempotent. - /// - /// If true, the gRPC library assumes that it's safe to initiate - /// this RPC multiple times. - void set_idempotent(bool idempotent) { idempotent_ = idempotent; } - - /// EXPERIMENTAL: Set this request to be cacheable. - /// If set, grpc is free to use the HTTP GET verb for sending the request, - /// with the possibility of receiving a cached response. - void set_cacheable(bool cacheable) { cacheable_ = cacheable; } - /// Trigger wait-for-ready or not on this request. /// See https://github.com/grpc/grpc/blob/master/doc/wait-for-ready.md. /// If set, if an RPC is made when a channel's connectivity state is @@ -485,13 +473,10 @@ class ClientContext { } uint32_t initial_metadata_flags() const { - return (idempotent_ ? GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST : 0) | - (wait_for_ready_ ? GRPC_INITIAL_METADATA_WAIT_FOR_READY : 0) | - (cacheable_ ? GRPC_INITIAL_METADATA_CACHEABLE_REQUEST : 0) | + return (wait_for_ready_ ? GRPC_INITIAL_METADATA_WAIT_FOR_READY : 0) | (wait_for_ready_explicitly_set_ ? GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET - : 0) | - (initial_metadata_corked_ ? GRPC_INITIAL_METADATA_CORKED : 0); + : 0); } TString authority() { return authority_; } @@ -505,8 +490,6 @@ class ClientContext { bool initial_metadata_received_; bool wait_for_ready_; bool wait_for_ready_explicitly_set_; - bool idempotent_; - bool cacheable_; std::shared_ptr<grpc::Channel> channel_; grpc::internal::Mutex mu_; grpc_call* call_; 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 f3560b5ad21..1c6b8ce51f8 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_interceptor.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_interceptor.h @@ -19,181 +19,9 @@ #ifndef GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H #define GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H -// IWYU pragma: private, include <grpcpp/support/client_interceptor.h> +// IWYU pragma: private -#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 - }; - - ~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 an identifying suffix for the client stub, or nullptr if one wasn't - /// specified. - const char* suffix_for_stats() const { return suffix_for_stats_; } - - /// 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 - ClientRpcInfo(grpc::ClientContext* ctx, internal::RpcMethod::RpcType type, - const char* method, const char* suffix_for_stats, - grpc::ChannelInterface* channel) - : ctx_(ctx), - type_(static_cast<Type>(type)), - method_(method), - suffix_for_stats_(suffix_for_stats), - 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))); - } - } - - grpc::ClientContext* ctx_ = nullptr; - // TODO(yashykt): make type_ const once move-assignment is deleted - Type type_{Type::UNKNOWN}; - const char* method_ = nullptr; - const char* suffix_for_stats_ = 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 -// 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); - -// For testing purposes only -void TestOnlyResetGlobalClientInterceptorFactory(); - -} // namespace experimental -} // namespace grpc +/// TODO(chengyuc): Remove this file after solving compatibility. +#include <grpcpp/support/client_interceptor.h> #endif // GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H 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 e0440ffe3b1..340dc47faa0 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen.h @@ -107,6 +107,8 @@ class CoreCodegen final : public CoreCodegenInterface { grpc_slice grpc_slice_sub(grpc_slice s, size_t begin, size_t end) override; void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice slice) override; void grpc_slice_buffer_pop(grpc_slice_buffer* sb) override; + void grpc_slice_buffer_add_indexed(grpc_slice_buffer* sb, + grpc_slice slice) override; grpc_slice grpc_slice_from_static_buffer(const void* buffer, size_t length) override; grpc_slice grpc_slice_from_copied_buffer(const void* buffer, 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 0b23bf46e63..5ca1feff08d 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 @@ -127,6 +127,8 @@ class CoreCodegenInterface { virtual grpc_slice grpc_slice_sub(grpc_slice s, size_t begin, size_t end) = 0; virtual void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice slice) = 0; + virtual void grpc_slice_buffer_add_indexed(grpc_slice_buffer* sb, + grpc_slice slice) = 0; virtual void grpc_slice_buffer_pop(grpc_slice_buffer* sb) = 0; virtual grpc_slice grpc_slice_from_static_buffer(const void* buffer, size_t length) = 0; diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h index 0818d5c5343..b66c6656aed 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h @@ -21,13 +21,17 @@ // IWYU pragma: private, include <grpcpp/support/interceptor.h> +#include <map> #include <memory> +#include <util/generic/string.h> +#include <util/string/cast.h> #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> +#include <grpcpp/impl/codegen/string_ref.h> +#include <grpcpp/support/byte_buffer.h> namespace grpc { 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 46a5d1ac6ba..f26b82b27e1 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor_common.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor_common.h @@ -29,8 +29,8 @@ #include <functional> #include <grpc/impl/codegen/grpc_types.h> +#include <grpcpp/impl/call_op_set_interface.h> #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> diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/method_handler.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/method_handler.h index 3b6afaa2c74..4f00728b571 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/method_handler.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/method_handler.h @@ -21,10 +21,10 @@ // IWYU pragma: private, include <grpcpp/support/method_handler.h> -#include <grpcpp/impl/codegen/byte_buffer.h> #include <grpcpp/impl/codegen/core_codegen_interface.h> #include <grpcpp/impl/codegen/rpc_service_method.h> #include <grpcpp/impl/codegen/sync_stream.h> +#include <grpcpp/support/byte_buffer.h> namespace grpc { diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_buffer_reader.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_buffer_reader.h index ecc0e301091..38df095ca02 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_buffer_reader.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_buffer_reader.h @@ -26,11 +26,11 @@ #include <grpc/impl/codegen/byte_buffer_reader.h> #include <grpc/impl/codegen/grpc_types.h> #include <grpc/impl/codegen/slice.h> -#include <grpcpp/impl/codegen/byte_buffer.h> #include <grpcpp/impl/codegen/config_protobuf.h> #include <grpcpp/impl/codegen/core_codegen_interface.h> #include <grpcpp/impl/codegen/serialization_traits.h> #include <grpcpp/impl/codegen/status.h> +#include <grpcpp/support/byte_buffer.h> /// This header provides an object that reads bytes directly from a /// grpc::ByteBuffer, via the ZeroCopyInputStream interface diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_buffer_writer.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_buffer_writer.h index 552c6a70fab..34730bd2050 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_buffer_writer.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_buffer_writer.h @@ -25,11 +25,11 @@ #include <grpc/impl/codegen/grpc_types.h> #include <grpc/impl/codegen/slice.h> -#include <grpcpp/impl/codegen/byte_buffer.h> #include <grpcpp/impl/codegen/config_protobuf.h> #include <grpcpp/impl/codegen/core_codegen_interface.h> #include <grpcpp/impl/codegen/serialization_traits.h> #include <grpcpp/impl/codegen/status.h> +#include <grpcpp/support/byte_buffer.h> /// This header provides an object that writes bytes directly into a /// grpc::ByteBuffer, via the ZeroCopyOutputStream interface @@ -110,7 +110,12 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream { // On win x64, int is only 32bit GPR_CODEGEN_ASSERT(GRPC_SLICE_LENGTH(slice_) <= INT_MAX); byte_count_ += * size = static_cast<int>(GRPC_SLICE_LENGTH(slice_)); - g_core_codegen_interface->grpc_slice_buffer_add(slice_buffer_, slice_); + // Using grpc_slice_buffer_add could modify slice_ and merge it with the + // previous slice. Therefore, use grpc_slice_buffer_add_indexed method to + // ensure the slice gets added at a separate index. It can then be kept + // around and popped later in the BackUp function. + g_core_codegen_interface->grpc_slice_buffer_add_indexed(slice_buffer_, + slice_); return true; } diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_utils.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_utils.h index 4f6d87415a1..9f9eb77b532 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_utils.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/proto_utils.h @@ -26,7 +26,6 @@ #include <grpc/impl/codegen/byte_buffer_reader.h> #include <grpc/impl/codegen/grpc_types.h> #include <grpc/impl/codegen/slice.h> -#include <grpcpp/impl/codegen/byte_buffer.h> #include <grpcpp/impl/codegen/config_protobuf.h> #include <grpcpp/impl/codegen/core_codegen_interface.h> #include <grpcpp/impl/codegen/proto_buffer_reader.h> @@ -34,6 +33,7 @@ #include <grpcpp/impl/codegen/serialization_traits.h> #include <grpcpp/impl/codegen/slice.h> #include <grpcpp/impl/codegen/status.h> +#include <grpcpp/support/byte_buffer.h> /// This header provides serialization and deserialization between gRPC /// messages serialized using protobuf and the C++ objects they represent. 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 6f6730a1f18..2aa7774ab59 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 @@ -28,10 +28,10 @@ #include <vector> #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> #include <grpcpp/impl/codegen/status.h> +#include <grpcpp/support/byte_buffer.h> namespace grpc { class ServerContextBase; diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/security/auth_context.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/security/auth_context.h index 3079fecbc4f..8343832c275 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/security/auth_context.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/security/auth_context.h @@ -36,9 +36,14 @@ class SecureAuthContext; typedef std::pair<string_ref, string_ref> AuthProperty; -class AuthPropertyIterator - : public std::iterator<std::input_iterator_tag, const AuthProperty> { +class AuthPropertyIterator { public: + using iterator_category = std::forward_iterator_tag; + using value_type = const AuthProperty; + using pointer = void; + using reference = void; + using difference_type = std::ptrdiff_t; + ~AuthPropertyIterator(); AuthPropertyIterator& operator++(); AuthPropertyIterator operator++(int); diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_context.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_context.h index 7a67ecd0522..406fc908028 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_context.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_context.h @@ -117,6 +117,11 @@ class ServerContextTestSpouse; class DefaultReactorTestPeer; } // namespace testing +namespace experimental { +class OrcaServerInterceptor; +class CallMetricRecorder; +} // namespace experimental + /// Base class of ServerContext. class ServerContextBase { public: @@ -283,6 +288,19 @@ class ServerContextBase { /// Applications never need to call this method. grpc_call* c_call() { return call_.call; } + /// Get the \a CallMetricRecorder object for the current RPC. + /// Use it to record metrics during your RPC to send back to the + /// client in order to make load balancing decisions. This will + /// return nullptr if the feature hasn't been enabled using + /// \a EnableCallMetricRecording. + experimental::CallMetricRecorder* ExperimentalGetCallMetricRecorder() { + return call_metric_recorder_; + } + + /// EXPERIMENTAL API + /// Returns the call's authority. + grpc::string_ref ExperimentalGetAuthority() const; + protected: /// Async only. Has to be called before the rpc starts. /// Returns the tag in completion queue when the rpc finishes. @@ -388,6 +406,7 @@ class ServerContextBase { friend class grpc::ClientContext; friend class grpc::GenericServerContext; friend class grpc::GenericCallbackServerContext; + friend class grpc::experimental::OrcaServerInterceptor; /// Prevent copying. ServerContextBase(const ServerContextBase&); @@ -429,6 +448,8 @@ class ServerContextBase { } } + void CreateCallMetricRecorder(); + struct CallWrapper { ~CallWrapper(); @@ -466,6 +487,7 @@ class ServerContextBase { grpc::experimental::ServerRpcInfo* rpc_info_ = nullptr; RpcAllocatorState* message_allocator_state_ = nullptr; ContextAllocator* context_allocator_ = nullptr; + experimental::CallMetricRecorder* call_metric_recorder_ = nullptr; class Reactor : public grpc::ServerUnaryReactor { public: 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 031b377e4b9..62a43b1bb4e 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interface.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interface.h @@ -24,7 +24,6 @@ #include <grpc/impl/codegen/port_platform.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/completion_queue_tag.h> @@ -32,6 +31,7 @@ #include <grpcpp/impl/codegen/interceptor_common.h> #include <grpcpp/impl/codegen/rpc_service_method.h> #include <grpcpp/impl/codegen/server_context.h> +#include <grpcpp/support/byte_buffer.h> namespace grpc { diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/status.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/status.h index 358f2bb7f98..a3ab974a933 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/status.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/status.h @@ -21,6 +21,8 @@ // IWYU pragma: private, include <grpcpp/support/status.h> +#include <grpc/impl/codegen/port_platform.h> + #include <grpc/impl/codegen/status.h> #include <grpcpp/impl/codegen/config.h> #include <grpcpp/impl/codegen/status_code_enum.h> @@ -30,7 +32,7 @@ namespace grpc { /// Did it work? If it didn't, why? /// /// See \a grpc::StatusCode for details on the available code and their meaning. -class Status { +class GRPC_MUST_USE_RESULT_WHEN_USE_STRICT_WARNING Status { public: /// Construct an OK instance. Status() : code_(StatusCode::OK) { @@ -90,6 +92,10 @@ class Status { /// Construct an instance with associated \a code and \a error_message. /// It is an error to construct an OK status with non-empty \a error_message. + /// Note that \a message is intentionally accepted as a const reference + /// instead of a value (which results in a copy instead of a move) to allow + /// for easy transition to y_absl::Status in the future which accepts an + /// y_absl::string_view as a parameter. Status(StatusCode code, const TString& error_message) : code_(code), error_message_(error_message) {} diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/status_code_enum.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/status_code_enum.h index 36ea24fdfdf..6950eab57d5 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/status_code_enum.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/status_code_enum.h @@ -19,7 +19,7 @@ #ifndef GRPCPP_IMPL_CODEGEN_STATUS_CODE_ENUM_H #define GRPCPP_IMPL_CODEGEN_STATUS_CODE_ENUM_H -// IWYU pragma: private, include <grpcpp/support/status_code_enum.h> +// IWYU pragma: private, include <grpcpp/support/status.h> namespace grpc { diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/sync_stream.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/sync_stream.h index 3ed2fddcb8a..1235b8de442 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/sync_stream.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/sync_stream.h @@ -20,7 +20,7 @@ // IWYU pragma: private, include <grpcpp/support/sync_stream.h> -#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/call.h> #include <grpcpp/impl/codegen/channel_interface.h> #include <grpcpp/impl/codegen/client_context.h> #include <grpcpp/impl/codegen/completion_queue.h> @@ -222,7 +222,12 @@ class ClientReader final : public ClientReaderInterface<R> { /// The \a ClientContext associated with this call is updated with /// possible metadata received from the server. grpc::Status Finish() override { - grpc::internal::CallOpSet<grpc::internal::CallOpClientRecvStatus> ops; + grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata, + grpc::internal::CallOpClientRecvStatus> + ops; + if (!context_->initial_metadata_received_) { + ops.RecvInitialMetadata(context_); + } grpc::Status status; ops.ClientRecvStatus(context_, &status); call_.PerformOps(&ops); |