X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FHostNameResolver.cs;h=fad5d77498c604dfe013e50174d3030f60561822;hb=c75a6b480b047abc73ee7afd912aef249e9da8e3;hp=a8cf0f17052d117cdf83313e6ea0c7dc9a90ebee;hpb=4d283fbd912fbeab578447ea18c0d8f47aa5cea6;p=catta diff --git a/avahi-sharp/HostNameResolver.cs b/avahi-sharp/HostNameResolver.cs index a8cf0f1..fad5d77 100644 --- a/avahi-sharp/HostNameResolver.cs +++ b/avahi-sharp/HostNameResolver.cs @@ -30,7 +30,7 @@ namespace Avahi internal delegate void HostNameResolverCallback (IntPtr resolver, int iface, Protocol proto, ResolverEvent revent, IntPtr hostname, IntPtr address, - IntPtr userdata); + LookupResultFlags flags, IntPtr userdata); public class HostNameResolver : IDisposable { @@ -40,6 +40,7 @@ namespace Avahi private Protocol proto; private string hostname; private Protocol aproto; + private LookupFlags flags; private HostNameResolverCallback cb; private IPAddress currentAddress; @@ -50,7 +51,7 @@ namespace Avahi [DllImport ("avahi-client")] private static extern IntPtr avahi_host_name_resolver_new (IntPtr client, int iface, Protocol proto, - IntPtr hostname, Protocol aproto, + IntPtr hostname, Protocol aproto, LookupFlags flags, HostNameResolverCallback cb, IntPtr userdata); [DllImport ("avahi-client")] @@ -91,18 +92,20 @@ namespace Avahi } public HostNameResolver (Client client, string hostname) : this (client, -1, Protocol.Unspecified, - hostname, Protocol.Unspecified) + hostname, Protocol.Unspecified, + LookupFlags.None) { } public HostNameResolver (Client client, int iface, Protocol proto, string hostname, - Protocol aproto) + Protocol aproto, LookupFlags flags) { this.client = client; this.iface = iface; this.proto = proto; this.hostname = hostname; this.aproto = aproto; + this.flags = flags; cb = OnHostNameResolverCallback; } @@ -118,26 +121,35 @@ 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, flags, + 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; + } } } private void OnHostNameResolverCallback (IntPtr resolver, int iface, Protocol proto, ResolverEvent revent, IntPtr hostname, IntPtr address, - IntPtr userdata) + LookupResultFlags flags, IntPtr userdata) { if (revent == ResolverEvent.Found) { currentAddress = Utility.PtrToAddress (address);