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 Jan 31, 2024
1 parent feccb57 commit 4531059
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 4531059

Please sign in to comment.