aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cpp/common/channel_arguments.cc (renamed from src/cpp/client/channel_arguments.cc)15
-rw-r--r--src/cpp/common/secure_channel_arguments.cc (renamed from src/cpp/client/secure_channel_arguments.cc)0
-rw-r--r--src/cpp/server/server.cc25
-rw-r--r--src/cpp/server/server_builder.cc18
4 files changed, 34 insertions, 24 deletions
diff --git a/src/cpp/client/channel_arguments.cc b/src/cpp/common/channel_arguments.cc
index 50422d06c9..90cd5136af 100644
--- a/src/cpp/client/channel_arguments.cc
+++ b/src/cpp/common/channel_arguments.cc
@@ -62,7 +62,9 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other)
break;
case GRPC_ARG_POINTER:
ap.value.pointer = a->value.pointer;
- ap.value.pointer.p = a->value.pointer.copy(ap.value.pointer.p);
+ ap.value.pointer.p = a->value.pointer.copy
+ ? a->value.pointer.copy(ap.value.pointer.p)
+ : ap.value.pointer.p;
break;
}
args_.push_back(ap);
@@ -89,6 +91,17 @@ void ChannelArguments::SetInt(const grpc::string& key, int value) {
args_.push_back(arg);
}
+void ChannelArguments::SetPointer(const grpc::string& key, void* value) {
+ 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.copy = nullptr;
+ arg.value.pointer.destroy = nullptr;
+ args_.push_back(arg);
+}
+
void ChannelArguments::SetString(const grpc::string& key,
const grpc::string& value) {
grpc_arg arg;
diff --git a/src/cpp/client/secure_channel_arguments.cc b/src/cpp/common/secure_channel_arguments.cc
index e17d3b58b0..e17d3b58b0 100644
--- a/src/cpp/client/secure_channel_arguments.cc
+++ b/src/cpp/common/secure_channel_arguments.cc
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index 377c1ed167..878775bbee 100644
--- a/src/cpp/server/server.cc
+++ b/src/cpp/server/server.cc
@@ -269,36 +269,21 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag {
grpc_completion_queue* cq_;
};
-static grpc_server* CreateServer(
- int max_message_size, const grpc_compression_options& compression_options) {
- grpc_arg args[2];
- size_t args_idx = 0;
- if (max_message_size > 0) {
- args[args_idx].type = GRPC_ARG_INTEGER;
- args[args_idx].key = const_cast<char*>(GRPC_ARG_MAX_MESSAGE_LENGTH);
- args[args_idx].value.integer = max_message_size;
- args_idx++;
- }
-
- args[args_idx].type = GRPC_ARG_INTEGER;
- args[args_idx].key = const_cast<char*>(GRPC_COMPRESSION_ALGORITHM_STATE_ARG);
- args[args_idx].value.integer = compression_options.enabled_algorithms_bitset;
- args_idx++;
-
- grpc_channel_args channel_args = {args_idx, args};
+static grpc_server* CreateServer(const ChannelArguments& args) {
+ grpc_channel_args channel_args;
+ args.SetChannelArgs(&channel_args);
return grpc_server_create(&channel_args, nullptr);
}
Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
- int max_message_size,
- grpc_compression_options compression_options)
+ int max_message_size, const ChannelArguments& args)
: max_message_size_(max_message_size),
started_(false),
shutdown_(false),
num_running_cb_(0),
sync_methods_(new std::list<SyncRequest>),
has_generic_service_(false),
- server_(CreateServer(max_message_size, compression_options)),
+ server_(CreateServer(args)),
thread_pool_(thread_pool),
thread_pool_owned_(thread_pool_owned) {
gpr_once_init(&g_once_init_callbacks, InitGlobalCallbacks);
diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc
index b8094aa8f6..26c0724a30 100644
--- a/src/cpp/server/server_builder.cc
+++ b/src/cpp/server/server_builder.cc
@@ -84,6 +84,10 @@ void ServerBuilder::RegisterAsyncGenericService(AsyncGenericService* service) {
generic_service_ = service;
}
+void ServerBuilder::SetOption(std::unique_ptr<ServerBuilderOption> option) {
+ options_.push_back(std::move(option));
+}
+
void ServerBuilder::AddListeningPort(const grpc::string& addr,
std::shared_ptr<ServerCredentials> creds,
int* selected_port) {
@@ -101,9 +105,17 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
thread_pool_ = CreateDefaultThreadPool();
thread_pool_owned = true;
}
- std::unique_ptr<Server> server(new Server(thread_pool_, thread_pool_owned,
- max_message_size_,
- compression_options_));
+ ChannelArguments args;
+ for (auto option = options_.begin(); option != options_.end(); ++option) {
+ (*option)->UpdateArguments(&args);
+ }
+ if (max_message_size_ > 0) {
+ args.SetInt(GRPC_ARG_MAX_MESSAGE_LENGTH, max_message_size_);
+ }
+ args.SetInt(GRPC_COMPRESSION_ALGORITHM_STATE_ARG,
+ compression_options_.enabled_algorithms_bitset);
+ std::unique_ptr<Server> server(
+ new Server(thread_pool_, thread_pool_owned, max_message_size_, args));
for (auto cq = cqs_.begin(); cq != cqs_.end(); ++cq) {
grpc_server_register_completion_queue(server->server_, (*cq)->cq(),
nullptr);