diff options
author | Yang Gao <yangg@google.com> | 2015-02-13 10:22:33 -0800 |
---|---|---|
committer | Yang Gao <yangg@google.com> | 2015-02-13 10:22:33 -0800 |
commit | 005f18a6a1b2f52ba841d885f93bc2250c8683fa (patch) | |
tree | 5a04f9b5944d66d8672dcd0d41c458478a5b48fb /include/grpc++ | |
parent | c05b6cb89d09a326a3a63e83e8399cc38e93a007 (diff) |
change ServerAsyncReader API and add a simple clientstreaming test, it passes
Diffstat (limited to 'include/grpc++')
-rw-r--r-- | include/grpc++/server_context.h | 2 | ||||
-rw-r--r-- | include/grpc++/stream.h | 20 |
2 files changed, 19 insertions, 3 deletions
diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index 64091a4505..423ebf2337 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -45,7 +45,7 @@ struct grpc_call; namespace grpc { -template <class R> +template <class W, class R> class ServerAsyncReader; template <class W> class ServerAsyncWriter; diff --git a/include/grpc++/stream.h b/include/grpc++/stream.h index ecc28f6216..6ee550bd64 100644 --- a/include/grpc++/stream.h +++ b/include/grpc++/stream.h @@ -615,7 +615,7 @@ class ServerAsyncResponseWriter final : public ServerAsyncStreamingInterface { CallOpBuffer finish_buf_; }; -template <class R> +template <class W, class R> class ServerAsyncReader : public ServerAsyncStreamingInterface, public AsyncReaderInterface<R> { public: @@ -637,18 +637,34 @@ class ServerAsyncReader : public ServerAsyncStreamingInterface, call_.PerformOps(&read_buf_); } - void Finish(const Status& status, void* tag) { + void Finish(const W& msg, const Status& status, void* tag) { finish_buf_.Reset(tag); if (!ctx_->sent_initial_metadata_) { finish_buf_.AddSendInitialMetadata(&ctx_->initial_metadata_); ctx_->sent_initial_metadata_ = true; } + // The response is dropped if the status is not OK. + if (status.IsOk()) { + finish_buf_.AddSendMessage(msg); + } bool cancelled = false; finish_buf_.AddServerRecvClose(&cancelled); finish_buf_.AddServerSendStatus(&ctx_->trailing_metadata_, status); call_.PerformOps(&finish_buf_); } + void FinishWithError(const Status& status, void* tag) { + GPR_ASSERT(!status.IsOk()); + finish_buf_.Reset(tag); + if (!ctx_->sent_initial_metadata_) { + finish_buf_.AddSendInitialMetadata(&ctx_->initial_metadata_); + ctx_->sent_initial_metadata_ = true; + } + bool cancelled = false; + finish_buf_.AddServerRecvClose(&cancelled); + finish_buf_.AddServerSendStatus(&ctx_->trailing_metadata_, status); + call_.PerformOps(&finish_buf_); + } private: void BindCall(Call *call) override { call_ = *call; } |