Use range-based fors in src/cpp/{client,server}

pull/20627/head
Vijay Pai 5 years ago
parent 72475f48a0
commit d6998122db
  1. 18
      src/cpp/client/secure_credentials.cc
  2. 21
      src/cpp/server/secure_server_credentials.cc
  3. 16
      src/cpp/server/server_builder.cc
  4. 14
      src/cpp/server/server_cc.cc

@ -262,11 +262,9 @@ std::shared_ptr<ChannelCredentials> AltsCredentials(
grpc::GrpcLibraryCodegen init; // To call grpc_init(). grpc::GrpcLibraryCodegen init; // To call grpc_init().
grpc_alts_credentials_options* c_options = grpc_alts_credentials_options* c_options =
grpc_alts_credentials_client_options_create(); grpc_alts_credentials_client_options_create();
for (auto service_account = options.target_service_accounts.begin(); for (const auto& service_account : options.target_service_accounts) {
service_account != options.target_service_accounts.end();
service_account++) {
grpc_alts_credentials_client_options_add_target_service_account( grpc_alts_credentials_client_options_add_target_service_account(
c_options, service_account->c_str()); c_options, service_account.c_str());
} }
grpc_channel_credentials* c_creds = grpc_alts_credentials_create(c_options); grpc_channel_credentials* c_creds = grpc_alts_credentials_create(c_options);
grpc_alts_credentials_options_destroy(c_options); grpc_alts_credentials_options_destroy(c_options);
@ -439,9 +437,9 @@ int MetadataCredentialsPluginWrapper::GetMetadata(
namespace { namespace {
void UnrefMetadata(const std::vector<grpc_metadata>& md) { void UnrefMetadata(const std::vector<grpc_metadata>& md) {
for (auto it = md.begin(); it != md.end(); ++it) { for (const auto& metadatum : md) {
grpc_slice_unref(it->key); grpc_slice_unref(metadatum.key);
grpc_slice_unref(it->value); grpc_slice_unref(metadatum.value);
} }
} }
@ -461,10 +459,10 @@ void MetadataCredentialsPluginWrapper::InvokePlugin(
Status status = plugin_->GetMetadata(context.service_url, context.method_name, Status status = plugin_->GetMetadata(context.service_url, context.method_name,
cpp_channel_auth_context, &metadata); cpp_channel_auth_context, &metadata);
std::vector<grpc_metadata> md; std::vector<grpc_metadata> md;
for (auto it = metadata.begin(); it != metadata.end(); ++it) { for (auto& metadatum : metadata) {
grpc_metadata md_entry; grpc_metadata md_entry;
md_entry.key = SliceFromCopiedString(it->first); md_entry.key = SliceFromCopiedString(metadatum.first);
md_entry.value = SliceFromCopiedString(it->second); md_entry.value = SliceFromCopiedString(metadatum.second);
md_entry.flags = 0; md_entry.flags = 0;
md.push_back(md_entry); md.push_back(md_entry);
} }

@ -69,20 +69,18 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor(
&response_metadata); &response_metadata);
std::vector<grpc_metadata> consumed_md; std::vector<grpc_metadata> consumed_md;
for (auto it = consumed_metadata.begin(); it != consumed_metadata.end(); for (const auto& consumed : consumed_metadata) {
++it) {
grpc_metadata md_entry; grpc_metadata md_entry;
md_entry.key = SliceReferencingString(it->first); md_entry.key = SliceReferencingString(consumed.first);
md_entry.value = SliceReferencingString(it->second); md_entry.value = SliceReferencingString(consumed.second);
md_entry.flags = 0; md_entry.flags = 0;
consumed_md.push_back(md_entry); consumed_md.push_back(md_entry);
} }
std::vector<grpc_metadata> response_md; std::vector<grpc_metadata> response_md;
for (auto it = response_metadata.begin(); it != response_metadata.end(); for (const auto& response : response_metadata) {
++it) {
grpc_metadata md_entry; grpc_metadata md_entry;
md_entry.key = SliceReferencingString(it->first); md_entry.key = SliceReferencingString(response.first);
md_entry.value = SliceReferencingString(it->second); md_entry.value = SliceReferencingString(response.second);
md_entry.flags = 0; md_entry.flags = 0;
response_md.push_back(md_entry); response_md.push_back(md_entry);
} }
@ -113,10 +111,9 @@ void SecureServerCredentials::SetAuthMetadataProcessor(
std::shared_ptr<ServerCredentials> SslServerCredentials( std::shared_ptr<ServerCredentials> SslServerCredentials(
const grpc::SslServerCredentialsOptions& options) { const grpc::SslServerCredentialsOptions& options) {
std::vector<grpc_ssl_pem_key_cert_pair> pem_key_cert_pairs; std::vector<grpc_ssl_pem_key_cert_pair> pem_key_cert_pairs;
for (auto key_cert_pair = options.pem_key_cert_pairs.begin(); for (const auto& key_cert_pair : options.pem_key_cert_pairs) {
key_cert_pair != options.pem_key_cert_pairs.end(); key_cert_pair++) { grpc_ssl_pem_key_cert_pair p = {key_cert_pair.private_key.c_str(),
grpc_ssl_pem_key_cert_pair p = {key_cert_pair->private_key.c_str(), key_cert_pair.cert_chain.c_str()};
key_cert_pair->cert_chain.c_str()};
pem_key_cert_pairs.push_back(p); pem_key_cert_pairs.push_back(p);
} }
grpc_server_credentials* c_creds = grpc_ssl_server_credentials_create_ex( grpc_server_credentials* c_creds = grpc_ssl_server_credentials_create_ex(

@ -269,8 +269,8 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
std::vector<std::unique_ptr<ServerCompletionQueue>>>()); std::vector<std::unique_ptr<ServerCompletionQueue>>>());
bool has_frequently_polled_cqs = false; bool has_frequently_polled_cqs = false;
for (auto it = cqs_.begin(); it != cqs_.end(); ++it) { for (const auto& cq : cqs_) {
if ((*it)->IsFrequentlyPolled()) { if (cq->IsFrequentlyPolled()) {
has_frequently_polled_cqs = true; has_frequently_polled_cqs = true;
break; break;
} }
@ -278,8 +278,8 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
// == Determine if the server has any callback methods == // == Determine if the server has any callback methods ==
bool has_callback_methods = false; bool has_callback_methods = false;
for (auto it = services_.begin(); it != services_.end(); ++it) { for (const auto& service : services_) {
if ((*it)->service->has_callback_methods()) { if (service->service->has_callback_methods()) {
has_callback_methods = true; has_callback_methods = true;
has_frequently_polled_cqs = true; has_frequently_polled_cqs = true;
break; break;
@ -382,15 +382,15 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
} }
bool added_port = false; bool added_port = false;
for (auto port = ports_.begin(); port != ports_.end(); port++) { for (auto& port : ports_) {
int r = server->AddListeningPort(port->addr, port->creds.get()); int r = server->AddListeningPort(port.addr, port.creds.get());
if (!r) { if (!r) {
if (added_port) server->Shutdown(); if (added_port) server->Shutdown();
return nullptr; return nullptr;
} }
added_port = true; added_port = true;
if (port->selected_port != nullptr) { if (port.selected_port != nullptr) {
*port->selected_port = r; *port.selected_port = r;
} }
} }

@ -1083,16 +1083,14 @@ bool Server::RegisterService(const grpc::string* host, grpc::Service* service) {
const char* method_name = nullptr; const char* method_name = nullptr;
for (auto it = service->methods_.begin(); it != service->methods_.end(); for (const auto& method : service->methods_) {
++it) { if (method.get() == nullptr) { // Handled by generic service if any.
if (it->get() == nullptr) { // Handled by generic service if any.
continue; continue;
} }
grpc::internal::RpcServiceMethod* method = it->get();
void* method_registration_tag = grpc_server_register_method( void* method_registration_tag = grpc_server_register_method(
server_, method->name(), host ? host->c_str() : nullptr, server_, method->name(), host ? host->c_str() : nullptr,
PayloadHandlingForMethod(method), 0); PayloadHandlingForMethod(method.get()), 0);
if (method_registration_tag == nullptr) { if (method_registration_tag == nullptr) {
gpr_log(GPR_DEBUG, "Attempt to register %s multiple times", gpr_log(GPR_DEBUG, "Attempt to register %s multiple times",
method->name()); method->name());
@ -1104,7 +1102,7 @@ bool Server::RegisterService(const grpc::string* host, grpc::Service* service) {
} else if (method->api_type() == } else if (method->api_type() ==
grpc::internal::RpcServiceMethod::ApiType::SYNC) { grpc::internal::RpcServiceMethod::ApiType::SYNC) {
for (const auto& value : sync_req_mgrs_) { for (const auto& value : sync_req_mgrs_) {
value->AddSyncMethod(method, method_registration_tag); value->AddSyncMethod(method.get(), method_registration_tag);
} }
} else { } else {
// a callback method. Register at least some callback requests // a callback method. Register at least some callback requests
@ -1113,8 +1111,8 @@ bool Server::RegisterService(const grpc::string* host, grpc::Service* service) {
// TODO(vjpai): Register these dynamically based on need // TODO(vjpai): Register these dynamically based on need
for (int i = 0; i < DEFAULT_CALLBACK_REQS_PER_METHOD; i++) { for (int i = 0; i < DEFAULT_CALLBACK_REQS_PER_METHOD; i++) {
callback_reqs_to_start_.push_back( callback_reqs_to_start_.push_back(
new CallbackRequest<grpc::ServerContext>(this, method_index, method, new CallbackRequest<grpc::ServerContext>(
method_registration_tag)); this, method_index, method.get(), method_registration_tag));
} }
// Enqueue it so that it will be Request'ed later after all request // Enqueue it so that it will be Request'ed later after all request
// matchers are created at core server startup // matchers are created at core server startup

Loading…
Cancel
Save