aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpp')
-rw-r--r--src/cpp/common/buffer_pool_cc.cc51
-rw-r--r--src/cpp/common/channel_arguments.cc14
-rw-r--r--src/cpp/server/server_builder.cc22
3 files changed, 86 insertions, 1 deletions
diff --git a/src/cpp/common/buffer_pool_cc.cc b/src/cpp/common/buffer_pool_cc.cc
new file mode 100644
index 0000000000..fe5704d661
--- /dev/null
+++ b/src/cpp/common/buffer_pool_cc.cc
@@ -0,0 +1,51 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <grpc++/buffer_pool.h>
+#include <grpc/grpc.h>
+
+namespace grpc {
+
+BufferPool::BufferPool() : impl_(grpc_buffer_pool_create(nullptr)) {}
+
+BufferPool::BufferPool(const grpc::string& name)
+ : impl_(grpc_buffer_pool_create(name.c_str())) {}
+
+BufferPool::~BufferPool() { grpc_buffer_pool_unref(impl_); }
+
+BufferPool& BufferPool::Resize(size_t new_size) {
+ grpc_buffer_pool_resize(impl_, new_size);
+ return *this;
+}
+
+} // namespace grpc
diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc
index f297ae8587..afde513e1e 100644
--- a/src/cpp/common/channel_arguments.cc
+++ b/src/cpp/common/channel_arguments.cc
@@ -34,6 +34,7 @@
#include <sstream>
+#include <grpc++/buffer_pool.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
@@ -113,6 +114,11 @@ void ChannelArguments::SetUserAgentPrefix(
}
}
+void ChannelArguments::SetBufferPool(const grpc::BufferPool& buffer_pool) {
+ SetPointerWithVtable(GRPC_ARG_BUFFER_POOL, buffer_pool.c_buffer_pool(),
+ grpc_buffer_pool_arg_vtable());
+}
+
void ChannelArguments::SetInt(const grpc::string& key, int value) {
grpc_arg arg;
arg.type = GRPC_ARG_INTEGER;
@@ -127,12 +133,18 @@ void ChannelArguments::SetPointer(const grpc::string& key, void* value) {
static const grpc_arg_pointer_vtable vtable = {
&PointerVtableMembers::Copy, &PointerVtableMembers::Destroy,
&PointerVtableMembers::Compare};
+ SetPointerWithVtable(key, value, &vtable);
+}
+
+void ChannelArguments::SetPointerWithVtable(
+ const grpc::string& key, void* value,
+ const grpc_arg_pointer_vtable* vtable) {
grpc_arg arg;
arg.type = GRPC_ARG_POINTER;
strings_.push_back(key);
arg.key = const_cast<char*>(strings_.back().c_str());
arg.value.pointer.p = value;
- arg.value.pointer.vtable = &vtable;
+ arg.value.pointer.vtable = vtable;
args_.push_back(arg);
}
diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc
index 2980b16c56..be5b97846a 100644
--- a/src/cpp/server/server_builder.cc
+++ b/src/cpp/server/server_builder.cc
@@ -33,6 +33,7 @@
#include <grpc++/server_builder.h>
+#include <grpc++/buffer_pool.h>
#include <grpc++/impl/service_type.h>
#include <grpc++/server.h>
#include <grpc/support/log.h>
@@ -54,6 +55,7 @@ static void do_plugin_list_init(void) {
ServerBuilder::ServerBuilder()
: max_receive_message_size_(-1),
max_send_message_size_(-1),
+ buffer_pool_(nullptr),
generic_service_(nullptr) {
gpr_once_init(&once_init_plugin_list, do_plugin_list_init);
for (auto it = g_plugin_factory_list->begin();
@@ -70,6 +72,12 @@ ServerBuilder::ServerBuilder()
sizeof(maybe_default_compression_algorithm_));
}
+ServerBuilder::~ServerBuilder() {
+ if (buffer_pool_ != nullptr) {
+ grpc_buffer_pool_unref(buffer_pool_);
+ }
+}
+
std::unique_ptr<ServerCompletionQueue> ServerBuilder::AddCompletionQueue(
bool is_frequently_polled) {
ServerCompletionQueue* cq = new ServerCompletionQueue(is_frequently_polled);
@@ -130,6 +138,16 @@ ServerBuilder& ServerBuilder::SetDefaultCompressionAlgorithm(
return *this;
}
+ServerBuilder& ServerBuilder::SetBufferPool(
+ const grpc::BufferPool& buffer_pool) {
+ if (buffer_pool_ != nullptr) {
+ grpc_buffer_pool_unref(buffer_pool_);
+ }
+ buffer_pool_ = buffer_pool.c_buffer_pool();
+ grpc_buffer_pool_ref(buffer_pool_);
+ return *this;
+}
+
ServerBuilder& ServerBuilder::AddListeningPort(
const grpc::string& addr, std::shared_ptr<ServerCredentials> creds,
int* selected_port) {
@@ -178,6 +196,10 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
args.SetInt(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM,
maybe_default_compression_algorithm_.algorithm);
}
+ if (buffer_pool_ != nullptr) {
+ args.SetPointerWithVtable(GRPC_ARG_BUFFER_POOL, buffer_pool_,
+ grpc_buffer_pool_arg_vtable());
+ }
std::unique_ptr<Server> server(new Server(thread_pool.release(), true,
max_receive_message_size_, &args));
ServerInitializer* initializer = server->initializer();