aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc++/completion_queue.h
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-03-19 19:21:15 +0100
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-03-19 19:21:15 +0100
commitf0863b02270f1b95d5c8b9f3f962959e4cbbdd42 (patch)
treee8a441a621d0addfa82a8fc3052080e78a012a2a /include/grpc++/completion_queue.h
parentf358573091ef9c14c39ea56d9d9883410a533992 (diff)
parent43c5fe6825098b127e33159d3cf14ac937ce7db5 (diff)
Merge branch 'master' of github.com:google/grpc into freebsd
Conflicts: Makefile templates/Makefile.template
Diffstat (limited to 'include/grpc++/completion_queue.h')
-rw-r--r--include/grpc++/completion_queue.h43
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