X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FServiceResolver.cs;h=7f8901a177a6beefe0ae7ac5a672bf29c0c421cc;hb=77da2ce3eeadca00aad85d1f61d2755739e4809a;hp=e94bd13bba53d85d49399c5212778d2729542ac6;hpb=3a8e64847dff76b56599e37bd31245db9f9ac8ff;p=catta diff --git a/avahi-sharp/ServiceResolver.cs b/avahi-sharp/ServiceResolver.cs index e94bd13..7f8901a 100644 --- a/avahi-sharp/ServiceResolver.cs +++ b/avahi-sharp/ServiceResolver.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 @@ -34,7 +33,7 @@ namespace Avahi UInt16 port, IntPtr txt, LookupResultFlags flags, IntPtr userdata); - public class ServiceResolver : IDisposable + public class ServiceResolver : ResolverBase, IDisposable { private IntPtr handle; private ServiceInfo currentInfo; @@ -50,10 +49,10 @@ namespace Avahi private ArrayList foundListeners = new ArrayList (); private ArrayList timeoutListeners = new ArrayList (); - + [DllImport ("avahi-client")] private static extern IntPtr avahi_service_resolver_new (IntPtr client, int iface, Protocol proto, - IntPtr name, IntPtr type, IntPtr domain, + byte[] name, byte[] type, byte[] domain, Protocol aproto, LookupFlags flags, ServiceResolverCallback cb, IntPtr userdata); @@ -81,7 +80,7 @@ namespace Avahi Stop (false); } } - + public event EventHandler Timeout { add { @@ -114,7 +113,7 @@ namespace Avahi GetLookupFlags (service.Flags)) { } - + public ServiceResolver (Client client, int iface, Protocol proto, string name, string type, string domain, Protocol aproto, LookupFlags flags) { @@ -145,18 +144,14 @@ namespace Avahi (foundListeners.Count == 0 && timeoutListeners.Count == 0)) return; - IntPtr namePtr = Utility.StringToPtr (name); - IntPtr typePtr = Utility.StringToPtr (type); - IntPtr domainPtr = Utility.StringToPtr (domain); - lock (client) { - handle = avahi_service_resolver_new (client.Handle, iface, proto, namePtr, typePtr, domainPtr, - aproto, flags, cb, IntPtr.Zero); + handle = avahi_service_resolver_new (client.Handle, iface, proto, + Utility.StringToBytes (name), Utility.StringToBytes (type), + Utility.StringToBytes (domain), aproto, flags, cb, IntPtr.Zero); + + if (handle == IntPtr.Zero) + client.ThrowError (); } - - Utility.Free (namePtr); - Utility.Free (typePtr); - Utility.Free (domainPtr); } private void Stop (bool force) @@ -187,6 +182,9 @@ namespace Avahi info.Address = Utility.PtrToAddress (address); info.Port = port; + if (proto == Protocol.IPv6) + info.Address.ScopeId = iface; + ArrayList txtlist = new ArrayList (); for (IntPtr l = txt; l != IntPtr.Zero; l = avahi_string_list_get_next (l)) { IntPtr buf = avahi_string_list_get_text (l); @@ -199,17 +197,17 @@ namespace Avahi info.Text = (byte[][]) txtlist.ToArray (typeof (byte[])); info.Flags = flags; - - if (revent == ResolverEvent.Found) { + + switch (revent) { + case ResolverEvent.Found: currentInfo = info; foreach (ServiceInfoHandler handler in foundListeners) - handler (this, info); - } else { - currentInfo = ServiceInfo.Zero; - - foreach (EventHandler handler in timeoutListeners) - handler (this, new EventArgs ()); + handler (this, new ServiceInfoArgs (info)); + break; + case ResolverEvent.Failure: + EmitFailure (client.LastError); + break; } }