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 /src | |
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 'src')
-rw-r--r-- | src/cpp/common/completion_queue.cc | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/cpp/common/completion_queue.cc b/src/cpp/common/completion_queue.cc index c37e97909b..2913298afe 100644 --- a/src/cpp/common/completion_queue.cc +++ b/src/cpp/common/completion_queue.cc @@ -57,24 +57,23 @@ class EventDeleter { } }; -bool CompletionQueue::Next(void** tag, bool* ok, gpr_timespec deadline) { +CompletionQueue::NextStatus CompletionQueue::AsyncNext(void** tag, bool* ok, + gpr_timespec deadline) { std::unique_ptr<grpc_event, EventDeleter> ev; for (;;) { ev.reset(grpc_completion_queue_next(cq_, deadline)); if (!ev) { /* got a NULL back because deadline passed */ - *ok = true; - *tag = nullptr; - return true; + return TIMEOUT; } if (ev->type == GRPC_QUEUE_SHUTDOWN) { - return false; + return SHUTDOWN; } auto cq_tag = static_cast<CompletionQueueTag*>(ev->tag); *ok = ev->data.op_complete == GRPC_OP_OK; *tag = cq_tag; if (cq_tag->FinalizeResult(tag, ok)) { - return true; + return GOT_EVENT; } } } |