Change API for next message size to allow a bool return value for failure

cases.
pull/7018/head
Vijay Pai 8 years ago
parent 0a1c598986
commit 2d04dd827c
  1. 5
      include/grpc++/impl/codegen/fc_unary.h
  2. 22
      include/grpc++/impl/codegen/sync_stream.h
  3. 4
      test/cpp/end2end/hybrid_end2end_test.cc
  4. 10
      test/cpp/end2end/mock_test.cc

@ -56,7 +56,10 @@ template <class RequestType, class ResponseType>
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;

@ -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<R> {
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<CallOpRecvInitialMetadata, CallOpRecvMessage<R>> ops;
@ -298,7 +301,10 @@ class ClientReaderWriter GRPC_FINAL : public ClientReaderWriterInterface<W, R> {
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<CallOpRecvInitialMetadata, CallOpRecvMessage<R>> ops;
@ -359,7 +365,10 @@ class ServerReader GRPC_FINAL : public ReaderInterface<R> {
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<CallOpRecvMessage<R>> ops;
@ -427,7 +436,10 @@ class ServerReaderWriter GRPC_FINAL : public WriterInterface<W>,
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<CallOpRecvMessage<R>> ops;

@ -426,7 +426,9 @@ public:
Status FCEcho(ServerContext* context, FCUnary<EchoRequest,EchoResponse>* 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));

@ -64,7 +64,10 @@ class MockClientReaderWriter GRPC_FINAL
: public ClientReaderWriterInterface<W, R> {
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<EchoRequest, EchoResponse> 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_);

Loading…
Cancel
Save