aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yang Gao <yangg@google.com>2015-02-12 16:44:00 -0800
committerGravatar Yang Gao <yangg@google.com>2015-02-12 16:44:00 -0800
commit31150f01db50241ee29cce5966a7dcfcf981ec0b (patch)
tree5f01130f430764d57670ccfe49395a41241812ce
parent555a0e9e77b68a402a2d652bcd2d2003c4de998a (diff)
implement async unary call
-rw-r--r--include/grpc++/client_context.h6
-rw-r--r--include/grpc++/completion_queue.h1
-rw-r--r--include/grpc++/impl/call.h2
-rw-r--r--src/cpp/client/client_unary_call.cc20
4 files changed, 27 insertions, 2 deletions
diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h
index 5ff60a5399..ab5965f55a 100644
--- a/include/grpc++/client_context.h
+++ b/include/grpc++/client_context.h
@@ -57,6 +57,7 @@ namespace grpc {
class CallOpBuffer;
class ChannelInterface;
+class CompletionQueue;
class RpcMethod;
class Status;
template <class R> class ClientReader;
@@ -106,6 +107,11 @@ class ClientContext {
ClientContext *context,
const google::protobuf::Message &request,
google::protobuf::Message *result);
+ friend void AsyncUnaryCall(ChannelInterface *channel, const RpcMethod &method,
+ ClientContext *context,
+ const google::protobuf::Message &request,
+ google::protobuf::Message *result, Status *status,
+ CompletionQueue *cq, void *tag);
grpc_call *call() { return call_; }
void set_call(grpc_call *call) {
diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h
index 3e68cf3776..80874cd1e6 100644
--- a/include/grpc++/completion_queue.h
+++ b/include/grpc++/completion_queue.h
@@ -58,6 +58,7 @@ class Server;
class CompletionQueueTag {
public:
+ virtual ~CompletionQueueTag() {}
// Called prior to returning from Next(), return value
// is the status of the operation (return status is the default thing
// to do)
diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h
index 853f19e9b3..7aa22ee7c2 100644
--- a/include/grpc++/impl/call.h
+++ b/include/grpc++/impl/call.h
@@ -54,7 +54,7 @@ namespace grpc {
class Call;
-class CallOpBuffer final : public CompletionQueueTag {
+class CallOpBuffer : public CompletionQueueTag {
public:
CallOpBuffer() : return_tag_(this) {}
~CallOpBuffer();
diff --git a/src/cpp/client/client_unary_call.cc b/src/cpp/client/client_unary_call.cc
index 99030a2d47..69f0b77d7b 100644
--- a/src/cpp/client/client_unary_call.cc
+++ b/src/cpp/client/client_unary_call.cc
@@ -62,11 +62,29 @@ Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method,
return status;
}
+class ClientAsyncRequest final : public CallOpBuffer {
+ public:
+ void FinalizeResult(void** tag, bool* status) override {
+ CallOpBuffer::FinalizeResult(tag, status);
+ delete this;
+ }
+};
+
void AsyncUnaryCall(ChannelInterface *channel, const RpcMethod &method,
ClientContext *context,
const google::protobuf::Message &request,
google::protobuf::Message *result, Status *status,
CompletionQueue *cq, void *tag) {
-
+ ClientAsyncRequest* buf = new ClientAsyncRequest;
+ buf->Reset(tag);
+ Call call(channel->CreateCall(method, context, cq));
+ buf->AddSendInitialMetadata(context);
+ buf->AddSendMessage(request);
+ buf->AddRecvInitialMetadata(&context->recv_initial_metadata_);
+ buf->AddRecvMessage(result, nullptr);
+ buf->AddClientSendClose();
+ buf->AddClientRecvStatus(&context->trailing_metadata_, status);
+ call.PerformOps(buf);
}
+
} // namespace grpc