Make SendInitialMetadata work.

pull/501/head
Yang Gao 10 years ago
parent b492f06c9d
commit 3ccdbe9bcc
  1. 2
      include/grpc++/server_context.h
  2. 37
      include/grpc++/stream.h
  3. 1
      src/cpp/server/server.cc
  4. 7
      src/cpp/server/server_context.cc

@ -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<grpc::string, grpc::string> client_metadata_;

@ -257,10 +257,13 @@ class ServerReader final : public ReaderInterface<R> {
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<W> {
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<W>,
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<W>,
}
virtual bool Write(const W& msg) override {
SendInitialMetadata();
CallOpBuffer buf;
ctx_->SendInitialMetadataIfNeeded(&buf);
buf.AddSendMessage(msg);
call_->PerformOps(&buf);
return call_->cq()->Pluck(&buf);

@ -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);
}

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

Loading…
Cancel
Save