aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/util/cli_call.cc
diff options
context:
space:
mode:
authorGravatar Yuchen Zeng <zyc@google.com>2016-09-09 20:05:37 -0700
committerGravatar Yuchen Zeng <zyc@google.com>2016-12-15 16:10:37 -0800
commitd37f642f359cb7fd7405831e675abb93fd4704e2 (patch)
treec91596b19971b347cd039c99051818ddf4dd7eda /test/cpp/util/cli_call.cc
parentf9329217b1ce334a19b8720f70a17ce8f5d5db23 (diff)
Support server streaming
Skip unparsable input Add tests for uni-directional stream calls Simplify client stream handling
Diffstat (limited to 'test/cpp/util/cli_call.cc')
-rw-r--r--test/cpp/util/cli_call.cc42
1 files changed, 21 insertions, 21 deletions
diff --git a/test/cpp/util/cli_call.cc b/test/cpp/util/cli_call.cc
index d9232ec4b6..1101abe3c9 100644
--- a/test/cpp/util/cli_call.cc
+++ b/test/cpp/util/cli_call.cc
@@ -48,8 +48,6 @@ namespace {
void* tag(int i) { return (void*)(intptr_t)i; }
} // namespace
-enum CliCall::CallStatus : intptr_t { CREATE, PROCESS, FINISH };
-
Status CliCall::Call(std::shared_ptr<grpc::Channel> channel,
const grpc::string& method, const grpc::string& request,
grpc::string* response,
@@ -59,7 +57,9 @@ Status CliCall::Call(std::shared_ptr<grpc::Channel> channel,
CliCall call(channel, method, metadata);
call.Write(request);
call.WritesDone();
- call.Read(response, server_initial_metadata);
+ if (!call.Read(response, server_initial_metadata)) {
+ fprintf(stderr, "Failed to read response.\n");
+ }
return call.Finish(server_trailing_metadata);
}
@@ -92,36 +92,36 @@ void CliCall::Write(const grpc::string& request) {
GPR_ASSERT(ok);
}
-void CliCall::Read(grpc::string* response,
+bool CliCall::Read(grpc::string* response,
IncomingMetadataContainer* server_initial_metadata) {
void* got_tag;
bool ok;
grpc::ByteBuffer recv_buffer;
- call_->Read(&recv_buffer, tag(4));
- cq_.Next(&got_tag, &ok);
- if (!ok) {
- fprintf(stderr, "Failed to read response.");
- } else {
- std::vector<grpc::Slice> slices;
- (void)recv_buffer.Dump(&slices);
-
- response->clear();
- for (size_t i = 0; i < slices.size(); i++) {
- response->append(reinterpret_cast<const char*>(slices[i].begin()),
- slices[i].size());
- }
- if (server_initial_metadata) {
- *server_initial_metadata = ctx_.GetServerInitialMetadata();
- }
+ call_->Read(&recv_buffer, tag(3));
+
+ if (!cq_.Next(&got_tag, &ok) || !ok) {
+ return false;
+ }
+ std::vector<grpc::Slice> slices;
+ recv_buffer.Dump(&slices);
+
+ response->clear();
+ for (size_t i = 0; i < slices.size(); i++) {
+ response->append(reinterpret_cast<const char*>(slices[i].begin()),
+ slices[i].size());
+ }
+ if (server_initial_metadata) {
+ *server_initial_metadata = ctx_.GetServerInitialMetadata();
}
+ return true;
}
void CliCall::WritesDone() {
void* got_tag;
bool ok;
- call_->WritesDone(tag(3));
+ call_->WritesDone(tag(4));
cq_.Next(&got_tag, &ok);
GPR_ASSERT(ok);
}