Skip to content

Commit

Permalink
Get multicast lock when publishing services on android (#22519)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 authored and pull[bot] committed Nov 14, 2023
1 parent baa06ca commit 1069776
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ public void onServiceUnregistered(NsdServiceInfo serviceInfo) {
"service " + serviceInfo.getServiceName() + "(" + this + ") onServiceUnregistered");
}
};
if (registrationListeners.size() == 0) {
multicastLock.acquire();
}
registrationListeners.add(registrationListener);

nsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, registrationListener);
Expand All @@ -198,6 +201,9 @@ public void onServiceUnregistered(NsdServiceInfo serviceInfo) {
@Override
public void removeServices() {
Log.d(TAG, "removeServices: ");
if (registrationListeners.size() > 0) {
multicastLock.release();
}
for (NsdManager.RegistrationListener l : registrationListeners) {
Log.i(TAG, "Remove " + l);
nsdManager.unregisterService(l);
Expand Down

0 comments on commit 1069776

Please sign in to comment.