Sorry for the delayed response. You should take a look at 
greeter_async_client2.cc 
<https://github.com/grpc/grpc/blob/master/examples/cpp/helloworld/greeter_async_client2.cc>,
 
it is a good example of client code that has a dedicated thread to drive 
work forward on RPCs. In the main body of the file, we start a thread that 
loops over AsyncCompleteRpc 
<https://github.com/grpc/grpc/blob/master/examples/cpp/helloworld/greeter_async_client2.cc#L71>,
 
which will block on AsyncNext, and proceed whenever there are bytes to be 
read from the wire.

For a more complex example of this type of pattern, take a look at our QPS 
Driver <https://github.com/grpc/grpc/tree/master/test/cpp/qps> codebase 
(especially client.h and client_async.cc). That has a similar pattern, but 
allows threading to be controlled more finely (and supports all types of 
streaming).

On Monday, April 2, 2018 at 2:22:36 PM UTC-7, luca.ma...@sysdig.com wrote:
>
> Hi everyone,
>
> I'm trying to integrate gRPC in my application and I'm having some issues. 
> This is mostly the workflow I have in my app:
>
> 1. a thread that does a bunch of different things
> 2. every second reads gRPC response of the request sent last second
> 3. at the same time it sends a new gRPC request to another process
>
> It's very important for us that every second we read the response 
> calculated by the other process. What I did so far is:
>
> 1. use AsyncNext with timeout 0 on CompletionQueue to read any data 
> available
> 2. Compose a new request and send it via Stub::AsyncSayHello and Finish()
>
> (just using this an example 
> https://github.com/grpc/grpc/blob/master/examples/protos/helloworld.proto#L27,
>  
> my code is equivalent)
>
>
> But it does not quite work, basically the server responds immediately but 
> the first call to AsyncNext just gives a timeout, calling again AsyncNext 
> instead gives the response.
>
> My questions is: Isn't there any API that allows to *read anything you can 
> from the socket*?
>
> I can also just call AsyncNext multiple times until it's done but how can 
> I know that there is yet something else to parse if I just receive TIMEOUT?
>
> My understanding is that I just need to call AsyncNext to keep things 
> going, how do you suggest to implement this? Like having a different thread 
> just doing AsyncNext for all my gRPC calls?
>
> Anybody that can explain this behaviour better to me would be very 
> appreciated, I'll be happy to send PR to update documentation if afterwards 
> if needed.
>
> Thanks,
> Luca
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@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/0d839a80-1968-446a-ba54-0f2933228dac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to