aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/common
diff options
context:
space:
mode:
authorGravatar Yang Gao <yangg@google.com>2015-03-17 15:45:33 -0700
committerGravatar Yang Gao <yangg@google.com>2015-03-17 15:45:33 -0700
commit700bdeb6f549ed79d586f962b8347b9a5275d5c8 (patch)
tree4812bfebcb980c4c7bbc8aec5418e5ec9e972de1 /src/cpp/common
parentd9427202661411b975fcb22f338ed03503d9af6a (diff)
parent7aadf46fdb05b5f595440c41998023e69e1700e5 (diff)
Merge pull request #1023 from vjpai/async
Non-blocking Next method for C++ async completion queue
Diffstat (limited to 'src/cpp/common')
-rw-r--r--src/cpp/common/completion_queue.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/cpp/common/completion_queue.cc b/src/cpp/common/completion_queue.cc
index 414966c1cd..fede2da016 100644
--- a/src/cpp/common/completion_queue.cc
+++ b/src/cpp/common/completion_queue.cc
@@ -57,19 +57,26 @@ class EventDeleter {
}
};
-bool CompletionQueue::Next(void** tag, bool* ok) {
+CompletionQueue::NextStatus
+CompletionQueue::AsyncNext(void** tag, bool* ok,
+ std::chrono::system_clock::time_point deadline) {
std::unique_ptr<grpc_event, EventDeleter> ev;
+ gpr_timespec gpr_deadline;
+ Timepoint2Timespec(deadline, &gpr_deadline);
for (;;) {
- ev.reset(grpc_completion_queue_next(cq_, gpr_inf_future));
+ ev.reset(grpc_completion_queue_next(cq_, gpr_deadline));
+ if (!ev) { /* got a NULL back because deadline passed */
+ 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;
}
}
}