Reputation: 574
I noticed grpc supports deadline setting.
auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec);
context->set_deadline(deadline);
But for the following code
// context_ and stream_ has already been created beforehand.
UpdateClientDeadline(context_.get(), timeout_sec);
stream_->Read(response);
Deadline doesn't work here (I checked by sleeping indefinitely long time at server-side).
I know re-creating stream works. But to keep high performance, that doesn't seem to be a solution to me.
Wondering what's the standard way to implement that in C++ grpc?
Upvotes: 1
Views: 2394
Reputation: 1111
Deadlines don't exist in gRPC per-send/receive operation, only per-stream (start to finish). If you need to enforce a deadline per message, you'll need to keep track of that on your own end and cancel the RPC if the deadline is met.
Upvotes: 3