Merge pull request #12 from yang-g/c++api

ServerAsyncResponseWriter and codegen change
pull/501/head
Craig Tiller 10 years ago
commit 83681967f2
  1. 47
      include/grpc++/stream.h
  2. 4
      src/compiler/cpp_generator.cc

@ -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>

@ -190,7 +190,7 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
"::grpc::ClientWriter< $Request$>* $Method$("
"::grpc::ClientContext* context, $Response$* response);\n");
printer->Print(*vars,
"::grpc::ClientWriter< $Request$>* $Method$("
"::grpc::ClientAsyncWriter< $Request$>* $Method$("
"::grpc::ClientContext* context, $Response$* response, "
"::grpc::Status *status, "
"::grpc::CompletionQueue *cq, void *tag);\n");
@ -200,7 +200,7 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
"::grpc::ClientReader< $Response$>* $Method$("
"::grpc::ClientContext* context, const $Request$* request);\n");
printer->Print(*vars,
"::grpc::ClientReader< $Response$>* $Method$("
"::grpc::ClientAsyncReader< $Response$>* $Method$("
"::grpc::ClientContext* context, const $Request$* request, "
"::grpc::CompletionQueue *cq, void *tag);\n");
} else if (BidiStreaming(method)) {

Loading…
Cancel
Save