|
|
|
@ -582,17 +582,52 @@ class ClientAsyncReaderWriter final : public ClientAsyncStreamingInterface, |
|
|
|
|
template <class W> |
|
|
|
|
class ServerAsyncResponseWriter final { |
|
|
|
|
public: |
|
|
|
|
explicit ServerAsyncResponseWriter(Call* call) : call_(call) {} |
|
|
|
|
ServerAsyncResponseWriter(Call* call, ServerContext* ctx) |
|
|
|
|
: call_(call), ctx_(ctx) {} |
|
|
|
|
|
|
|
|
|
virtual void Write(const W& msg, void* tag) override { |
|
|
|
|
CallOpBuffer buf; |
|
|
|
|
buf.Reset(tag); |
|
|
|
|
buf.AddSendMessage(msg); |
|
|
|
|
call_->PerformOps(&buf); |
|
|
|
|
void SendInitialMetadata(void* tag) { |
|
|
|
|
GPR_ASSERT(!ctx_->sent_initial_metadata_); |
|
|
|
|
|
|
|
|
|
meta_buf_.Reset(tag); |
|
|
|
|
meta_buf_.AddSendInitialMetadata(&ctx_->initial_metadata_); |
|
|
|
|
ctx_->sent_initial_metadata_ = true; |
|
|
|
|
call_->PerformOps(&meta_buf_); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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: |
|
|
|
|
Call* call_; |
|
|
|
|
ServerContext* ctx_; |
|
|
|
|
CallOpBuffer meta_buf_; |
|
|
|
|
CallOpBuffer finish_buf_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <class R> |
|
|
|
|