diff options
author | Vijay Pai <vpai@google.com> | 2015-03-12 05:16:31 -0700 |
---|---|---|
committer | Vijay Pai <vpai@google.com> | 2015-03-12 05:16:31 -0700 |
commit | 3e0a46a1c4297b2d8fd0f05162bf551f3bae78b5 (patch) | |
tree | 3253bd81f7813ac617d8f0c1daad2b60405de03e /include/grpc++/completion_queue.h | |
parent | ee705f6d6681fb22e0b364999763cf84a2cb1197 (diff) |
Change behavior to properly account for possibility of NULL
tag. This can happen if the tag is actually an integer being
typecast to void*
To avoid breaking the API of existing Next calls, I've made
a new AsyncNext method with a tri-state return that indicates
whether there is a shutdown, an actual event, or a timeout.
Still needs proper testing for the AsyncNext method specifically.
Diffstat (limited to 'include/grpc++/completion_queue.h')
-rw-r--r-- | include/grpc++/completion_queue.h | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h index db6e6d41f3..ffa53698bb 100644 --- a/include/grpc++/completion_queue.h +++ b/include/grpc++/completion_queue.h @@ -76,10 +76,19 @@ class CompletionQueue { explicit CompletionQueue(grpc_completion_queue *take); ~CompletionQueue(); + // Tri-state return for Next: SHUTDOWN, GOT_EVENT, TIMEOUT + enum NextStatus {SHUTDOWN, GOT_EVENT, TIMEOUT}; + // Blocking (until deadline) read from queue. - // Returns false if the queue is ready for destruction, true otherwise - // If the deadline passed, *tag will be null - bool Next(void **tag, bool *ok, gpr_timespec deadline=gpr_inf_future); + // Returns false if the queue is ready for destruction, true if event + + bool Next(void **tag, bool *ok) { + return (AsyncNext(tag,ok,gpr_inf_future) != SHUTDOWN); + } + + // Nonblocking (until deadline) read from queue. + // Cannot rely on result of tag or ok if return is TIMEOUT + NextStatus AsyncNext(void **tag, bool *ok, gpr_timespec deadline); // Shutdown has to be called, and the CompletionQueue can only be // destructed when false is returned from Next(). |