diff options
author | Vijay Pai <vpai@google.com> | 2015-03-23 10:26:50 -0700 |
---|---|---|
committer | Vijay Pai <vpai@google.com> | 2015-03-23 10:26:50 -0700 |
commit | 046d92dcb0e972c41a51fa5d56e5d0f00908e9b3 (patch) | |
tree | 0f7fd733c3406fbc83731bc4c215e87e27460200 /src/cpp | |
parent | 8c8588c7dc047ee509c7367f61ba0c5f00cb61d1 (diff) | |
parent | 10bb15cdd444777cf2dd47f8d7e4fb559c4ace8b (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/cpp')
-rw-r--r-- | src/cpp/common/completion_queue.cc | 17 | ||||
-rw-r--r-- | src/cpp/util/time.cc | 6 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/cpp/common/completion_queue.cc b/src/cpp/common/completion_queue.cc index fede2da016..cea2d24831 100644 --- a/src/cpp/common/completion_queue.cc +++ b/src/cpp/common/completion_queue.cc @@ -36,7 +36,6 @@ #include <grpc/grpc.h> #include <grpc/support/log.h> -#include <grpc/support/time.h> #include "src/cpp/util/time.h" namespace grpc { @@ -57,15 +56,12 @@ class EventDeleter { } }; -CompletionQueue::NextStatus -CompletionQueue::AsyncNext(void** tag, bool* ok, - std::chrono::system_clock::time_point deadline) { +CompletionQueue::NextStatus CompletionQueue::AsyncNextInternal( + void** tag, bool* ok, gpr_timespec 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_deadline)); + ev.reset(grpc_completion_queue_next(cq_, deadline)); if (!ev) { /* got a NULL back because deadline passed */ return TIMEOUT; } @@ -81,6 +77,13 @@ CompletionQueue::AsyncNext(void** tag, bool* ok, } } +CompletionQueue::NextStatus CompletionQueue::AsyncNext( + void** tag, bool* ok, std::chrono::system_clock::time_point deadline) { + gpr_timespec gpr_deadline; + Timepoint2Timespec(deadline, &gpr_deadline); + return AsyncNextInternal(tag, ok, gpr_deadline); +} + bool CompletionQueue::Pluck(CompletionQueueTag* tag) { std::unique_ptr<grpc_event, EventDeleter> ev; diff --git a/src/cpp/util/time.cc b/src/cpp/util/time.cc index 44d2283e76..059ea72abf 100644 --- a/src/cpp/util/time.cc +++ b/src/cpp/util/time.cc @@ -42,11 +42,15 @@ using std::chrono::system_clock; namespace grpc { -// TODO(yangg) prevent potential overflow. void Timepoint2Timespec(const system_clock::time_point& from, gpr_timespec* to) { system_clock::duration deadline = from.time_since_epoch(); seconds secs = duration_cast<seconds>(deadline); + if (from == system_clock::time_point::max() || + secs.count() >= gpr_inf_future.tv_sec || secs.count() < 0) { + *to = gpr_inf_future; + return; + } nanoseconds nsecs = duration_cast<nanoseconds>(deadline - secs); to->tv_sec = secs.count(); to->tv_nsec = nsecs.count(); |