Merge pull request #8693 from thinkerou/use_cpp11_for

Use range-based for loops on c++11
pull/20618/head
Vijay Pai 5 years ago committed by GitHub
commit f841c3ea30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/cpp/ext/proto_server_reflection.cc
  2. 51
      src/cpp/server/server_builder.cc
  3. 30
      src/cpp/server/server_cc.cc

@ -102,9 +102,9 @@ Status ProtoServerReflection::ListService(ServerContext* context,
if (services_ == nullptr) {
return Status(StatusCode::NOT_FOUND, "Services not found.");
}
for (auto it = services_->begin(); it != services_->end(); ++it) {
for (const auto& value : *services_) {
ServiceResponse* service_response = response->add_service();
service_response->set_name(*it);
service_response->set_name(value);
}
return Status::OK;
}
@ -182,8 +182,8 @@ Status ProtoServerReflection::GetAllExtensionNumbers(
std::vector<const protobuf::FieldDescriptor*> extensions;
descriptor_pool_->FindAllExtensions(desc, &extensions);
for (auto it = extensions.begin(); it != extensions.end(); it++) {
response->add_extension_number((*it)->number());
for (const auto& value : extensions) {
response->add_extension_number(value->number());
}
response->set_base_type_name(type);
return Status::OK;

@ -48,10 +48,8 @@ ServerBuilder::ServerBuilder()
sync_server_settings_(SyncServerSettings()),
resource_quota_(nullptr) {
gpr_once_init(&once_init_plugin_list, do_plugin_list_init);
for (auto it = g_plugin_factory_list->begin();
it != g_plugin_factory_list->end(); it++) {
auto& factory = *it;
plugins_.emplace_back(factory());
for (const auto& value : *g_plugin_factory_list) {
plugins_.emplace_back(value());
}
// all compression algorithms enabled by default.
@ -205,14 +203,14 @@ ServerBuilder& ServerBuilder::AddListeningPort(
std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
grpc::ChannelArguments args;
for (auto option = options_.begin(); option != options_.end(); ++option) {
(*option)->UpdateArguments(&args);
(*option)->UpdatePlugins(&plugins_);
for (const auto& option : options_) {
option->UpdateArguments(&args);
option->UpdatePlugins(&plugins_);
}
for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) {
(*plugin)->UpdateServerBuilder(this);
(*plugin)->UpdateChannelArguments(&args);
for (const auto& plugin : plugins_) {
plugin->UpdateServerBuilder(this);
plugin->UpdateChannelArguments(&args);
}
if (max_receive_message_size_ >= -1) {
@ -243,16 +241,16 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
// == Determine if the server has any syncrhonous methods ==
bool has_sync_methods = false;
for (auto it = services_.begin(); it != services_.end(); ++it) {
if ((*it)->service->has_synchronous_methods()) {
for (const auto& value : services_) {
if (value->service->has_synchronous_methods()) {
has_sync_methods = true;
break;
}
}
if (!has_sync_methods) {
for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) {
if ((*plugin)->has_sync_methods()) {
for (const auto& value : plugins_) {
if (value->has_sync_methods()) {
has_sync_methods = true;
break;
}
@ -331,8 +329,8 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
// server
// 2. cqs_: Completion queues added via AddCompletionQueue() call
for (auto it = sync_server_cqs->begin(); it != sync_server_cqs->end(); ++it) {
grpc_server_register_completion_queue(server->server_, (*it)->cq(),
for (const auto& value : *sync_server_cqs) {
grpc_server_register_completion_queue(server->server_, value->cq(),
nullptr);
has_frequently_polled_cqs = true;
}
@ -347,8 +345,8 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
// calling Next() or AsyncNext()) and hence are not safe to be used for
// listening to incoming channels. Such completion queues must be registered
// as non-listening queues
for (auto it = cqs_.begin(); it != cqs_.end(); ++it) {
grpc_server_register_completion_queue(server->server_, (*it)->cq(),
for (const auto& value : cqs_) {
grpc_server_register_completion_queue(server->server_, value->cq(),
nullptr);
}
@ -358,15 +356,14 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
return nullptr;
}
for (auto service = services_.begin(); service != services_.end();
service++) {
if (!server->RegisterService((*service)->host.get(), (*service)->service)) {
for (const auto& value : services_) {
if (!server->RegisterService(value->host.get(), value->service)) {
return nullptr;
}
}
for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) {
(*plugin)->InitServer(initializer);
for (const auto& value : plugins_) {
value->InitServer(initializer);
}
if (generic_service_) {
@ -374,8 +371,8 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
} else if (callback_generic_service_) {
server->RegisterCallbackGenericService(callback_generic_service_);
} else {
for (auto it = services_.begin(); it != services_.end(); ++it) {
if ((*it)->service->has_generic_methods()) {
for (const auto& value : services_) {
if (value->service->has_generic_methods()) {
gpr_log(GPR_ERROR,
"Some methods were marked generic but there is no "
"generic service registered.");
@ -400,8 +397,8 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
auto cqs_data = cqs_.empty() ? nullptr : &cqs_[0];
server->Start(cqs_data, cqs_.size());
for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) {
(*plugin)->Finish(initializer);
for (const auto& value : plugins_) {
value->Finish(initializer);
}
return server;

@ -914,9 +914,9 @@ class Server::SyncRequestThreadManager : public grpc::ThreadManager {
void Start() {
if (!sync_requests_.empty()) {
for (auto m = sync_requests_.begin(); m != sync_requests_.end(); m++) {
(*m)->SetupRequest();
(*m)->Request(server_->c_server(), server_cq_->cq());
for (const auto& value : sync_requests_) {
value->SetupRequest();
value->Request(server_->c_server(), server_cq_->cq());
}
Initialize(); // ThreadManager's Initialize()
@ -1014,8 +1014,8 @@ Server::~Server() {
Shutdown();
} else if (!started_) {
// Shutdown the completion queues
for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
(*it)->Shutdown();
for (const auto& value : sync_req_mgrs_) {
value->Shutdown();
}
}
}
@ -1103,8 +1103,8 @@ bool Server::RegisterService(const grpc::string* host, grpc::Service* service) {
method->set_server_tag(method_registration_tag);
} else if (method->api_type() ==
grpc::internal::RpcServiceMethod::ApiType::SYNC) {
for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
(*it)->AddSyncMethod(method, method_registration_tag);
for (const auto& value : sync_req_mgrs_) {
value->AddSyncMethod(method, method_registration_tag);
}
} else {
// a callback method. Register at least some callback requests
@ -1213,8 +1213,8 @@ void Server::Start(grpc::ServerCompletionQueue** cqs, size_t num_cqs) {
grpc_server_start(server_);
if (!has_async_generic_service_ && !has_callback_generic_service_) {
for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
(*it)->AddUnknownSyncMethod();
for (const auto& value : sync_req_mgrs_) {
value->AddUnknownSyncMethod();
}
for (size_t i = 0; i < num_cqs; i++) {
@ -1235,8 +1235,8 @@ void Server::Start(grpc::ServerCompletionQueue** cqs, size_t num_cqs) {
new grpc::internal::ResourceExhaustedHandler);
}
for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
(*it)->Start();
for (const auto& value : sync_req_mgrs_) {
value->Start();
}
for (auto* cbreq : callback_reqs_to_start_) {
@ -1287,13 +1287,13 @@ void Server::ShutdownInternal(gpr_timespec deadline) {
// Shutdown all ThreadManagers. This will try to gracefully stop all the
// threads in the ThreadManagers (once they process any inflight requests)
for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
(*it)->Shutdown(); // ThreadManager's Shutdown()
for (const auto& value : sync_req_mgrs_) {
value->Shutdown(); // ThreadManager's Shutdown()
}
// Wait for threads in all ThreadManagers to terminate
for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
(*it)->Wait();
for (const auto& value : sync_req_mgrs_) {
value->Wait();
}
// Wait for all outstanding callback requests to complete

Loading…
Cancel
Save