X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FHostNameResolver.cs;h=81305fd778efd9c35b4ee3bdc7591b2e802d8de8;hb=f6dff945b503abc070952682a46920a27edc9093;hp=fad5d77498c604dfe013e50174d3030f60561822;hpb=cc272cf44768c9292879a9ee43783fec4b510ffd;p=catta diff --git a/avahi-sharp/HostNameResolver.cs b/avahi-sharp/HostNameResolver.cs index fad5d77..81305fd 100644 --- a/avahi-sharp/HostNameResolver.cs +++ b/avahi-sharp/HostNameResolver.cs @@ -23,6 +23,7 @@ using System; using System.Collections; using System.Net; using System.Runtime.InteropServices; +using System.Text; using Mono.Unix; namespace Avahi @@ -32,7 +33,7 @@ namespace Avahi ResolverEvent revent, IntPtr hostname, IntPtr address, LookupResultFlags flags, IntPtr userdata); - public class HostNameResolver : IDisposable + public class HostNameResolver : ResolverBase, IDisposable { private IntPtr handle; private Client client; @@ -51,7 +52,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, LookupFlags flags, + byte[] hostname, Protocol aproto, LookupFlags flags, HostNameResolverCallback cb, IntPtr userdata); [DllImport ("avahi-client")] @@ -125,14 +126,14 @@ namespace Avahi (foundListeners.Count == 0 && timeoutListeners.Count == 0)) return; - IntPtr hostPtr = Utility.StringToPtr (hostname); - lock (client) { - handle = avahi_host_name_resolver_new (client.Handle, iface, proto, hostPtr, aproto, flags, + handle = avahi_host_name_resolver_new (client.Handle, iface, proto, + Utility.StringToBytes (hostname), aproto, flags, cb, IntPtr.Zero); + + if (handle == IntPtr.Zero) + client.ThrowError (); } - - Utility.Free (hostPtr); } private void Stop (bool force) @@ -151,18 +152,17 @@ namespace Avahi ResolverEvent revent, IntPtr hostname, IntPtr address, LookupResultFlags flags, IntPtr userdata) { - if (revent == ResolverEvent.Found) { + switch (revent) { + case ResolverEvent.Found: currentAddress = Utility.PtrToAddress (address); currentHost = Utility.PtrToString (hostname); foreach (HostAddressHandler handler in foundListeners) - handler (this, currentHost, currentAddress); - } else { - currentAddress = null; - currentHost = null; - - foreach (EventHandler handler in timeoutListeners) - handler (this, new EventArgs ()); + handler (this, new HostAddressArgs (currentHost, currentAddress)); + break; + case ResolverEvent.Failure: + EmitFailure (client.LastError); + break; } } }