From fd7199f64ec05c46f6aebd8644bbcb78f2889898 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Wed, 11 Feb 2015 23:14:49 -0800 Subject: Add client side WaitForInitialMetadata for streaming. --- src/cpp/common/call.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/cpp') diff --git a/src/cpp/common/call.cc b/src/cpp/common/call.cc index a20d4a0d9a..aae69084eb 100644 --- a/src/cpp/common/call.cc +++ b/src/cpp/common/call.cc @@ -121,6 +121,12 @@ void CallOpBuffer::AddSendInitialMetadata( initial_metadata_ = FillMetadataArray(metadata); } +void CallOpBuffer::AddRecvInitialMetadata( + std::multimap* metadata) { + recv_initial_metadata_ = metadata; +} + + void CallOpBuffer::AddSendInitialMetadata(ClientContext *ctx) { AddSendInitialMetadata(&ctx->send_initial_metadata_); } -- cgit v1.2.3 From 3ccdbe9bcc66f5769348ca5279f9bf5b7e700613 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Wed, 11 Feb 2015 23:56:30 -0800 Subject: Make SendInitialMetadata work. --- include/grpc++/server_context.h | 2 -- include/grpc++/stream.h | 37 +++++++++++++++++++++++-------------- src/cpp/server/server.cc | 1 - src/cpp/server/server_context.cc | 7 ------- 4 files changed, 23 insertions(+), 24 deletions(-) (limited to 'src/cpp') diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index a30f6cb51d..6cc3716291 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -75,8 +75,6 @@ class ServerContext { ServerContext(gpr_timespec deadline, grpc_metadata *metadata, size_t metadata_count); - void SendInitialMetadataIfNeeded(CallOpBuffer *buf); - const std::chrono::system_clock::time_point deadline_; bool sent_initial_metadata_ = false; std::multimap client_metadata_; diff --git a/include/grpc++/stream.h b/include/grpc++/stream.h index be518c61ed..6265310c5a 100644 --- a/include/grpc++/stream.h +++ b/include/grpc++/stream.h @@ -257,10 +257,13 @@ class ServerReader final : public ReaderInterface { ServerReader(Call* call, ServerContext* ctx) : call_(call), ctx_(ctx) {} void SendInitialMetadata() { - CallOpBuffer buf; - ctx_->SendInitialMetadataIfNeeded(&buf); - call_->PerformOps(&buf); - return call_->cq()->Pluck(&buf); + if (!ctx_->sent_initial_metadata_) { + CallOpBuffer buf; + buf.AddSendInitialMetadata(&ctx_->initial_metadata_); + ctx_->sent_initial_metadata_ = true; + call_->PerformOps(&buf); + call_->cq()->Pluck(&buf); + } } virtual bool Read(R* msg) override { @@ -282,15 +285,18 @@ class ServerWriter final : public WriterInterface { ServerWriter(Call* call, ServerContext* ctx) : call_(call), ctx_(ctx) {} void SendInitialMetadata() { - CallOpBuffer buf; - ctx_->SendInitialMetadataIfNeeded(&buf); - call_->PerformOps(&buf); - return call_->cq()->Pluck(&buf); + if (!ctx_->sent_initial_metadata_) { + CallOpBuffer buf; + buf.AddSendInitialMetadata(&ctx_->initial_metadata_); + ctx_->sent_initial_metadata_ = true; + call_->PerformOps(&buf); + call_->cq()->Pluck(&buf); + } } virtual bool Write(const W& msg) override { + SendInitialMetadata(); CallOpBuffer buf; - ctx_->SendInitialMetadataIfNeeded(&buf); buf.AddSendMessage(msg); call_->PerformOps(&buf); return call_->cq()->Pluck(&buf); @@ -309,10 +315,13 @@ class ServerReaderWriter final : public WriterInterface, ServerReaderWriter(Call* call, ServerContext* ctx) : call_(call), ctx_(ctx) {} void SendInitialMetadata() { - CallOpBuffer buf; - ctx_->SendInitialMetadataIfNeeded(&buf); - call_->PerformOps(&buf); - return call_->cq()->Pluck(&buf); + if (!ctx_->sent_initial_metadata_) { + CallOpBuffer buf; + buf.AddSendInitialMetadata(&ctx_->initial_metadata_); + ctx_->sent_initial_metadata_ = true; + call_->PerformOps(&buf); + call_->cq()->Pluck(&buf); + } } virtual bool Read(R* msg) override { @@ -324,8 +333,8 @@ class ServerReaderWriter final : public WriterInterface, } virtual bool Write(const W& msg) override { + SendInitialMetadata(); CallOpBuffer buf; - ctx_->SendInitialMetadataIfNeeded(&buf); buf.AddSendMessage(msg); call_->PerformOps(&buf); return call_->cq()->Pluck(&buf); diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 17b0543bcd..630b16ba0b 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -177,7 +177,6 @@ class Server::MethodRequestData final : public CompletionQueueTag { auto status = method_->handler()->RunHandler( MethodHandler::HandlerParameter(&call_, &ctx_, req.get(), res.get())); CallOpBuffer buf; - ctx_.SendInitialMetadataIfNeeded(&buf); if (has_response_payload_) { buf.AddSendMessage(*res); } diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index 06eeb39297..1823dfc81b 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -49,11 +49,4 @@ ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata *metadata, } } -void ServerContext::SendInitialMetadataIfNeeded(CallOpBuffer* buf) { - if (!sent_initial_metadata_) { - buf->AddSendInitialMetadata(&initial_metadata_); - sent_initial_metadata_ = true; - } -} - } // namespace grpc -- cgit v1.2.3