From 2d04dd827ce66a54ea8ddc6c691f9c028833fd56 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Wed, 27 Jul 2016 11:35:56 -0700 Subject: [PATCH] Change API for next message size to allow a bool return value for failure cases. --- include/grpc++/impl/codegen/fc_unary.h | 5 ++++- include/grpc++/impl/codegen/sync_stream.h | 22 +++++++++++++++++----- test/cpp/end2end/hybrid_end2end_test.cc | 4 +++- test/cpp/end2end/mock_test.cc | 10 ++++++++-- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/grpc++/impl/codegen/fc_unary.h b/include/grpc++/impl/codegen/fc_unary.h index 22e40ab02e5..768443912b8 100644 --- a/include/grpc++/impl/codegen/fc_unary.h +++ b/include/grpc++/impl/codegen/fc_unary.h @@ -56,7 +56,10 @@ template public: FCUnary(Call* call, ServerContext* ctx): call_(call), ctx_(ctx), read_done_(false), write_done_(false) {} ~FCUnary() {} - uint32_t NextMessageSize() {return call_->max_message_size();} + bool NextMessageSize(uint32_t *sz) { + *sz = call_->max_message_size(); + return true; + } bool Read(RequestType *request) { if (read_done_) { return false; diff --git a/include/grpc++/impl/codegen/sync_stream.h b/include/grpc++/impl/codegen/sync_stream.h index 0afa8b6aa49..930c72056c2 100644 --- a/include/grpc++/impl/codegen/sync_stream.h +++ b/include/grpc++/impl/codegen/sync_stream.h @@ -71,7 +71,7 @@ class ReaderInterface { virtual ~ReaderInterface() {} /// Upper bound on the next message size available for reading on this stream - virtual uint32_t NextMessageSize() = 0; + virtual bool NextMessageSize(uint32_t *sz) = 0; /// Blocking read a message and parse to \a msg. Returns \a true on success. /// This is thread-safe with respect to \a Write or \WritesDone methods on @@ -151,7 +151,10 @@ class ClientReader GRPC_FINAL : public ClientReaderInterface { cq_.Pluck(&ops); /// status ignored } - uint32_t NextMessageSize() GRPC_OVERRIDE {return call_.max_message_size();} + bool NextMessageSize(uint32_t *sz) GRPC_OVERRIDE { + *sz = call_.max_message_size(); + return true; + } bool Read(R* msg) GRPC_OVERRIDE { CallOpSet> ops; @@ -298,7 +301,10 @@ class ClientReaderWriter GRPC_FINAL : public ClientReaderWriterInterface { cq_.Pluck(&ops); // status ignored } - uint32_t NextMessageSize() GRPC_OVERRIDE {return call_.max_message_size();} + bool NextMessageSize(uint32_t *sz) GRPC_OVERRIDE { + *sz = call_.max_message_size(); + return true; + } bool Read(R* msg) GRPC_OVERRIDE { CallOpSet> ops; @@ -359,7 +365,10 @@ class ServerReader GRPC_FINAL : public ReaderInterface { call_->cq()->Pluck(&ops); } - uint32_t NextMessageSize() GRPC_OVERRIDE {return call_->max_message_size();} + bool NextMessageSize(uint32_t *sz) GRPC_OVERRIDE { + *sz = call_->max_message_size(); + return true; + } bool Read(R* msg) GRPC_OVERRIDE { CallOpSet> ops; @@ -427,7 +436,10 @@ class ServerReaderWriter GRPC_FINAL : public WriterInterface, call_->cq()->Pluck(&ops); } - uint32_t NextMessageSize() GRPC_OVERRIDE {return call_->max_message_size();} + bool NextMessageSize(uint32_t *sz) GRPC_OVERRIDE { + *sz = call_->max_message_size(); + return true; + } bool Read(R* msg) GRPC_OVERRIDE { CallOpSet> ops; diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index 699cf49b260..b80010e8031 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -426,7 +426,9 @@ public: Status FCEcho(ServerContext* context, FCUnary* fc_unary) GRPC_OVERRIDE { EchoRequest req; EchoResponse resp; - gpr_log(GPR_INFO, "FC Unary Next Message Size is %u", fc_unary->NextMessageSize()); + uint32_t next_msg_sz; + fc_unary->NextMessageSize(&next_msg_sz); + gpr_log(GPR_INFO, "FC Unary Next Message Size is %u", next_msg_sz); GPR_ASSERT(fc_unary->Read(&req)); resp.set_message(req.message() + "_dup"); GPR_ASSERT(fc_unary->Write(resp)); diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 744a7cd9eb9..40526271221 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -64,7 +64,10 @@ class MockClientReaderWriter GRPC_FINAL : public ClientReaderWriterInterface { public: void WaitForInitialMetadata() GRPC_OVERRIDE {} - uint32_t NextMessageSize() GRPC_OVERRIDE {return UINT_MAX;} + bool NextMessageSize(uint32_t* sz) GRPC_OVERRIDE { + *sz = UINT_MAX; + return true; + } bool Read(R* msg) GRPC_OVERRIDE { return true; } bool Write(const W& msg) GRPC_OVERRIDE { return true; } bool WritesDone() GRPC_OVERRIDE { return true; } @@ -76,7 +79,10 @@ class MockClientReaderWriter GRPC_FINAL public: MockClientReaderWriter() : writes_done_(false) {} void WaitForInitialMetadata() GRPC_OVERRIDE {} - uint32_t NextMessageSize() GRPC_OVERRIDE {return UINT_MAX;} + bool NextMessageSize(uint32_t* sz) GRPC_OVERRIDE { + *sz = UINT_MAX; + return true; + } bool Read(EchoResponse* msg) GRPC_OVERRIDE { if (writes_done_) return false; msg->set_message(last_message_);