| 14 | int64_t constexpr kInvalidPing = -1; |
| 15 | |
| 16 | int64_t DoPing(std::string const & url) |
| 17 | { |
| 18 | using namespace std::chrono; |
| 19 | |
| 20 | if (url.empty()) |
| 21 | { |
| 22 | ASSERT(false, ("Metaserver returned an empty url.")); |
| 23 | return kInvalidPing; |
| 24 | } |
| 25 | |
| 26 | LOG(LDEBUG, ("Pinging server", url)); |
| 27 | platform::HttpClient request(url); |
| 28 | request.SetHttpMethod("HEAD"); |
| 29 | request.SetTimeout(kTimeoutInSeconds); |
| 30 | auto const begin = high_resolution_clock::now(); |
| 31 | if (request.RunHttpRequest() && !request.WasRedirected() && request.ErrorCode() == 200) |
| 32 | { |
| 33 | return duration_cast<milliseconds>(high_resolution_clock::now() - begin).count(); |
| 34 | } |
| 35 | else |
| 36 | { |
| 37 | LOG(LWARNING, ("Ping to server", url, "failed with code =", request.ErrorCode(), |
| 38 | "; wasRedirected =", request.WasRedirected())); |
| 39 | } |
| 40 | |
| 41 | return kInvalidPing; |
| 42 | } |
| 43 | } // namespace pinger |
| 44 | |
| 45 | namespace storage |
no test coverage detected