Expose max message size at the server side
diff --git a/include/grpc++/config.h b/include/grpc++/config.h
index 0f3d692..b6c1705 100644
--- a/include/grpc++/config.h
+++ b/include/grpc++/config.h
@@ -93,13 +93,17 @@
#endif
#ifndef GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream.h>
#define GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM \
::google::protobuf::io::ZeroCopyOutputStream
#define GRPC_CUSTOM_ZEROCOPYINPUTSTREAM \
::google::protobuf::io::ZeroCopyInputStream
+#define GRPC_CUSTOM_CODEDINPUTSTREAM \
+ ::google::protobuf::io::CodedInputStream
#endif
+
#ifdef GRPC_CXX0X_NO_NULLPTR
#include <memory>
const class {
@@ -126,6 +130,7 @@
namespace io {
typedef GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM ZeroCopyOutputStream;
typedef GRPC_CUSTOM_ZEROCOPYINPUTSTREAM ZeroCopyInputStream;
+typedef GRPC_CUSTOM_CODEDINPUTSTREAM CodedInputStream;
} // namespace io
} // namespace protobuf
diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h
index b14c41d..d76ef61 100644
--- a/include/grpc++/impl/call.h
+++ b/include/grpc++/impl/call.h
@@ -80,6 +80,10 @@
// Called by completion queue just prior to returning from Next() or Pluck()
bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE;
+ void set_max_message_size(int max_message_size) {
+ max_message_size_ = max_message_size;
+ }
+
bool got_message;
private:
@@ -99,6 +103,7 @@
grpc::protobuf::Message* recv_message_;
ByteBuffer* recv_message_buffer_;
grpc_byte_buffer* recv_buf_;
+ int max_message_size_;
// Client send close
bool client_send_close_;
// Client recv status
@@ -130,16 +135,21 @@
public:
/* call is owned by the caller */
Call(grpc_call* call, CallHook* call_hook_, CompletionQueue* cq);
+ Call(grpc_call* call, CallHook* call_hook_, CompletionQueue* cq,
+ int max_message_size);
void PerformOps(CallOpBuffer* buffer);
grpc_call* call() { return call_; }
CompletionQueue* cq() { return cq_; }
+ int max_message_size() { return max_message_size_; }
+
private:
CallHook* call_hook_;
CompletionQueue* cq_;
grpc_call* call_;
+ int max_message_size_;
};
} // namespace grpc
diff --git a/include/grpc++/server.h b/include/grpc++/server.h
index c686474..b2b9044 100644
--- a/include/grpc++/server.h
+++ b/include/grpc++/server.h
@@ -79,7 +79,8 @@
class AsyncRequest;
// ServerBuilder use only
- Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned);
+ Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
+ int max_message_size);
// Register a service. This call does not take ownership of the service.
// The service must exist for the lifetime of the Server instance.
bool RegisterService(RpcService* service);
@@ -106,6 +107,8 @@
ServerAsyncStreamingInterface* stream,
CompletionQueue* cq, void* tag);
+ const int max_message_size_;
+
// Completion queue.
CompletionQueue cq_;
@@ -126,7 +129,7 @@
// Whether the thread pool is created and owned by the server.
bool thread_pool_owned_;
private:
- Server() : server_(NULL) { abort(); }
+ Server() : max_message_size_(-1), server_(NULL) { abort(); }
};
} // namespace grpc
diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h
index 9a9932e..7155c7f 100644
--- a/include/grpc++/server_builder.h
+++ b/include/grpc++/server_builder.h
@@ -68,6 +68,11 @@
// Register a generic service.
void RegisterAsyncGenericService(AsyncGenericService* service);
+ // Set max message size in bytes.
+ void SetMaxMessageSize(int max_message_size) {
+ max_message_size_ = max_message_size;
+ }
+
// Add a listening port. Can be called multiple times.
void AddListeningPort(const grpc::string& addr,
std::shared_ptr<ServerCredentials> creds,
@@ -87,6 +92,7 @@
int* selected_port;
};
+ int max_message_size_;
std::vector<RpcService*> services_;
std::vector<AsynchronousService*> async_services_;
std::vector<Port> ports_;