change ServerAsyncReader API and add a simple clientstreaming test, it passes
diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h
index 64091a4..423ebf2 100644
--- a/include/grpc++/server_context.h
+++ b/include/grpc++/server_context.h
@@ -45,7 +45,7 @@
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 ecc28f6..6ee550b 100644
--- a/include/grpc++/stream.h
+++ b/include/grpc++/stream.h
@@ -615,7 +615,7 @@
CallOpBuffer finish_buf_;
};
-template <class R>
+template <class W, class R>
class ServerAsyncReader : public ServerAsyncStreamingInterface,
public AsyncReaderInterface<R> {
public:
@@ -637,7 +637,24 @@
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_);
@@ -649,7 +666,6 @@
call_.PerformOps(&finish_buf_);
}
-
private:
void BindCall(Call *call) override { call_ = *call; }