MuffinsResponse reply;
// Context for the client. It could be used to convey extra information to
// the server and/or tweak certain RPC behaviors.
ClientContext context;
// The producer-consumer queue we use to communicate asynchronously with the
// gRPC runtime.
CompletionQueue cq;
// Storage for the status of the RPC upon completion.
Status status;
void* got_tag_read;
void* got_tag_write;
void* got_tag_finish;
bool ok = false;
// stub_->AsyncSendMuffins() performs the RPC call, returning an instance we
// store in "rpc". Because we are using the asynchronous API, we need to
// hold on to the "rpc" instance in order to get updates on the ongoing RPC.i
std::unique_ptr<grpc::ClientAsyncReaderWriter<Muffins::MuffinsMessage, Muffins::MuffinsResponse>> stream(
stub_->AsyncSendMuffins(&context, &cq, got_tag_read));
// Request that, upon completion of the RPC, "reply" be updated with the
// server's response; "status" with the indication of whether the operation
// was successful. Tag the request with the integer 1.
// rpc->Finish(&reply, &status, (void*)1);
stream->Write(request, got_tag_write);
std::string req = request.muffin_description();
std::cout << "The req sent is " << req << std::endl;
cq.Next(&got_tag_write, &ok);
if (ok && got_tag_write == (void*)1) {
printf("\n CLient sent the req");
stream->Read(&reply, got_tag_read);
}
cq.Next(&got_tag_read, &ok);
if (ok && got_tag_read == (void*)1) {
stream->Finish(&status, got_tag_finish);
}
cq.Next(&got_tag_finish, &ok);
GPR_ASSERT(ok);
if (status.ok()) {
return reply.Muffin_description();
} else {
return "RPC failed";
}
}