I am trying to use the async stream in a C++ client.
I made some trials by modifying the route_guide example, with the ListFeatures rpc method from the RouteGuide service.
In the provided client, the ListFeatures() method is called with the sync interface. So I tried to call it with the async interface.
I have thus changed the ListFeatures() function from the route_guide_client.cc file as follow: void ListFeatures() {
routeguide::Rectangle rect;
Feature feature;
ClientContext context;
rect.mutable_lo()->set_latitude(400000000);
rect.mutable_lo()->set_longitude(-750000000);
rect.mutable_hi()->set_latitude(420000000);
rect.mutable_hi()->set_longitude(-730000000);
std::cout << "Looking for features between 40, -75 and 42, -73"
<< std::endl;
CompletionQueue cq;
std::unique_ptr<ClientAsyncReader<Feature> > reader(stub_->AsyncListFeatures(&context, rect,&cq,(void*)1));
void* got_tag;
bool ok;
while (1) {
ok = false;
bool ret = cq.Next(&got_tag, &ok);
if (!ret || !ok) {
break;
}
reader->Read(&feature,got_tag);
if (got_tag == (void*)1) {
std::cout << "Found feature called "
<< feature.name() << " at "
<< feature.location().latitude()/kCoordFactor_ << ", "
<< feature.location().longitude()/kCoordFactor_ << std::endl;
}
}
}--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/3c73c2fa-a8d7-49a7-9e1a-f9187aa8b465%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
CompletionQueue cq;
std::unique_ptr<ClientAsyncReader<Feature> > reader(stub_->AsyncListFeatures(&context, rect,&cq,(void*)1));
void* got_tag;
bool ok;
bool ret = cq.Next(&got_tag, &ok);
if (ret && ok && got_tag == (void*)1) {
while (1) {
reader->Read(&feature,(void*)1);
ok = false;
ret = cq.Next(&got_tag, &ok);
if (!ret || !ok || got_tag != (void*)1) {
break;
}
std::cout << "Found feature called "
<< feature.name() << " at "
<< feature.location().latitude()/kCoordFactor_ << ", "
<< feature.location().longitude()/kCoordFactor_ << std::endl;
}
}