[C++] Java onError equivalent in C++

25 views
Skip to first unread message

dixi.y...@gmail.com

unread,
May 13, 2019, 10:16:47 AM5/13/19
to grpc.io

Hi,
I have gRPC server with bidirectional method, that receive some numbers in stream and the server streams some numbers back, totally async.
But if the number is not good (for some reason), the server that written in java invokes the observer.onError().

I have client implemented in Java for that server, and when the server raise error in catchs in the client receiver observer on the onError() and everything is fine.
Now I want to write C++ implementation of this client but something is different. In C++ there is no way to register for error events, I could get the error only after I invoke the stream->Finish(), but it's not good for me because we are talking about long living streams, unbounded. I can't wait for the finish to get the error - I must know when the server raised an error WHILE I send the numbers from client to server.

In other words, what is the equivalent of java SessionObserver.onError() in C++? How can I be notified when the server raise onError()?

Yang Gao

unread,
May 15, 2019, 1:50:52 PM5/15/19
to grpc.io
If the server returns an error status, the read/write calls on the client side will fail and the status can be obtained via Finish.
I do not think there is another way to do it.

dixi.y...@gmail.com

unread,
May 16, 2019, 11:52:02 AM5/16/19
to grpc.io
I already figured it out and it is working good!
I didn't understand the effect of errors on the read/write operations.

Thank you.
Reply all
Reply to author
Forward
0 new messages