blob: 8417c45e64144f4c2dc527dbc61177ee5408beca [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015-2016 gRPC authors.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080016 *
17 */
18
Muxi Yan0e00c432018-01-26 15:39:32 -080019#include <grpcpp/server_builder.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080020
Craig Tillerf40df232016-03-25 13:38:14 -070021#include <grpc/support/cpu.h>
22#include <grpc/support/log.h>
Muxi Yan0e00c432018-01-26 15:39:32 -080023#include <grpcpp/impl/service_type.h>
24#include <grpcpp/resource_quota.h>
25#include <grpcpp/server.h>
David Garcia Quintas2d024562016-05-17 23:24:39 -070026
Noah Eisen58e0cbf2018-06-07 22:17:14 -070027#include <utility>
28
Vijay Paid4d0a302018-01-25 13:24:03 -080029#include "src/core/lib/gpr/useful.h"
Vijay Paie8a7e302015-08-24 10:52:33 -070030#include "src/cpp/server/thread_pool_interface.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080031
32namespace grpc {
33
Yuchen Zeng7d099a52016-05-06 13:21:36 -070034static std::vector<std::unique_ptr<ServerBuilderPlugin> (*)()>*
35 g_plugin_factory_list;
Yuchen Zeng3b8f3352016-05-03 12:18:13 -070036static gpr_once once_init_plugin_list = GPR_ONCE_INIT;
37
38static void do_plugin_list_init(void) {
Yuchen Zeng7d099a52016-05-06 13:21:36 -070039 g_plugin_factory_list =
40 new std::vector<std::unique_ptr<ServerBuilderPlugin> (*)()>();
Yuchen Zeng3b8f3352016-05-03 12:18:13 -070041}
42
Yang Gao5f4539f2015-03-06 16:11:16 -080043ServerBuilder::ServerBuilder()
Yash Tibrewal3052cff2018-06-07 14:03:00 -070044 : max_receive_message_size_(INT_MIN),
45 max_send_message_size_(INT_MIN),
Sree Kuchibhotla96766192016-10-13 12:42:54 -070046 sync_server_settings_(SyncServerSettings()),
Craig Tiller20afa3d2016-10-17 14:52:14 -070047 resource_quota_(nullptr),
Jan Tattermuschc9ec2c02018-01-12 10:16:22 +010048 generic_service_(nullptr) {
Yuchen Zeng3b8f3352016-05-03 12:18:13 -070049 gpr_once_init(&once_init_plugin_list, do_plugin_list_init);
Vijay Paieac07c32016-06-10 01:36:53 -070050 for (auto it = g_plugin_factory_list->begin();
51 it != g_plugin_factory_list->end(); it++) {
Vijay Paib645a2d2016-06-09 18:39:06 -070052 auto& factory = *it;
Vijay Pai15855f32016-06-10 12:25:32 -070053 plugins_.emplace_back(factory());
Yuchen Zeng3b8f3352016-05-03 12:18:13 -070054 }
Sree Kuchibhotla892dbf42016-09-27 19:42:27 -070055
David Garcia Quintas2d024562016-05-17 23:24:39 -070056 // all compression algorithms enabled by default.
57 enabled_compression_algorithms_bitset_ =
58 (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1;
59 memset(&maybe_default_compression_level_, 0,
60 sizeof(maybe_default_compression_level_));
61 memset(&maybe_default_compression_algorithm_, 0,
62 sizeof(maybe_default_compression_algorithm_));
David Garcia Quintasbeac88c2015-08-10 13:39:52 -070063}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080064
Craig Tillerdb1a5cc2016-09-28 14:22:12 -070065ServerBuilder::~ServerBuilder() {
Craig Tiller20afa3d2016-10-17 14:52:14 -070066 if (resource_quota_ != nullptr) {
67 grpc_resource_quota_unref(resource_quota_);
Craig Tillerdb1a5cc2016-09-28 14:22:12 -070068 }
69}
70
Sree Kuchibhotla1f5e2622016-04-21 12:28:09 -070071std::unique_ptr<ServerCompletionQueue> ServerBuilder::AddCompletionQueue(
72 bool is_frequently_polled) {
Craig Tiller334c4672017-04-11 16:26:07 -070073 ServerCompletionQueue* cq = new ServerCompletionQueue(
74 is_frequently_polled ? GRPC_CQ_DEFAULT_POLLING : GRPC_CQ_NON_LISTENING);
Craig Tillerf9e6adf2015-05-06 11:45:59 -070075 cqs_.push_back(cq);
76 return std::unique_ptr<ServerCompletionQueue>(cq);
77}
78
David Garcia Quintas2d024562016-05-17 23:24:39 -070079ServerBuilder& ServerBuilder::RegisterService(Service* service) {
Craig Tiller15f383c2016-01-07 12:45:32 -080080 services_.emplace_back(new NamedService(service));
David Garcia Quintas2d024562016-05-17 23:24:39 -070081 return *this;
Craig Tiller822d2c72015-07-07 16:08:00 -070082}
83
David Garcia Quintas2d024562016-05-17 23:24:39 -070084ServerBuilder& ServerBuilder::RegisterService(const grpc::string& addr,
85 Service* service) {
Craig Tiller15f383c2016-01-07 12:45:32 -080086 services_.emplace_back(new NamedService(addr, service));
David Garcia Quintas2d024562016-05-17 23:24:39 -070087 return *this;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080088}
89
David Garcia Quintas2d024562016-05-17 23:24:39 -070090ServerBuilder& ServerBuilder::RegisterAsyncGenericService(
91 AsyncGenericService* service) {
Yang Gao005eb882015-03-11 22:17:13 -070092 if (generic_service_) {
Yang Gao1c402332015-03-05 16:39:25 -080093 gpr_log(GPR_ERROR,
Yang Gao49996492015-03-12 16:40:19 -070094 "Adding multiple AsyncGenericService is unsupported for now. "
Yang Gao6baa9b62015-03-17 10:49:39 -070095 "Dropping the service %p",
Sree Kuchibhotla4028d2c2016-09-21 10:45:33 -070096 (void*)service);
David Garcia Quintas2d024562016-05-17 23:24:39 -070097 } else {
98 generic_service_ = service;
Yang Gao1c402332015-03-05 16:39:25 -080099 }
David Garcia Quintas2d024562016-05-17 23:24:39 -0700100 return *this;
Yang Gao1c402332015-03-05 16:39:25 -0800101}
102
David Garcia Quintas2d024562016-05-17 23:24:39 -0700103ServerBuilder& ServerBuilder::SetOption(
104 std::unique_ptr<ServerBuilderOption> option) {
yang-ga23f17b2015-11-25 10:21:05 -0800105 options_.push_back(std::move(option));
David Garcia Quintas2d024562016-05-17 23:24:39 -0700106 return *this;
yang-ga23f17b2015-11-25 10:21:05 -0800107}
108
Sree Kuchibhotla96766192016-10-13 12:42:54 -0700109ServerBuilder& ServerBuilder::SetSyncServerOption(
110 ServerBuilder::SyncServerOption option, int val) {
111 switch (option) {
112 case NUM_CQS:
113 sync_server_settings_.num_cqs = val;
114 break;
Sree Kuchibhotla96766192016-10-13 12:42:54 -0700115 case MIN_POLLERS:
116 sync_server_settings_.min_pollers = val;
117 break;
118 case MAX_POLLERS:
119 sync_server_settings_.max_pollers = val;
120 break;
121 case CQ_TIMEOUT_MSEC:
122 sync_server_settings_.cq_timeout_msec = val;
123 break;
124 }
125 return *this;
126}
127
David Garcia Quintas2d024562016-05-17 23:24:39 -0700128ServerBuilder& ServerBuilder::SetCompressionAlgorithmSupportStatus(
129 grpc_compression_algorithm algorithm, bool enabled) {
130 if (enabled) {
131 GPR_BITSET(&enabled_compression_algorithms_bitset_, algorithm);
132 } else {
133 GPR_BITCLEAR(&enabled_compression_algorithms_bitset_, algorithm);
134 }
135 return *this;
136}
137
138ServerBuilder& ServerBuilder::SetDefaultCompressionLevel(
139 grpc_compression_level level) {
140 maybe_default_compression_level_.level = level;
141 return *this;
142}
143
144ServerBuilder& ServerBuilder::SetDefaultCompressionAlgorithm(
145 grpc_compression_algorithm algorithm) {
146 maybe_default_compression_algorithm_.is_set = true;
147 maybe_default_compression_algorithm_.algorithm = algorithm;
148 return *this;
149}
150
Craig Tiller20afa3d2016-10-17 14:52:14 -0700151ServerBuilder& ServerBuilder::SetResourceQuota(
152 const grpc::ResourceQuota& resource_quota) {
153 if (resource_quota_ != nullptr) {
154 grpc_resource_quota_unref(resource_quota_);
Craig Tillerdb1a5cc2016-09-28 14:22:12 -0700155 }
Craig Tiller20afa3d2016-10-17 14:52:14 -0700156 resource_quota_ = resource_quota.c_resource_quota();
157 grpc_resource_quota_ref(resource_quota_);
Craig Tillerdb1a5cc2016-09-28 14:22:12 -0700158 return *this;
159}
160
David Garcia Quintas2d024562016-05-17 23:24:39 -0700161ServerBuilder& ServerBuilder::AddListeningPort(
David Garcia Quintas94ab1b52017-05-15 15:27:11 -0700162 const grpc::string& addr_uri, std::shared_ptr<ServerCredentials> creds,
David Garcia Quintas2d024562016-05-17 23:24:39 -0700163 int* selected_port) {
David Garcia Quintas94ab1b52017-05-15 15:27:11 -0700164 const grpc::string uri_scheme = "dns:";
165 grpc::string addr = addr_uri;
166 if (addr_uri.compare(0, uri_scheme.size(), uri_scheme) == 0) {
167 size_t pos = uri_scheme.size();
168 while (addr_uri[pos] == '/') ++pos; // Skip slashes.
169 addr = addr_uri.substr(pos);
170 }
Noah Eisen58e0cbf2018-06-07 22:17:14 -0700171 Port port = {addr, std::move(creds), selected_port};
Nicolas Noble30862032015-04-24 18:17:45 -0700172 ports_.push_back(port);
David Garcia Quintas2d024562016-05-17 23:24:39 -0700173 return *this;
yangg9e21f722014-12-08 15:49:52 -0800174}
175
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800176std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
Sree Kuchibhotla2d08f5b2016-09-26 16:11:02 -0700177 ChannelArguments args;
178 for (auto option = options_.begin(); option != options_.end(); ++option) {
179 (*option)->UpdateArguments(&args);
180 (*option)->UpdatePlugins(&plugins_);
181 }
182
183 for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) {
Juanli Shen1f965152018-06-30 22:43:27 -0700184 (*plugin)->UpdateServerBuilder(this);
Sree Kuchibhotla2d08f5b2016-09-26 16:11:02 -0700185 (*plugin)->UpdateChannelArguments(&args);
186 }
187
Yash Tibrewalefee8f22018-05-15 16:39:16 -0700188 if (max_receive_message_size_ >= -1) {
Sree Kuchibhotla2d08f5b2016-09-26 16:11:02 -0700189 args.SetInt(GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH, max_receive_message_size_);
190 }
191
Yash Tibrewal3052cff2018-06-07 14:03:00 -0700192 // The default message size is -1 (max), so no need to explicitly set it for
193 // -1.
Sree Kuchibhotla2d08f5b2016-09-26 16:11:02 -0700194 if (max_send_message_size_ >= 0) {
195 args.SetInt(GRPC_ARG_MAX_SEND_MESSAGE_LENGTH, max_send_message_size_);
196 }
197
198 args.SetInt(GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET,
199 enabled_compression_algorithms_bitset_);
200 if (maybe_default_compression_level_.is_set) {
201 args.SetInt(GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL,
202 maybe_default_compression_level_.level);
203 }
204 if (maybe_default_compression_algorithm_.is_set) {
205 args.SetInt(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM,
206 maybe_default_compression_algorithm_.algorithm);
207 }
208
Craig Tiller20afa3d2016-10-17 14:52:14 -0700209 if (resource_quota_ != nullptr) {
Craig Tiller153eaa72016-10-21 13:52:36 -0700210 args.SetPointerWithVtable(GRPC_ARG_RESOURCE_QUOTA, resource_quota_,
Craig Tiller20afa3d2016-10-17 14:52:14 -0700211 grpc_resource_quota_arg_vtable());
Craig Tillerdb1a5cc2016-09-28 14:22:12 -0700212 }
Sree Kuchibhotla1e088b42016-10-28 17:34:55 -0700213
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700214 // == Determine if the server has any syncrhonous methods ==
Craig Tiller8a7fe1a2016-05-20 11:17:20 -0700215 bool has_sync_methods = false;
Craig Tiller15f383c2016-01-07 12:45:32 -0800216 for (auto it = services_.begin(); it != services_.end(); ++it) {
217 if ((*it)->service->has_synchronous_methods()) {
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700218 has_sync_methods = true;
219 break;
220 }
221 }
222
223 if (!has_sync_methods) {
224 for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) {
225 if ((*plugin)->has_sync_methods()) {
Craig Tiller8a7fe1a2016-05-20 11:17:20 -0700226 has_sync_methods = true;
yang-gbef0d872016-01-13 15:27:33 -0800227 break;
Craig Tiller15f383c2016-01-07 12:45:32 -0800228 }
229 }
Craig Tiller0db1bef2015-02-09 13:47:39 -0800230 }
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700231
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700232 // If this is a Sync server, i.e a server expositing sync API, then the server
233 // needs to create some completion queues to listen for incoming requests.
234 // 'sync_server_cqs' are those internal completion queues.
235 //
236 // This is different from the completion queues added to the server via
237 // ServerBuilder's AddCompletionQueue() method (those completion queues
238 // are in 'cqs_' member variable of ServerBuilder object)
Sree Kuchibhotla4028d2c2016-09-21 10:45:33 -0700239 std::shared_ptr<std::vector<std::unique_ptr<ServerCompletionQueue>>>
Sree Kuchibhotla61355352016-10-20 11:17:22 -0700240 sync_server_cqs(std::make_shared<
241 std::vector<std::unique_ptr<ServerCompletionQueue>>>());
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700242
Craig Tiller75bfb972017-04-11 17:55:12 -0700243 int num_frequently_polled_cqs = 0;
244 for (auto it = cqs_.begin(); it != cqs_.end(); ++it) {
245 if ((*it)->IsFrequentlyPolled()) {
246 num_frequently_polled_cqs++;
247 }
248 }
249
250 const bool is_hybrid_server =
251 has_sync_methods && num_frequently_polled_cqs > 0;
252
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700253 if (has_sync_methods) {
Craig Tiller334c4672017-04-11 16:26:07 -0700254 grpc_cq_polling_type polling_type =
Craig Tiller75bfb972017-04-11 17:55:12 -0700255 is_hybrid_server ? GRPC_CQ_NON_POLLING : GRPC_CQ_DEFAULT_POLLING;
Craig Tiller334c4672017-04-11 16:26:07 -0700256
Sree Kuchibhotlaa7a21d22016-09-28 12:38:01 -0700257 // Create completion queues to listen to incoming rpc requests
Sree Kuchibhotla892dbf42016-09-27 19:42:27 -0700258 for (int i = 0; i < sync_server_settings_.num_cqs; i++) {
Craig Tiller334c4672017-04-11 16:26:07 -0700259 sync_server_cqs->emplace_back(new ServerCompletionQueue(polling_type));
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700260 }
261 }
262
Sree Kuchibhotla892dbf42016-09-27 19:42:27 -0700263 std::unique_ptr<Server> server(new Server(
Sree Kuchibhotla9ce673f2018-08-01 12:12:46 -0700264 max_receive_message_size_, &args, sync_server_cqs,
Sree Kuchibhotla892dbf42016-09-27 19:42:27 -0700265 sync_server_settings_.min_pollers, sync_server_settings_.max_pollers,
Sree Kuchibhotla9ce673f2018-08-01 12:12:46 -0700266 sync_server_settings_.cq_timeout_msec, resource_quota_));
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700267
ncteisen85fac6d2017-07-12 07:49:45 -0700268 if (has_sync_methods) {
269 // This is a Sync server
270 gpr_log(GPR_INFO,
271 "Synchronous server. Num CQs: %d, Min pollers: %d, Max Pollers: "
272 "%d, CQ timeout (msec): %d",
273 sync_server_settings_.num_cqs, sync_server_settings_.min_pollers,
274 sync_server_settings_.max_pollers,
275 sync_server_settings_.cq_timeout_msec);
276 }
277
Yuchen Zenga42ec212016-04-29 13:03:06 -0700278 ServerInitializer* initializer = server->initializer();
Sree Kuchibhotla7def0362016-04-21 14:54:32 -0700279
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700280 // Register all the completion queues with the server. i.e
281 // 1. sync_server_cqs: internal completion queues created IF this is a sync
282 // server
283 // 2. cqs_: Completion queues added via AddCompletionQueue() call
Sree Kuchibhotla7def0362016-04-21 14:54:32 -0700284
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700285 for (auto it = sync_server_cqs->begin(); it != sync_server_cqs->end(); ++it) {
Craig Tiller11c58322017-04-12 08:21:17 -0700286 grpc_server_register_completion_queue(server->server_, (*it)->cq(),
287 nullptr);
Craig Tiller75bfb972017-04-11 17:55:12 -0700288 num_frequently_polled_cqs++;
Sree Kuchibhotlaaabada92016-08-24 10:01:13 -0700289 }
290
291 // cqs_ contains the completion queue added by calling the ServerBuilder's
292 // AddCompletionQueue() API. Some of them may not be frequently polled (i.e by
293 // calling Next() or AsyncNext()) and hence are not safe to be used for
294 // listening to incoming channels. Such completion queues must be registered
295 // as non-listening queues
296 for (auto it = cqs_.begin(); it != cqs_.end(); ++it) {
Craig Tiller11c58322017-04-12 08:21:17 -0700297 grpc_server_register_completion_queue(server->server_, (*it)->cq(),
298 nullptr);
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700299 }
Sree Kuchibhotla7def0362016-04-21 14:54:32 -0700300
301 if (num_frequently_polled_cqs == 0) {
302 gpr_log(GPR_ERROR,
Craig Tilleraae6c2c2016-05-20 08:58:30 -0700303 "At least one of the completion queues must be frequently polled");
Sree Kuchibhotla7def0362016-04-21 14:54:32 -0700304 return nullptr;
305 }
306
Vijay Pai82dd80a2015-03-24 10:36:08 -0700307 for (auto service = services_.begin(); service != services_.end();
308 service++) {
Craig Tillerd9b6fcf2015-07-07 16:28:20 -0700309 if (!server->RegisterService((*service)->host.get(), (*service)->service)) {
Craig Tiller0db1bef2015-02-09 13:47:39 -0800310 return nullptr;
311 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800312 }
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700313
Yuchen Zenga42ec212016-04-29 13:03:06 -0700314 for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) {
Vijay Pai15855f32016-06-10 12:25:32 -0700315 (*plugin)->InitServer(initializer);
Yuchen Zenga42ec212016-04-29 13:03:06 -0700316 }
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700317
Yang Gao005eb882015-03-11 22:17:13 -0700318 if (generic_service_) {
Yang Gao49996492015-03-12 16:40:19 -0700319 server->RegisterAsyncGenericService(generic_service_);
yang-g1ac6f452016-01-15 11:46:40 -0800320 } else {
321 for (auto it = services_.begin(); it != services_.end(); ++it) {
322 if ((*it)->service->has_generic_methods()) {
323 gpr_log(GPR_ERROR,
324 "Some methods were marked generic but there is no "
325 "generic service registered.");
326 return nullptr;
327 }
328 }
Yang Gao1c402332015-03-05 16:39:25 -0800329 }
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700330
Craig Tiller12352b22017-01-10 15:16:14 -0800331 bool added_port = false;
Vijay Pai82dd80a2015-03-24 10:36:08 -0700332 for (auto port = ports_.begin(); port != ports_.end(); port++) {
333 int r = server->AddListeningPort(port->addr, port->creds.get());
Craig Tiller12352b22017-01-10 15:16:14 -0800334 if (!r) {
335 if (added_port) server->Shutdown();
336 return nullptr;
337 }
338 added_port = true;
Vijay Pai82dd80a2015-03-24 10:36:08 -0700339 if (port->selected_port != nullptr) {
340 *port->selected_port = r;
Craig Tiller0db1bef2015-02-09 13:47:39 -0800341 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800342 }
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700343
yang-g61e461e2015-09-03 13:08:59 -0700344 auto cqs_data = cqs_.empty() ? nullptr : &cqs_[0];
Craig Tiller9d9313c2017-04-11 15:05:46 -0700345 server->Start(cqs_data, cqs_.size());
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700346
Yuchen Zenga42ec212016-04-29 13:03:06 -0700347 for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) {
Vijay Pai15855f32016-06-10 12:25:32 -0700348 (*plugin)->Finish(initializer);
Yuchen Zenga42ec212016-04-29 13:03:06 -0700349 }
Sree Kuchibhotla3ea9e242016-08-22 14:15:43 -0700350
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800351 return server;
352}
353
Yuchen Zeng3b8f3352016-05-03 12:18:13 -0700354void ServerBuilder::InternalAddPluginFactory(
355 std::unique_ptr<ServerBuilderPlugin> (*CreatePlugin)()) {
356 gpr_once_init(&once_init_plugin_list, do_plugin_list_init);
Yuchen Zeng7d099a52016-05-06 13:21:36 -0700357 (*g_plugin_factory_list).push_back(CreatePlugin);
Yuchen Zeng3b8f3352016-05-03 12:18:13 -0700358}
359
Muxi Yanf6b622c2017-05-17 10:34:10 -0700360ServerBuilder& ServerBuilder::EnableWorkaround(grpc_workaround_list id) {
Muxi Yancdc0d032017-05-09 16:04:10 -0700361 switch (id) {
362 case GRPC_WORKAROUND_ID_CRONET_COMPRESSION:
Muxi Yanf5b3db92017-05-09 17:12:24 -0700363 return AddChannelArgument(GRPC_ARG_WORKAROUND_CRONET_COMPRESSION, 1);
Muxi Yancdc0d032017-05-09 16:04:10 -0700364 default:
Muxi Yan928681d2017-05-16 10:16:23 -0700365 gpr_log(GPR_ERROR, "Workaround %u does not exist or is obsolete.", id);
Muxi Yanf5b3db92017-05-09 17:12:24 -0700366 return *this;
Muxi Yancdc0d032017-05-09 16:04:10 -0700367 }
368}
369
Craig Tiller190d3602015-02-18 09:23:38 -0800370} // namespace grpc