]> git.meshlink.io Git - catta/blobdiff - avahi-sharp/HostNameResolver.cs
lose the dep on avahi-glib, and run the avahi loop in a thread
[catta] / avahi-sharp / HostNameResolver.cs
index a8cf0f17052d117cdf83313e6ea0c7dc9a90ebee..d522cea66425594164784853b41254b979d55f6d 100644 (file)
@@ -118,20 +118,29 @@ namespace Avahi
 
         private void Start ()
         {
-            if (handle != IntPtr.Zero || (foundListeners.Count == 0 && timeoutListeners.Count == 0))
+            if (client.Handle == IntPtr.Zero || handle != IntPtr.Zero ||
+                (foundListeners.Count == 0 && timeoutListeners.Count == 0))
                 return;
 
             IntPtr hostPtr = Utility.StringToPtr (hostname);
-            handle = avahi_host_name_resolver_new (client.Handle, iface, proto, hostPtr, aproto,
-                                                   cb, IntPtr.Zero);
+
+            lock (client) {
+                handle = avahi_host_name_resolver_new (client.Handle, iface, proto, hostPtr, aproto,
+                                                       cb, IntPtr.Zero);
+            }
+            
             Utility.Free (hostPtr);
         }
 
         private void Stop (bool force)
         {
-            if (handle != IntPtr.Zero && (force || (foundListeners.Count == 0 && timeoutListeners.Count == 0))) {
-                avahi_host_name_resolver_free (handle);
-                handle = IntPtr.Zero;
+            if (client.Handle != IntPtr.Zero && handle != IntPtr.Zero &&
+                (force || (foundListeners.Count == 0 && timeoutListeners.Count == 0))) {
+
+                lock (client) {
+                    avahi_host_name_resolver_free (handle);
+                    handle = IntPtr.Zero;
+                }
             }
         }