aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/common
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-09-28 14:22:12 -0700
committerGravatar Craig Tiller <ctiller@google.com>2016-09-28 14:22:12 -0700
commitdb1a5cce471cb038953f4221401142da85c2412a (patch)
treeb56f4abfacd665381974819446c8f6f67f0d6040 /src/cpp/common
parent42ee4d86b9fb3d47f6aa59fca5a2e2b0da1f092d (diff)
Buffer pool C++ wrapper
Diffstat (limited to 'src/cpp/common')
-rw-r--r--src/cpp/common/buffer_pool.cc50
-rw-r--r--src/cpp/common/channel_arguments.cc14
2 files changed, 63 insertions, 1 deletions
diff --git a/src/cpp/common/buffer_pool.cc b/src/cpp/common/buffer_pool.cc
new file mode 100644
index 0000000000..9d65bd7431
--- /dev/null
+++ b/src/cpp/common/buffer_pool.cc
@@ -0,0 +1,50 @@
+/*
+ *
+ * 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_); }
+
+void BufferPool::Resize(size_t new_size) {
+ grpc_buffer_pool_resize(impl_, new_size);
+}
+
+} // 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);
}