summaryrefslogtreecommitdiffstats
path: root/avahi-sharp/ServiceBrowser.cs
diff options
context:
space:
mode:
Diffstat (limited to 'avahi-sharp/ServiceBrowser.cs')
-rw-r--r--avahi-sharp/ServiceBrowser.cs20
1 files changed, 14 insertions, 6 deletions
diff --git a/avahi-sharp/ServiceBrowser.cs b/avahi-sharp/ServiceBrowser.cs
index a96040c..5da7ea4 100644
--- a/avahi-sharp/ServiceBrowser.cs
+++ b/avahi-sharp/ServiceBrowser.cs
@@ -129,22 +129,30 @@ namespace Avahi
private void Start ()
{
- if (handle != IntPtr.Zero || (addListeners.Count == 0 && removeListeners.Count == 0))
+ if (client.Handle == IntPtr.Zero || handle != IntPtr.Zero ||
+ (addListeners.Count == 0 && removeListeners.Count == 0))
return;
IntPtr domainPtr = Utility.StringToPtr (domain);
IntPtr typePtr = Utility.StringToPtr (type);
- handle = avahi_service_browser_new (client.Handle, iface, (int) proto, typePtr, domainPtr,
- cb, IntPtr.Zero);
+
+ lock (client) {
+ handle = avahi_service_browser_new (client.Handle, iface, (int) proto, typePtr, domainPtr,
+ cb, IntPtr.Zero);
+ }
Utility.Free (domainPtr);
Utility.Free (typePtr);
}
private void Stop (bool force)
{
- if (handle != IntPtr.Zero && (force || (addListeners.Count == 0 && removeListeners.Count == 0))) {
- avahi_service_browser_free (handle);
- handle = IntPtr.Zero;
+ if (client.Handle != IntPtr.Zero && handle != IntPtr.Zero &&
+ (force || (addListeners.Count == 0 && removeListeners.Count == 0))) {
+
+ lock (client) {
+ avahi_service_browser_free (handle);
+ handle = IntPtr.Zero;
+ }
}
}