MCPcopy Create free account
hub / github.com/comaps/comaps / DoPing

Function DoPing

libs/storage/pinger.cpp:16–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14int64_t constexpr kInvalidPing = -1;
15
16int64_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
45namespace storage

Callers 1

Calls 7

ASSERTFunction · 0.85
WasRedirectedMethod · 0.80
ErrorCodeMethod · 0.80
emptyMethod · 0.45
SetTimeoutMethod · 0.45
RunHttpRequestMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected