X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FAddressResolver.cs;h=c462346452e48067a84750ed58e23be155117b08;hb=5af9f469d85a9281bc5484e9f5a8740751591dfe;hp=8a0b66ba6e3d63ce2f6b280af0b40e423f53394a;hpb=a26804ae8742b59b220b5a0776f42de3da026d6a;p=catta diff --git a/avahi-sharp/AddressResolver.cs b/avahi-sharp/AddressResolver.cs index 8a0b66b..c462346 100644 --- a/avahi-sharp/AddressResolver.cs +++ b/avahi-sharp/AddressResolver.cs @@ -41,6 +41,7 @@ namespace Avahi private int iface; private Protocol proto; private IPAddress address; + private AddressResolverCallback cb; private IPAddress currentAddress; private string currentHost; @@ -100,6 +101,7 @@ namespace Avahi this.iface = iface; this.proto = proto; this.address = address; + cb = OnAddressResolverCallback; } ~AddressResolver () @@ -114,20 +116,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 addrPtr = Utility.StringToPtr (address.ToString ()); - handle = avahi_address_resolver_new (client.Handle, iface, proto, addrPtr, - OnAddressResolverCallback, IntPtr.Zero); + + lock (client) { + handle = avahi_address_resolver_new (client.Handle, iface, proto, addrPtr, + cb, IntPtr.Zero); + } + Utility.Free (addrPtr); } private void Stop (bool force) { - if (handle != IntPtr.Zero && (force || (foundListeners.Count == 0 && timeoutListeners.Count == 0))) { - avahi_address_resolver_free (handle); - handle = IntPtr.Zero; + if (client.Handle != IntPtr.Zero && handle != IntPtr.Zero && + (force || (foundListeners.Count == 0 && timeoutListeners.Count == 0))) { + + lock (client) { + avahi_address_resolver_free (handle); + handle = IntPtr.Zero; + } } }