aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2018-03-19 23:28:29 -0700
committerGravatar Vijay Pai <vpai@google.com>2018-03-20 08:46:28 -0700
commitcdddc8ce421f120ca038c83f2a3628544beae21f (patch)
treea81d7f1d307f791971a4504983deeebb01a46ce6 /include
parent9bef1390540e7662b6d941c0a17f136b10ffc084 (diff)
Desneak client unary call, avoid Hyrum's Law (used for 1-thread simplicity)
Diffstat (limited to 'include')
-rw-r--r--include/grpcpp/impl/codegen/async_unary_call.h51
1 files changed, 29 insertions, 22 deletions
diff --git a/include/grpcpp/impl/codegen/async_unary_call.h b/include/grpcpp/impl/codegen/async_unary_call.h
index 255f874e26..60ff8e2f05 100644
--- a/include/grpcpp/impl/codegen/async_unary_call.h
+++ b/include/grpcpp/impl/codegen/async_unary_call.h
@@ -126,9 +126,10 @@ class ClientAsyncResponseReader final
assert(started_);
GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_);
- meta_buf.set_output_tag(tag);
- meta_buf.RecvInitialMetadata(context_);
- call_.PerformOps(&meta_buf);
+ single_buf.set_output_tag(tag);
+ single_buf.RecvInitialMetadata(context_);
+ call_.PerformOps(&single_buf);
+ initial_metadata_read_ = true;
}
/// See \a ClientAysncResponseReaderInterface::Finish for semantics.
@@ -138,14 +139,20 @@ class ClientAsyncResponseReader final
/// possible initial and trailing metadata sent from the server.
void Finish(R* msg, Status* status, void* tag) override {
assert(started_);
- finish_buf.set_output_tag(tag);
- if (!context_->initial_metadata_received_) {
- finish_buf.RecvInitialMetadata(context_);
+ if (initial_metadata_read_) {
+ finish_buf.set_output_tag(tag);
+ finish_buf.RecvMessage(msg);
+ finish_buf.AllowNoMessage();
+ finish_buf.ClientRecvStatus(context_, status);
+ call_.PerformOps(&finish_buf);
+ } else {
+ single_buf.set_output_tag(tag);
+ single_buf.RecvInitialMetadata(context_);
+ single_buf.RecvMessage(msg);
+ single_buf.AllowNoMessage();
+ single_buf.ClientRecvStatus(context_, status);
+ call_.PerformOps(&single_buf);
}
- finish_buf.RecvMessage(msg);
- finish_buf.AllowNoMessage();
- finish_buf.ClientRecvStatus(context_, status);
- call_.PerformOps(&finish_buf);
}
private:
@@ -153,6 +160,7 @@ class ClientAsyncResponseReader final
ClientContext* const context_;
::grpc::internal::Call call_;
bool started_;
+ bool initial_metadata_read_ = false;
template <class W>
ClientAsyncResponseReader(::grpc::internal::Call call, ClientContext* context,
@@ -160,30 +168,29 @@ class ClientAsyncResponseReader final
: context_(context), call_(call), started_(start) {
// Bind the metadata at time of StartCallInternal but set up the rest here
// TODO(ctiller): don't assert
- GPR_CODEGEN_ASSERT(init_buf.SendMessage(request).ok());
- init_buf.ClientSendClose();
+ GPR_CODEGEN_ASSERT(single_buf.SendMessage(request).ok());
+ single_buf.ClientSendClose();
if (start) StartCallInternal();
}
void StartCallInternal() {
- init_buf.SendInitialMetadata(context_->send_initial_metadata_,
- context_->initial_metadata_flags());
- call_.PerformOps(&init_buf);
+ single_buf.SendInitialMetadata(context_->send_initial_metadata_,
+ context_->initial_metadata_flags());
}
// disable operator new
static void* operator new(std::size_t size);
static void* operator new(std::size_t size, void* p) { return p; }
- ::grpc::internal::SneakyCallOpSet<::grpc::internal::CallOpSendInitialMetadata,
- ::grpc::internal::CallOpSendMessage,
- ::grpc::internal::CallOpClientSendClose>
- init_buf;
- ::grpc::internal::CallOpSet<::grpc::internal::CallOpRecvInitialMetadata>
- meta_buf;
- ::grpc::internal::CallOpSet<::grpc::internal::CallOpRecvInitialMetadata,
+ ::grpc::internal::CallOpSet<::grpc::internal::CallOpSendInitialMetadata,
+ ::grpc::internal::CallOpSendMessage,
+ ::grpc::internal::CallOpClientSendClose,
+ ::grpc::internal::CallOpRecvInitialMetadata,
::grpc::internal::CallOpRecvMessage<R>,
::grpc::internal::CallOpClientRecvStatus>
+ single_buf;
+ ::grpc::internal::CallOpSet<::grpc::internal::CallOpRecvMessage<R>,
+ ::grpc::internal::CallOpClientRecvStatus>
finish_buf;
};