X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FHostNameResolver.cs;h=b9fe7f4348e8da6aac2e363efd0d70ecf36cbab6;hb=6c560282c3d67856e62fb7faa12bf036f9fce529;hp=44febcdf4d1a8f4d2bc4703978bdb936deb4f501;hpb=6d952319b1a15b439150e7f5911b12e7fc204b69;p=catta diff --git a/avahi-sharp/HostNameResolver.cs b/avahi-sharp/HostNameResolver.cs index 44febcd..b9fe7f4 100644 --- a/avahi-sharp/HostNameResolver.cs +++ b/avahi-sharp/HostNameResolver.cs @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of avahi. @@ -23,6 +21,7 @@ using System; using System.Collections; using System.Net; using System.Runtime.InteropServices; +using System.Text; using Mono.Unix; namespace Avahi @@ -48,10 +47,10 @@ namespace Avahi private ArrayList foundListeners = new ArrayList (); private ArrayList timeoutListeners = new ArrayList (); - + [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")] @@ -68,7 +67,7 @@ namespace Avahi Stop (false); } } - + public event EventHandler Timeout { add { @@ -125,14 +124,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) @@ -157,17 +156,10 @@ namespace Avahi currentHost = Utility.PtrToString (hostname); foreach (HostAddressHandler handler in foundListeners) - handler (this, currentHost, currentAddress); - break; - case ResolverEvent.Timeout: - currentAddress = null; - currentHost = null; - - foreach (EventHandler handler in timeoutListeners) - handler (this, new EventArgs ()); + handler (this, new HostAddressArgs (currentHost, currentAddress)); break; - default: - EmitResolverEvent (revent); + case ResolverEvent.Failure: + EmitFailure (client.LastError); break; } }