Periodically send discovery requests
This commit is contained in:
@@ -418,6 +418,7 @@ public:
|
||||
void wivrn_discover::discover(std::string service_name)
|
||||
{
|
||||
cache->send_query(MDNS_RECORDTYPE_PTR, service_name);
|
||||
auto next_query = steady_clock::now() + discover_period;
|
||||
|
||||
milliseconds poll_timeout = poll_max_time;
|
||||
std::vector<service> services_staging;
|
||||
@@ -430,6 +431,14 @@ void wivrn_discover::discover(std::string service_name)
|
||||
poll_timeout = poll_max_time;
|
||||
|
||||
auto now = steady_clock::now();
|
||||
|
||||
if (now > next_query)
|
||||
{
|
||||
cache->send_query(MDNS_RECORDTYPE_PTR, service_name);
|
||||
next_query = now + discover_period;
|
||||
}
|
||||
poll_timeout = std::min(poll_timeout, duration_cast<milliseconds>(next_query - now));
|
||||
|
||||
for (auto [ptr, ttl]: cache->read<dnssd_cache::ptr>(service_name))
|
||||
{
|
||||
bool srv_found = false;
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
|
||||
static inline const std::chrono::milliseconds poll_min_time{500};
|
||||
static inline const std::chrono::milliseconds poll_max_time{10000};
|
||||
static inline const std::chrono::milliseconds discover_period{5000};
|
||||
|
||||
private:
|
||||
std::unique_ptr<dnssd_cache> cache;
|
||||
|
||||
Reference in New Issue
Block a user