diff options
author | Yuchen Zeng <zyc@google.com> | 2016-10-24 13:00:10 -0700 |
---|---|---|
committer | Yuchen Zeng <zyc@google.com> | 2016-10-24 13:00:10 -0700 |
commit | d30699c7bebfa3cb0ad4ba1eac99284a52b7859f (patch) | |
tree | 32ed6c891354680361699707301273eee4c9ac54 /include/grpc++ | |
parent | 654aa869d2817a9be127f66df8cd8b18e7b760bc (diff) | |
parent | 13ca42dbae2656b97b3e40e0fa8b63aae7fd5dd5 (diff) |
Merge remote-tracking branch 'upstream/master' into reflection_header
Diffstat (limited to 'include/grpc++')
-rw-r--r-- | include/grpc++/impl/codegen/method_handler_impl.h | 13 | ||||
-rw-r--r-- | include/grpc++/impl/codegen/server_context.h | 1 | ||||
-rw-r--r-- | include/grpc++/impl/codegen/service_type.h | 11 | ||||
-rw-r--r-- | include/grpc++/impl/codegen/sync_stream.h | 39 |
4 files changed, 57 insertions, 7 deletions
diff --git a/include/grpc++/impl/codegen/method_handler_impl.h b/include/grpc++/impl/codegen/method_handler_impl.h index 52f927631c..bb992f0e18 100644 --- a/include/grpc++/impl/codegen/method_handler_impl.h +++ b/include/grpc++/impl/codegen/method_handler_impl.h @@ -236,6 +236,19 @@ class StreamedUnaryHandler ServerUnaryStreamer<RequestType, ResponseType>, true>(func) {} }; +template <class RequestType, class ResponseType> +class SplitServerStreamingHandler + : public TemplatedBidiStreamingHandler< + ServerSplitStreamer<RequestType, ResponseType>, false> { + public: + explicit SplitServerStreamingHandler( + std::function<Status(ServerContext*, + ServerSplitStreamer<RequestType, ResponseType>*)> + func) + : TemplatedBidiStreamingHandler< + ServerSplitStreamer<RequestType, ResponseType>, false>(func) {} +}; + // Handle unknown method by returning UNIMPLEMENTED error. class UnknownMethodHandler : public MethodHandler { public: diff --git a/include/grpc++/impl/codegen/server_context.h b/include/grpc++/impl/codegen/server_context.h index 975f710f13..ddf50b019d 100644 --- a/include/grpc++/impl/codegen/server_context.h +++ b/include/grpc++/impl/codegen/server_context.h @@ -44,7 +44,6 @@ #include <grpc++/impl/codegen/time.h> #include <grpc/impl/codegen/compression_types.h> -struct gpr_timespec; struct grpc_metadata; struct grpc_call; struct census_context; diff --git a/include/grpc++/impl/codegen/service_type.h b/include/grpc++/impl/codegen/service_type.h index 72b2225312..bd65ea009e 100644 --- a/include/grpc++/impl/codegen/service_type.h +++ b/include/grpc++/impl/codegen/service_type.h @@ -147,14 +147,15 @@ class Service { methods_[index].reset(); } - void MarkMethodStreamedUnary(int index, - MethodHandler* streamed_unary_method) { + void MarkMethodStreamed(int index, MethodHandler* streamed_method) { GPR_CODEGEN_ASSERT(methods_[index] && methods_[index]->handler() && - "Cannot mark an async or generic method Streamed Unary"); - methods_[index]->SetHandler(streamed_unary_method); + "Cannot mark an async or generic method Streamed"); + methods_[index]->SetHandler(streamed_method); // From the server's point of view, streamed unary is a special - // case of BIDI_STREAMING that has 1 read and 1 write, in that order. + // case of BIDI_STREAMING that has 1 read and 1 write, in that order, + // and split server-side streaming is BIDI_STREAMING with 1 read and + // any number of writes, in that order methods_[index]->SetMethodType(::grpc::RpcMethod::BIDI_STREAMING); } diff --git a/include/grpc++/impl/codegen/sync_stream.h b/include/grpc++/impl/codegen/sync_stream.h index e3c5a919b1..9a3efb5119 100644 --- a/include/grpc++/impl/codegen/sync_stream.h +++ b/include/grpc++/impl/codegen/sync_stream.h @@ -538,7 +538,7 @@ class ServerReaderWriter GRPC_FINAL : public ServerReaderWriterInterface<W, R> { /// the \a NextMessageSize method to determine an upper-bound on the size of /// the message. /// A key difference relative to streaming: ServerUnaryStreamer -/// must have exactly 1 Read and exactly 1 Write, in that order, to function +/// must have exactly 1 Read and exactly 1 Write, in that order, to function /// correctly. Otherwise, the RPC is in error. template <class RequestType, class ResponseType> class ServerUnaryStreamer GRPC_FINAL @@ -577,6 +577,43 @@ class ServerUnaryStreamer GRPC_FINAL bool write_done_; }; +/// A class to represent a flow-controlled server-side streaming call. +/// This is something of a hybrid between server-side and bidi streaming. +/// This is invoked through a server-side streaming call on the client side, +/// but the server responds to it as though it were a bidi streaming call that +/// must first have exactly 1 Read and then any number of Writes. +template <class RequestType, class ResponseType> +class ServerSplitStreamer GRPC_FINAL + : public ServerReaderWriterInterface<ResponseType, RequestType> { + public: + ServerSplitStreamer(Call* call, ServerContext* ctx) + : body_(call, ctx), read_done_(false) {} + + void SendInitialMetadata() GRPC_OVERRIDE { body_.SendInitialMetadata(); } + + bool NextMessageSize(uint32_t* sz) GRPC_OVERRIDE { + return body_.NextMessageSize(sz); + } + + bool Read(RequestType* request) GRPC_OVERRIDE { + if (read_done_) { + return false; + } + read_done_ = true; + return body_.Read(request); + } + + using WriterInterface<ResponseType>::Write; + bool Write(const ResponseType& response, + const WriteOptions& options) GRPC_OVERRIDE { + return read_done_ && body_.Write(response, options); + } + + private: + internal::ServerReaderWriterBody<ResponseType, RequestType> body_; + bool read_done_; +}; + } // namespace grpc #endif // GRPCXX_IMPL_CODEGEN_SYNC_STREAM_H |