aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/grpc++/resource_quota.h70
-rw-r--r--include/grpc++/server_builder.h8
-rw-r--r--include/grpc++/support/channel_arguments.h8
-rw-r--r--include/grpc/grpc.h17
-rw-r--r--include/grpc/impl/codegen/grpc_types.h5
5 files changed, 108 insertions, 0 deletions
diff --git a/include/grpc++/resource_quota.h b/include/grpc++/resource_quota.h
new file mode 100644
index 0000000000..db5bc8e7be
--- /dev/null
+++ b/include/grpc++/resource_quota.h
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#ifndef GRPCXX_RESOURCE_QUOTA_H
+#define GRPCXX_RESOURCE_QUOTA_H
+
+struct grpc_resource_quota;
+
+#include <grpc++/impl/codegen/config.h>
+
+namespace grpc {
+
+/// ResourceQuota represents a bound on memory usage by the gRPC library.
+/// A ResourceQuota can be attached to a server (via ServerBuilder), or a client
+/// channel (via ChannelArguments). gRPC will attempt to keep memory used by
+/// all attached entities below the ResourceQuota bound.
+class ResourceQuota GRPC_FINAL {
+ public:
+ explicit ResourceQuota(const grpc::string& name);
+ ResourceQuota();
+ ~ResourceQuota();
+
+ /// Resize this ResourceQuota to a new size. If new_size is smaller than the
+ /// current size of the pool, memory usage will be monotonically decreased
+ /// until it falls under new_size. No time bound is given for this to occur
+ /// however.
+ ResourceQuota& Resize(size_t new_size);
+
+ grpc_resource_quota* c_resource_quota() const { return impl_; }
+
+ private:
+ ResourceQuota(const ResourceQuota& rhs);
+ ResourceQuota& operator=(const ResourceQuota& rhs);
+
+ grpc_resource_quota* const impl_;
+};
+
+} // namespace grpc
+
+#endif // GRPCXX_RESOURCE_QUOTA_H
diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h
index 37f1f8cb80..15333df60e 100644
--- a/include/grpc++/server_builder.h
+++ b/include/grpc++/server_builder.h
@@ -43,9 +43,12 @@
#include <grpc++/support/config.h>
#include <grpc/compression.h>
+struct grpc_resource_quota;
+
namespace grpc {
class AsyncGenericService;
+class ResourceQuota;
class CompletionQueue;
class RpcService;
class Server;
@@ -61,6 +64,7 @@ class ServerBuilderPluginTest;
class ServerBuilder {
public:
ServerBuilder();
+ ~ServerBuilder();
/// Register a service. This call does not take ownership of the service.
/// The service must exist for the lifetime of the \a Server instance returned
@@ -113,6 +117,9 @@ class ServerBuilder {
ServerBuilder& SetDefaultCompressionAlgorithm(
grpc_compression_algorithm algorithm);
+ /// Set the attached buffer pool for this server
+ ServerBuilder& SetResourceQuota(const ResourceQuota& resource_quota);
+
ServerBuilder& SetOption(std::unique_ptr<ServerBuilderOption> option);
/// Tries to bind \a server to the given \a addr.
@@ -187,6 +194,7 @@ class ServerBuilder {
std::vector<ServerCompletionQueue*> cqs_;
std::shared_ptr<ServerCredentials> creds_;
std::vector<std::unique_ptr<ServerBuilderPlugin>> plugins_;
+ grpc_resource_quota* resource_quota_;
AsyncGenericService* generic_service_;
struct {
bool is_set;
diff --git a/include/grpc++/support/channel_arguments.h b/include/grpc++/support/channel_arguments.h
index ae243939e9..ba203f85bd 100644
--- a/include/grpc++/support/channel_arguments.h
+++ b/include/grpc++/support/channel_arguments.h
@@ -46,6 +46,8 @@ namespace testing {
class ChannelArgumentsTest;
} // namespace testing
+class ResourceQuota;
+
/// Options for channel creation. The user can use generic setters to pass
/// key value pairs down to c channel creation code. For grpc related options,
/// concrete setters are provided.
@@ -80,6 +82,9 @@ class ChannelArguments {
/// The given string will be sent at the front of the user agent string.
void SetUserAgentPrefix(const grpc::string& user_agent_prefix);
+ /// The given buffer pool will be attached to the constructed channel
+ void SetResourceQuota(const ResourceQuota& resource_quota);
+
// Generic channel argument setters. Only for advanced use cases.
/// Set an integer argument \a value under \a key.
void SetInt(const grpc::string& key, int value);
@@ -88,6 +93,9 @@ class ChannelArguments {
/// Set a pointer argument \a value under \a key. Owership is not transferred.
void SetPointer(const grpc::string& key, void* value);
+ void SetPointerWithVtable(const grpc::string& key, void* value,
+ const grpc_arg_pointer_vtable* vtable);
+
/// Set a textual argument \a value under \a key.
void SetString(const grpc::string& key, const grpc::string& value);
diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h
index 587d86c98f..f8e442274e 100644
--- a/include/grpc/grpc.h
+++ b/include/grpc/grpc.h
@@ -401,6 +401,23 @@ GRPCAPI int grpc_is_binary_header(const char *key, size_t length);
/** Convert grpc_call_error values to a string */
GRPCAPI const char *grpc_call_error_to_string(grpc_call_error error);
+/** Create a buffer pool */
+GRPCAPI grpc_resource_quota *grpc_resource_quota_create(const char *trace_name);
+
+/** Add a reference to a buffer pool */
+GRPCAPI void grpc_resource_quota_ref(grpc_resource_quota *resource_quota);
+
+/** Drop a reference to a buffer pool */
+GRPCAPI void grpc_resource_quota_unref(grpc_resource_quota *resource_quota);
+
+/** Update the size of a buffer pool */
+GRPCAPI void grpc_resource_quota_resize(grpc_resource_quota *resource_quota,
+ size_t new_size);
+
+/** Fetch a vtable for a grpc_channel_arg that points to a grpc_resource_quota
+ */
+GRPCAPI const grpc_arg_pointer_vtable *grpc_resource_quota_arg_vtable(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h
index 0be7ab2ad2..66ece3c8a0 100644
--- a/include/grpc/impl/codegen/grpc_types.h
+++ b/include/grpc/impl/codegen/grpc_types.h
@@ -201,6 +201,9 @@ typedef struct {
#define GRPC_ARG_MAX_METADATA_SIZE "grpc.max_metadata_size"
/** If non-zero, allow the use of SO_REUSEPORT if it's available (default 1) */
#define GRPC_ARG_ALLOW_REUSEPORT "grpc.so_reuseport"
+/** If non-zero, a pointer to a buffer pool (use grpc_resource_quota_arg_vtable
+ to fetch an appropriate pointer arg vtable */
+#define GRPC_ARG_RESOURCE_QUOTA "grpc.resource_quota"
/** Service config data, to be passed to subchannels.
Not intended for external use. */
#define GRPC_ARG_SERVICE_CONFIG "grpc.service_config"
@@ -467,6 +470,8 @@ typedef struct grpc_op {
} data;
} grpc_op;
+typedef struct grpc_resource_quota grpc_resource_quota;
+
#ifdef __cplusplus
}
#endif