pocoproject / poco-dnssd

POCO DNS-SD (Zeroconf) Wrapper Library for Bonjour and Avahi
Other
21 stars 13 forks source link

The calling of serviceResolved for a particular service is incrementally increased #7

Open soroshsabz opened 7 years ago

soroshsabz commented 7 years ago

ITNOA

Hi,

I have a main code like below

dnssd_responder.start();

dnssd_responder.browser().serviceFound += Poco::delegate(on_service_found);
dnssd_responder.browser().serviceResolved += Poco::delegate(on_service_resolved);

Poco::DNSSD::Service service("_test._udp", 3000);

dnssd_responder.browse().browse("_test._udp", "local");

auto service_handle = dnssd_responder.registerService(service);
std::this_thread::sleep_for(3s);
dnssd_responder.unregisterService(service_handle);
service_handle = dnssd_responder.registerService(service);
dnssd_responder.unregisterService(service_handle);

and i have a simple implementaion for event handlers like below

void on_service_found(const void* sender, const Poco::DNSSD::DNSSDBrowser::ServiceEventArgs& arguments)
{
    reinterpret_cast<Poco::DNSSD::DNSSDBrowser*>(const_cast<void*>(sender))->resolve(arguments.service));
}

void on_service_resolved(const void* sender, const Poco::DNSSD::DNSSDBrowser::ServiceEventArgs& arguments)
{
    static int a = 0;
    std::cout << "number of on service resolved calls: " << ++a << std::endl;
}

I expect that after the run program i see 2 line and last a equal to 2, but i see 3 line and last a equal to 3.

I think the problem is resolver run in background continuously, for each on_service_found called and it does not stop after new resolve called. However, the documentation of resolve method in DNSSDBrowser.h file says: "After either the serviceResolved or resolveError event has been fired, the returend BrowseHandle is no longer valid" so i think resolve will be stop after fire serviceResolved, But it does not follow behavior that i guess.

I have two question about that:

  1. Is this an bug or not?
  2. If this does not a bug, so what is the solution for call on_service_resolve only twice?

thanks a lot

thegreathir commented 6 years ago

No answer?