What's the right way to use grpc_impl::ServerAsyncReader ? (C++)

43 views
Skip to first unread message

guru pucu

unread,
Oct 9, 2020, 3:50:37 AM10/9/20
to grpc.io
Hi,

I'm exploring a way to let client side send streaming request to server (async call with cq). From the server side I got a ServerAsyncReader<W, R> object, which has a read function to read the request stream. However, the function confuses me and I couldn't find any answer to my Q from the document.

When I tested the function, it looks like it is a non-blocking call, which means the server will not wait for client to write to request stream if there's nothing to read. However, the function has no return value. So, what would I get if there's nothing to read? From the doc the cq notification means the read completes, but does not mean there's more request to read. How do the server know many times it should read from the input stream, and what happens if it reads more / faster than the client writes?

Another issue I keep hitting is, the code keeps crashing when calling next on cq. In my code I make the server to pause after receiving the rpc call, wait until the client calls writesdone on ClientAsyncWriter, then start reading from the ServerAsyncReader object. However, the request read from ServerAsyncReader is always garbage, and the code crash right after I call next on the cq.

I searched around but couldn't find any useful sample code / flow chart about how the client / server work in such setup. Is there any document about how to use this class?

Thank you.

Malek Musleh

unread,
Apr 30, 2021, 6:53:44 PMApr 30
to grpc.io
HI,

I actually have the same question. Did you figure this out?

Malek

Reply all
Reply to author
Forward
0 new messages