I am unsure about how to use the ServerContext::isCanceled() functionality.

The ServerContext documentation (source code) says:  
// IsCancelled is always safe to call when using sync API
// When using async API, it is only safe to call IsCancelled after
// the AsyncNotifyWhenDone tag has been delivered
bool IsCancelled() const;

// Async only. Has to be called before the rpc starts.
// Returns the tag in completion queue when the rpc finishes.
// IsCancelled() can then be called to check whether the rpc was cancelled.
void AsyncNotifyWhenDone(void* tag) {
 has_notify_when_done_tag_ = true;
 async_notify_when_done_tag_ = tag;

I have a function checking the ServerCompletionQueue as follows:
      template <class REP, class PERIOD>
   bool getFor(std::chrono::duration<REP, PERIOD> timeout)
          void* tag;
     bool ok;

     typedef ::grpc::ServerCompletionQueue::NextStatus NextStatus;
     NextStatus nextStatus = notification_cq->AsyncNext(&tag, &ok, 
std::chrono::system_clock::now() + timeout);

     if(nextStatus == NextStatus::SHUTDOWN)
       return false;
     else if(nextStatus == NextStatus::TIMEOUT)
       return false;
     else if(nextStatus == NextStatus::GOT_EVENT)
         PROCOM_DEBUG("NOT OK, RPC canceled or timed out or client 
       return true;
     return false;
ICallMetadata is a class which basically does what CallData does in the 
gRPC Async C++ examples.

What I want to do is the following:
If a client does multiple asynchronous calls, and cancels some of them at a 
later time, before they are processed (thus before AsyncNext got the new 
I want to never process the canceled calls. 

What I see is that I still get the event in the CompletionQueue (side note: 
And sometimes I get a not OK event, what does this mean exactly besides 
what the source comment says: "Upon success, true if read a regular event, 
false otherwise.". What is a regular event and what is a non-regular event? 
Is there some documentation about this?)

I can call AsyncNotifyWhenDone when creating a CallData object, but which 
tag should I use? (void*) CallData*? 
When receiving such a tag in the CompletionQueue, how do I know if I can 
safely call  IsCancelled()? 
So basically how am I supposed to match a AsyncNotifyWhenDone tag to a 
CallData tag? Is there some example where AsyncNotifyWhenDone is used?

If you need more information, please let me know.

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 
For more options, visit https://groups.google.com/d/optout.

Reply via email to