static
| 46 | { |
| 47 | // static |
| 48 | Pinger::Endpoints Pinger::ExcludeUnavailableAndSortEndpoints(Endpoints const & urls) |
| 49 | { |
| 50 | auto const size = urls.size(); |
| 51 | CHECK_GREATER(size, 0, ()); |
| 52 | |
| 53 | using EntryT = std::pair<int64_t, size_t>; |
| 54 | std::vector<EntryT> timeUrls(size, {pinger::kInvalidPing, 0}); |
| 55 | { |
| 56 | base::DelayedThreadPool pool(size, base::DelayedThreadPool::Exit::ExecPending); |
| 57 | for (size_t i = 0; i < size; ++i) |
| 58 | pool.Push([&urls, &timeUrls, i] { timeUrls[i] = {pinger::DoPing(urls[i]), i}; }); |
| 59 | } |
| 60 | |
| 61 | std::sort(timeUrls.begin(), timeUrls.end(), [](EntryT const & e1, EntryT const & e2) { return e1.first < e2.first; }); |
| 62 | |
| 63 | Endpoints readyUrls; |
| 64 | for (auto const & [ping, index] : timeUrls) |
| 65 | if (ping >= 0) |
| 66 | readyUrls.push_back(urls[index]); |
| 67 | |
| 68 | return readyUrls; |
| 69 | } |
| 70 | } // namespace storage |