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_alts_credentials_options* c_options =
grpc_alts_credentials_client_options_create();
for (auto service_account = options.target_service_accounts.begin();
service_account != options.target_service_accounts.end();
service_account++) {
for (const auto& service_account : options.target_service_accounts) {
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_alts_credentials_options_destroy(c_options);
@ -439,9 +437,9 @@ int MetadataCredentialsPluginWrapper::GetMetadata(
namespace {
void UnrefMetadata(const std::vector<grpc_metadata>& md) {
for (auto it = md.begin(); it != md.end(); ++it) {
grpc_slice_unref(it->key);
grpc_slice_unref(it->value);
for (const auto& metadatum : md) {
grpc_slice_unref(metadatum.key);
grpc_slice_unref(metadatum.value);
}
}
@ -461,10 +459,10 @@ void MetadataCredentialsPluginWrapper::InvokePlugin(
Status status = plugin_->GetMetadata(context.service_url, context.method_name,
cpp_channel_auth_context, &metadata);
std::vector<grpc_metadata> md;
for (auto it = metadata.begin(); it != metadata.end(); ++it) {
for (auto& metadatum : metadata) {
grpc_metadata md_entry;
md_entry.key = SliceFromCopiedString(it->first);
md_entry.value = SliceFromCopiedString(it->second);
md_entry.key = SliceFromCopiedString(metadatum.first);
md_entry.value = SliceFromCopiedString(metadatum.second);
md_entry.flags = 0;
md.push_back(md_entry);
}

@ -69,20 +69,18 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor(
&response_metadata);
std::vector<grpc_metadata> consumed_md;
for (auto it = consumed_metadata.begin(); it != consumed_metadata.end();
++it) {
for (const auto& consumed : consumed_metadata) {
grpc_metadata md_entry;
md_entry.key = SliceReferencingString(it->first);
md_entry.value = SliceReferencingString(it->second);
md_entry.key = SliceReferencingString(consumed.first);
md_entry.value = SliceReferencingString(consumed.second);
md_entry.flags = 0;
consumed_md.push_back(md_entry);
}
std::vector<grpc_metadata> response_md;
for (auto it = response_metadata.begin(); it != response_metadata.end();
++it) {
for (const auto& response : response_metadata) {
grpc_metadata md_entry;
md_entry.key = SliceReferencingString(it->first);
md_entry.value = SliceReferencingString(it->second);
md_entry.key = SliceReferencingString(response.first);
md_entry.value = SliceReferencingString(response.second);
md_entry.flags = 0;
response_md.push_back(md_entry);
}
@ -113,10 +111,9 @@ void SecureServerCredentials::SetAuthMetadataProcessor(
std::shared_ptr<ServerCredentials> SslServerCredentials(
const grpc::SslServerCredentialsOptions& options) {
std::vector<grpc_ssl_pem_key_cert_pair> pem_key_cert_pairs;
for (auto key_cert_pair = options.pem_key_cert_pairs.begin();
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(),
key_cert_pair->cert_chain.c_str()};
for (const auto& key_cert_pair : options.pem_key_cert_pairs) {
grpc_ssl_pem_key_cert_pair p = {key_cert_pair.private_key.c_str(),
key_cert_pair.cert_chain.c_str()};
pem_key_cert_pairs.push_back(p);
}
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>>>());
bool has_frequently_polled_cqs = false;
for (auto it = cqs_.begin(); it != cqs_.end(); ++it) {
if ((*it)->IsFrequentlyPolled()) {
for (const auto& cq : cqs_) {
if (cq->IsFrequentlyPolled()) {
has_frequently_polled_cqs = true;
break;
}
@ -278,8 +278,8 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
// == Determine if the server has any callback methods ==
bool has_callback_methods = false;
for (auto it = services_.begin(); it != services_.end(); ++it) {
if ((*it)->service->has_callback_methods()) {
for (const auto& service : services_) {
if (service->service->has_callback_methods()) {
has_callback_methods = true;
has_frequently_polled_cqs = true;
break;
@ -382,15 +382,15 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
}
bool added_port = false;
for (auto port = ports_.begin(); port != ports_.end(); port++) {
int r = server->AddListeningPort(port->addr, port->creds.get());
for (auto& port : ports_) {
int r = server->AddListeningPort(port.addr, port.creds.get());
if (!r) {
if (added_port) server->Shutdown();
return nullptr;
}
added_port = true;
if (port->selected_port != nullptr) {
*port->selected_port = r;
if (port.selected_port != nullptr) {
*port.selected_port = r;
}
}

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

Loading…
Cancel
Save