36static bool Ping(
const std::string& url,
long port = 8443L) {
37 CURL* c = curl_easy_init();
38 curl_easy_setopt(c, CURLOPT_URL, url.c_str());
39 curl_easy_setopt(c, CURLOPT_PORT, port);
40 curl_easy_setopt(c, CURLOPT_TIMEOUT_MS, 2000L);
41 CURLcode result = curl_easy_perform(c);
43 bool ok = result == CURLE_RECV_ERROR || result == CURLE_OK;
44 DEBUG_LOG <<
"Checked mdns host: " << url <<
": "
45 << (ok ?
"ok" : curl_easy_strerror(result));
55 std::unique_lock lock(m_mutex);
56 auto found = std::find_if(m_cache.begin(), m_cache.end(),
57 [entry](
Entry& e) { return e.ip == entry.ip; });
58 DEBUG_LOG <<
"Added mdns cache entry, ip: " << entry.ip
59 <<
", status: " << (found == m_cache.end() ?
"true" :
"false");
60 if (found != m_cache.end())
return false;
61 m_cache.push_back(entry);
66 const std::string& _ip,
const std::string& _port) {
67 return Add(
Entry(service, host, _ip, _port));
71 return Add(
Entry(
"opencpn",
"unknown", _ip, _port));
75 std::unique_lock lock(m_mutex);
76 for (
auto it = m_cache.begin(); it != m_cache.end();) {
Singleton cache for hosts looked up using mdns.
bool Add(const Entry &entry)
Add new entry to the cache.
void Validate()
Check that all entries are accessible, remove stale ones.
Enhanced logging interface on top of wx/log.h.
MdnsCache mDNS host lookups cache.