]> git.meshlink.io Git - catta/blobdiff - avahi-sharp/HostNameResolver.cs
add a missing file, and add EntryGroup.GetAlternativeServiceName
[catta] / avahi-sharp / HostNameResolver.cs
index de2ff51b38cd2a23a58c44b5a1d0cc2a34932191..d522cea66425594164784853b41254b979d55f6d 100644 (file)
@@ -1,3 +1,5 @@
+/* $Id$ */
+
 /***
   This file is part of avahi.
 
@@ -38,6 +40,7 @@ namespace Avahi
         private Protocol proto;
         private string hostname;
         private Protocol aproto;
+        private HostNameResolverCallback cb;
 
         private IPAddress currentAddress;
         private string currentHost;
@@ -100,6 +103,7 @@ namespace Avahi
             this.proto = proto;
             this.hostname = hostname;
             this.aproto = aproto;
+            cb = OnHostNameResolverCallback;
         }
 
         ~HostNameResolver ()
@@ -114,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,
-                                                   OnHostNameResolverCallback, 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;
+                }
             }
         }