Skip to content

Commit

Permalink
in fact no need for destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe44 committed Nov 28, 2023
1 parent 66346ef commit a358bf8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
29 changes: 11 additions & 18 deletions main/platform/linux/MDNSService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class implMDNSService : public MDNSService {
#ifndef BELL_DISABLE_AVAHI
implMDNSService(AvahiEntryGroup* avahiGroup) : avahiGroup(avahiGroup){};
#endif
virtual ~implMDNSService();
void unregisterService();
};

Expand All @@ -70,11 +69,21 @@ void implMDNSService::unregisterService() {
#ifndef BELL_DISABLE_AVAHI
if (avahiGroup) {
avahi_entry_group_free(avahiGroup);
if (!--instances && implMDNSService::avahiClient) {
avahi_client_free(implMDNSService::avahiClient);
avahi_simple_poll_free(implMDNSService::avahiPoll);
implMDNSService::avahiClient = nullptr;
implMDNSService::avahiPoll = nullptr;
}
} else
#endif
{
mdns_service_remove(implMDNSService::mdnsServer, service);
}
if (!--instances && implMDNSService::mdnsServer) {
mdnsd_stop(implMDNSService::mdnsServer);
implMDNSService::mdnsServer = nullptr;
}
}
}

std::unique_ptr<MDNSService> MDNSService::registerService(
Expand Down Expand Up @@ -200,19 +209,3 @@ std::unique_ptr<MDNSService> MDNSService::registerService(
serviceName.c_str());
return NULL;
}

implMDNSService::~implMDNSService() {
if (--instances) return;
#ifndef BELL_DISABLE_AVAHI
if (implMDNSService::avahiClient) {
avahi_client_free(implMDNSService::avahiClient);
avahi_simple_poll_free(implMDNSService::avahiPoll);
implMDNSService::avahiClient = nullptr;
implMDNSService::avahiPoll = nullptr;
} else
#endif
if (implMDNSService::mdnsServer) {
mdnsd_stop(implMDNSService::mdnsServer);
implMDNSService::mdnsServer = nullptr;
}
}
20 changes: 9 additions & 11 deletions main/platform/win32/MDNSService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ using namespace bell;
class implMDNSService : public MDNSService {
private:
struct mdns_service* service;
void unregisterService(void) {
mdns_service_remove(implMDNSService::mdnsServer, service);
};
void unregisterService(void);

public:
static struct mdnsd* mdnsServer;
static std::atomic<size_t> instances;
implMDNSService(struct mdns_service* service) : service(service) { instances++; };
virtual ~implMDNSService();
};

/**
Expand All @@ -39,6 +36,14 @@ std::atomic<size_t> implMDNSService::instances = 0;

static std::mutex registerMutex;

void implMDNSService::unregisterService() {
mdns_service_remove(implMDNSService::mdnsServer, service);
if (!--instances && implMDNSService::mdnsServer) {
mdnsd_stop(implMDNSService::mdnsServer);
implMDNSService::mdnsServer = nullptr;
}
}

std::unique_ptr<MDNSService> MDNSService::registerService(
const std::string& serviceName, const std::string& serviceType,
const std::string& serviceProto, const std::string& serviceHost,
Expand Down Expand Up @@ -100,10 +105,3 @@ std::unique_ptr<MDNSService> MDNSService::registerService(

return std::make_unique<implMDNSService>(service);
}

implMDNSService::~implMDNSService() {
if (!--instances && implMDNSService::mdnsServer) {
mdnsd_stop(implMDNSService::mdnsServer);
implMDNSService::mdnsServer = nullptr;
}
}

0 comments on commit a358bf8

Please sign in to comment.