fix sync unary call with metadata pieces

pull/501/head
Yang Gao 10 years ago
parent 3d20c5e8c6
commit cbcc977857
  1. 23
      include/grpc++/client_context.h
  2. 4
      src/cpp/client/client_unary_call.cc

@ -47,9 +47,18 @@ using std::chrono::system_clock;
struct grpc_call;
struct grpc_completion_queue;
namespace google {
namespace protobuf {
class Message;
} // namespace protobuf
} // namespace google
namespace grpc {
class CallOpBuffer;
class ChannelInterface;
class RpcMethod;
class Status;
template <class R> class ClientReader;
template <class W> class ClientWriter;
template <class R, class W> class ClientReaderWriter;
@ -65,6 +74,16 @@ class ClientContext {
void AddMetadata(const grpc::string &meta_key,
const grpc::string &meta_value);
std::multimap<grpc::string, grpc::string> GetServerInitialMetadata() {
GPR_ASSERT(initial_metadata_received_);
return recv_initial_metadata_;
}
std::multimap<grpc::string, grpc::string> GetServerTrailingMetadata() {
// TODO(yangg) check finished
return trailing_metadata_;
}
void set_absolute_deadline(const system_clock::time_point &deadline);
system_clock::time_point absolute_deadline();
@ -83,6 +102,10 @@ class ClientContext {
template <class R> friend class ::grpc::ClientAsyncReader;
template <class W> friend class ::grpc::ClientAsyncWriter;
template <class R, class W> friend class ::grpc::ClientAsyncReaderWriter;
friend Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method,
ClientContext *context,
const google::protobuf::Message &request,
google::protobuf::Message *result);
grpc_call *call() { return call_; }
void set_call(grpc_call *call) {

@ -34,6 +34,7 @@
#include <grpc++/impl/client_unary_call.h>
#include <grpc++/impl/call.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
#include <grpc++/completion_queue.h>
#include <grpc++/status.h>
#include <grpc/support/log.h>
@ -51,10 +52,11 @@ Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method,
Status status;
buf.AddSendInitialMetadata(context);
buf.AddSendMessage(request);
buf.AddRecvInitialMetadata(&context->recv_initial_metadata_);
bool got_message;
buf.AddRecvMessage(result, &got_message);
buf.AddClientSendClose();
buf.AddClientRecvStatus(nullptr, &status); // TODO metadata
buf.AddClientRecvStatus(&context->trailing_metadata_, &status);
call.PerformOps(&buf);
GPR_ASSERT(cq.Pluck(&buf) && (got_message || !status.IsOk()));
return status;

Loading…
Cancel
Save