diff options
Diffstat (limited to 'include/grpc++/impl/client_unary_call.h')
-rw-r--r-- | include/grpc++/impl/client_unary_call.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/include/grpc++/impl/client_unary_call.h b/include/grpc++/impl/client_unary_call.h index 0e8aeed781..561c4721ef 100644 --- a/include/grpc++/impl/client_unary_call.h +++ b/include/grpc++/impl/client_unary_call.h @@ -36,6 +36,8 @@ #include <grpc++/config.h> +#include <grpc++/impl/call.h> + namespace grpc { class ChannelInterface; @@ -45,10 +47,31 @@ class RpcMethod; class Status; // Wrapper that performs a blocking unary call +template <class InputMessage, class OutputMessage> Status BlockingUnaryCall(ChannelInterface* channel, const RpcMethod& method, ClientContext* context, - const grpc::protobuf::Message& request, - grpc::protobuf::Message* result); + const InputMessage& request, + OutputMessage* result) { + CompletionQueue cq; + Call call(channel->CreateCall(method, context, &cq)); + CallOpSet< + CallOpSendInitialMetadata, + CallOpSendMessage, + CallOpRecvInitialMetadata, + CallOpRecvMessage<OutputMessage>, + CallOpClientSendClose, + CallOpClientRecvStatus> ops; + Status status; + ops.AddSendInitialMetadata(context); + ops.AddSendMessage(request); + ops.AddRecvInitialMetadata(context); + ops.AddRecvMessage(result); + ops.AddClientSendClose(); + ops.AddClientRecvStatus(context, &status); + call.PerformOps(&ops); + GPR_ASSERT((cq.Pluck(&ops) && ops.got_message) || !status.IsOk()); + return status; +} } // namespace grpc |