| 509 | } |
| 510 | |
| 511 | bool ReactorThread::FindConnection(const ConnectionId& conn_id, |
| 512 | CredentialsPolicy cred_policy, |
| 513 | scoped_refptr<Connection>* conn) { |
| 514 | DCHECK(IsCurrentThread()); |
| 515 | const auto range = client_conns_.equal_range(conn_id); |
| 516 | scoped_refptr<Connection> found_conn; |
| 517 | for (auto it = range.first; it != range.second;) { |
| 518 | const auto& c = it->second.get(); |
| 519 | // * Do not use connections scheduled for shutdown to place new calls. |
| 520 | // |
| 521 | // * Do not use a connection with a non-compliant credentials policy. |
| 522 | // Instead, open a new one, while marking the former as scheduled for |
| 523 | // shutdown. This process converges: any connection that satisfies the |
| 524 | // PRIMARY_CREDENTIALS policy automatically satisfies the ANY_CREDENTIALS |
| 525 | // policy as well. The idea is to keep only one usable connection |
| 526 | // identified by the specified 'conn_id'. |
| 527 | // |
| 528 | // * If the test-only 'one-connection-per-RPC' mode is enabled, connections |
| 529 | // are re-established at every RPC call. |
| 530 | if (c->scheduled_for_shutdown() || |
| 531 | !c->SatisfiesCredentialsPolicy(cred_policy) || |
| 532 | PREDICT_FALSE(FLAGS_rpc_reopen_outbound_connections)) { |
| 533 | if (c->Idle()) { |
| 534 | // Shutdown idle connections to the target destination. Non-idle ones |
| 535 | // will be taken care of later by the idle connection scanner. |
| 536 | DCHECK_EQ(Connection::CLIENT, c->direction()); |
| 537 | c->Shutdown(Status::NetworkError("connection is closed due to non-reuse policy")); |
| 538 | it = client_conns_.erase(it); |
| 539 | continue; |
| 540 | } |
| 541 | c->set_scheduled_for_shutdown(); |
| 542 | } else { |
| 543 | DCHECK(!found_conn); |
| 544 | found_conn = c; |
| 545 | // Appropriate connection is found; continue further to take care of the |
| 546 | // rest of connections to mark them for shutdown if they are not |
| 547 | // satisfying the policy. |
| 548 | } |
| 549 | ++it; |
| 550 | } |
| 551 | if (found_conn) { |
| 552 | // Found matching not-to-be-shutdown connection: return it as the result. |
| 553 | conn->swap(found_conn); |
| 554 | return true; |
| 555 | } |
| 556 | return false; |
| 557 | } |
| 558 | |
| 559 | Status ReactorThread::FindOrStartConnection(const ConnectionId& conn_id, |
| 560 | CredentialsPolicy cred_policy, |
nothing calls this directly
no test coverage detected