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;
}
}
Le jeudi 16 mars 2017 18:47:51 UTC+1, Julien a écrit :
>
> Hello,
>
> 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;
> }
> }
> }
>
> Unfortunately, this does not exactly work properly.
> Strangely, the client receives an additionnal Feature objet at the
> beginning of the stream. Here is the relevant part of the output of the
> client:
> -------------- ListFeatures --------------
> Looking for features between 40, -75 and 42, -73
> *Found feature called at 0, 0* * <---------- empty feature*
> Found feature called PatriotsPath,Mendham,NJ07945,USA at 40.7838, -74.6144
> Found feature called 101NewJersey10,Whippany,NJ07981,USA at 40.8123,
> -74.3999
> Found feature called U.S.6,Shohola,PA18458,USA at 41.3628, -74.9016
> ...
>
> This empty feature is not received with the original sync client.
>
> So what am I doing wrong in my above code?
>
> Note: I use grpc 1.1.4 and protobuf 3.2.0.
>
> Thank you in advance for your help.
>
> Julien
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
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/f27c60cb-d198-4ca2-a43a-53d9895ac57d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.