mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Handle failure to stop mDNS
PiperOrigin-RevId: 748865989
This commit is contained in:
committed by
Copybara-Service
parent
ce71a47291
commit
e047aeb341
@@ -157,24 +157,18 @@ bool WifiLanMdns::StopMdnsService() {
|
||||
|
||||
if (status != DNS_REQUEST_PENDING) {
|
||||
NEARBY_LOGS(ERROR) << "Failed to stop mDNS advertising.";
|
||||
CleanUp();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dns_service_notification_->WaitForNotificationWithTimeout(
|
||||
kDnsServiceTimeout)) {
|
||||
LOG(ERROR) << "Failed to start mDNS advertising.";
|
||||
CleanUp();
|
||||
return false;
|
||||
}
|
||||
|
||||
dns_service_notification_ = nullptr;
|
||||
if (dns_service_instance_.keys != nullptr) {
|
||||
delete[] dns_service_instance_.keys;
|
||||
delete[] dns_service_instance_.values;
|
||||
dns_service_instance_.keys = nullptr;
|
||||
dns_service_instance_.values = nullptr;
|
||||
}
|
||||
|
||||
is_service_started_ = false;
|
||||
CleanUp();
|
||||
LOG(INFO) << "Succeeded to stop mDNS advertising.";
|
||||
|
||||
return true;
|
||||
@@ -206,4 +200,15 @@ void WifiLanMdns::DnsServiceRegisterComplete(DWORD Status, PVOID pQueryContext,
|
||||
mdns->NotifyStatusUpdated(Status);
|
||||
}
|
||||
|
||||
void WifiLanMdns::CleanUp() {
|
||||
is_service_started_ = false;
|
||||
dns_service_notification_ = nullptr;
|
||||
if (dns_service_instance_.keys != nullptr) {
|
||||
delete[] dns_service_instance_.keys;
|
||||
delete[] dns_service_instance_.values;
|
||||
dns_service_instance_.keys = nullptr;
|
||||
dns_service_instance_.values = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nearby::windows
|
||||
|
||||
@@ -38,9 +38,10 @@ class WifiLanMdns {
|
||||
|
||||
bool StartMdnsService(
|
||||
const std::string& service_name, const std::string& service_type,
|
||||
int port, absl::flat_hash_map<std::string, std::string> text_records);
|
||||
int port, absl::flat_hash_map<std::string, std::string> text_records)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
bool StopMdnsService();
|
||||
bool StopMdnsService() ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
void NotifyStatusUpdated(DWORD status);
|
||||
|
||||
@@ -48,6 +49,7 @@ class WifiLanMdns {
|
||||
static void DnsServiceRegisterComplete(DWORD Status, PVOID pQueryContext,
|
||||
PDNS_SERVICE_INSTANCE pInstance);
|
||||
std::optional<std::string> GetComputerName();
|
||||
void CleanUp() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
absl::Mutex mutex_;
|
||||
std::unique_ptr<absl::Notification> dns_service_notification_ = nullptr;
|
||||
|
||||
@@ -220,6 +220,7 @@ bool WifiLanMedium::StopAdvertising(const NsdServiceInfo& nsd_service_info) {
|
||||
}
|
||||
|
||||
LOG(ERROR) << "failed to stop mDNS advertising.";
|
||||
medium_status_ &= (~kMediumStatusAdvertising);
|
||||
return false;
|
||||
} else {
|
||||
dnssd_service_instance_ = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user