diff options
Diffstat (limited to 'include/grpc++/completion_queue.h')
-rw-r--r-- | include/grpc++/completion_queue.h | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h index f741e3c36b..f4619a1060 100644 --- a/include/grpc++/completion_queue.h +++ b/include/grpc++/completion_queue.h @@ -34,6 +34,7 @@ #ifndef GRPCXX_COMPLETION_QUEUE_H #define GRPCXX_COMPLETION_QUEUE_H +#include <chrono> #include <grpc++/impl/client_unary_call.h> struct grpc_completion_queue; @@ -65,26 +66,38 @@ class CompletionQueueTag { // to do) // If this function returns false, the tag is dropped and not returned // from the completion queue - virtual bool FinalizeResult(void **tag, bool *status) = 0; + virtual bool FinalizeResult(void** tag, bool* status) = 0; }; // grpc_completion_queue wrapper class class CompletionQueue { public: CompletionQueue(); - explicit CompletionQueue(grpc_completion_queue *take); + explicit CompletionQueue(grpc_completion_queue* take); ~CompletionQueue(); - // Blocking read from queue. - // Returns true if an event was received, false if the queue is ready - // for destruction. - bool Next(void **tag, bool *ok); + // Tri-state return for AsyncNext: SHUTDOWN, GOT_EVENT, TIMEOUT + enum NextStatus { SHUTDOWN, GOT_EVENT, TIMEOUT }; + + // Nonblocking (until deadline) read from queue. + // Cannot rely on result of tag or ok if return is TIMEOUT + NextStatus AsyncNext(void** tag, bool* ok, + std::chrono::system_clock::time_point deadline); + + // Blocking (until deadline) read from queue. + // Returns false if the queue is ready for destruction, true if event + + bool Next(void** tag, bool* ok) { + return ( + AsyncNext(tag, ok, (std::chrono::system_clock::time_point::max)()) != + SHUTDOWN); + } // Shutdown has to be called, and the CompletionQueue can only be // destructed when false is returned from Next(). void Shutdown(); - grpc_completion_queue *cq() { return cq_; } + grpc_completion_queue* cq() { return cq_; } private: // Friend synchronous wrappers so that they can access Pluck(), which is @@ -103,20 +116,20 @@ class CompletionQueue { friend class ::grpc::ServerReaderWriter; friend class ::grpc::Server; friend class ::grpc::ServerContext; - friend Status BlockingUnaryCall(ChannelInterface *channel, - const RpcMethod &method, - ClientContext *context, - const grpc::protobuf::Message &request, - grpc::protobuf::Message *result); + friend Status BlockingUnaryCall(ChannelInterface* channel, + const RpcMethod& method, + ClientContext* context, + const grpc::protobuf::Message& request, + grpc::protobuf::Message* result); // Wraps grpc_completion_queue_pluck. // Cannot be mixed with calls to Next(). - bool Pluck(CompletionQueueTag *tag); + bool Pluck(CompletionQueueTag* tag); // Does a single polling pluck on tag - void TryPluck(CompletionQueueTag *tag); + void TryPluck(CompletionQueueTag* tag); - grpc_completion_queue *cq_; // owned + grpc_completion_queue* cq_; // owned }; } // namespace grpc |