]> git.meshlink.io Git - catta/blobdiff - avahi-sharp/RecordBrowser.cs
fix avahi_netlink_new to allow multiple netlinks per process
[catta] / avahi-sharp / RecordBrowser.cs
index 5a736bd3d13b284198e8b08cd693369b716da603..ba5a983b9dea8bc2fbab30b32f67bfe01887a720 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: ServiceBrowser.cs 635 2005-09-26 03:57:30Z snorp $ */
-
 /***
   This file is part of avahi.
 
@@ -23,12 +21,13 @@ using System;
 using System.Net;
 using System.Collections;
 using System.Runtime.InteropServices;
+using System.Text;
 
 namespace Avahi
 {
 
     public delegate void RecordInfoHandler (object o, RecordInfoArgs args);
-    
+
     internal delegate void RecordBrowserCallback (IntPtr browser, int iface, Protocol proto, BrowserEvent bevent,
                                                   IntPtr name, ushort clazz, ushort type, IntPtr rdata, int size,
                                                   LookupResultFlags flags, IntPtr userdata);
@@ -49,7 +48,7 @@ namespace Avahi
         Aaa = 28,
         Srv = 33
     }
-    
+
     public struct RecordInfo
     {
         public int NetworkInterface;
@@ -90,10 +89,10 @@ namespace Avahi
 
         private ArrayList addListeners = new ArrayList ();
         private ArrayList removeListeners = new ArrayList ();
-        
+
         [DllImport ("avahi-client")]
         private static extern IntPtr avahi_record_browser_new (IntPtr client, int iface, Protocol proto,
-                                                               IntPtr name, ushort clazz, ushort type,
+                                                               byte[] name, ushort clazz, ushort type,
                                                                LookupFlags flags, RecordBrowserCallback cb,
                                                                IntPtr userdata);
 
@@ -112,7 +111,7 @@ namespace Avahi
                 Stop (false);
             }
         }
-        
+
         public event RecordInfoHandler RecordRemoved
         {
             add {
@@ -134,7 +133,7 @@ namespace Avahi
             this (client, -1, Protocol.Unspecified, name, RecordClass.In, type, LookupFlags.None)
         {
         }
-        
+
         public RecordBrowser (Client client, int iface, Protocol proto, string name, RecordClass clazz,
                               RecordType type, LookupFlags flags)
         {
@@ -164,21 +163,20 @@ namespace Avahi
                 (addListeners.Count == 0 && removeListeners.Count == 0))
                 return;
 
-            IntPtr namePtr = Utility.StringToPtr (name);
-
             lock (client) {
-                handle = avahi_record_browser_new (client.Handle, iface, proto, namePtr, (ushort) clazz, (ushort) type,
-                                                   flags, cb, IntPtr.Zero);
-            }
+                handle = avahi_record_browser_new (client.Handle, iface, proto, Utility.StringToBytes (name),
+                                                   (ushort) clazz, (ushort) type, flags, cb, IntPtr.Zero);
 
-            Utility.Free (namePtr);
+                if (handle == IntPtr.Zero)
+                    client.ThrowError ();
+            }
         }
 
         private void Stop (bool force)
         {
             if (client.Handle != IntPtr.Zero && handle != IntPtr.Zero &&
                 (force || (addListeners.Count == 0 && removeListeners.Count == 0))) {
-                
+
                 lock (client) {
                     avahi_record_browser_free (handle);
                     handle = IntPtr.Zero;