]> git.meshlink.io Git - catta/commitdiff
* correct the error handling in EntryGroup
authorJames Willcox <snopr@snorp.net>
Wed, 26 Oct 2005 18:01:56 +0000 (18:01 +0000)
committerJames Willcox <snopr@snorp.net>
Wed, 26 Oct 2005 18:01:56 +0000 (18:01 +0000)
* get rid of evil Thread.Abort

git-svn-id: file:///home/lennart/svn/public/avahi/trunk@878 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-sharp/Client.cs
avahi-sharp/EntryGroup.cs

index 73b6f57c0b85f19db23ea3e84c51d027e928a161..cc77cf870e0100fa1c8da4b22c9065591f70425b 100644 (file)
@@ -232,19 +232,15 @@ namespace Avahi
 
         public void Dispose ()
         {
-            lock (this) {
-                if (handle != IntPtr.Zero) {
-                    thread.Abort ();
-
-                    avahi_client_free (handle);
-                    avahi_simple_poll_quit (spoll);
-                    avahi_simple_poll_free (spoll);
-                    handle = IntPtr.Zero;
-                }
+            if (handle != IntPtr.Zero) {
+                avahi_client_free (handle);
+                avahi_simple_poll_quit (spoll);
+                avahi_simple_poll_free (spoll);
+                handle = IntPtr.Zero;
             }
         }
 
-        internal void CheckError ()
+        internal void ThrowError ()
         {
             ErrorCode error = LastError;
 
@@ -270,7 +266,6 @@ namespace Avahi
                 lock (this) {
                     avahi_simple_poll_loop (spoll);
                 }
-            } catch (ThreadAbortException e) {
             } catch (Exception e) {
                 Console.Error.WriteLine ("Error in avahi-sharp event loop: " + e);
             }
index 4373178b1b71dd560fecd60dc78f6ab147b077e2..3f8a94cd98f3abfe44a2a06bbba2aa310754df23 100644 (file)
@@ -59,10 +59,10 @@ namespace Avahi
         private static extern IntPtr avahi_entry_group_new (IntPtr client, EntryGroupCallback cb, IntPtr userdata);
 
         [DllImport ("avahi-client")]
-        private static extern void avahi_entry_group_commit (IntPtr group);
+        private static extern int avahi_entry_group_commit (IntPtr group);
 
         [DllImport ("avahi-client")]
-        private static extern void avahi_entry_group_reset (IntPtr group);
+        private static extern int avahi_entry_group_reset (IntPtr group);
 
         [DllImport ("avahi-client")]
         private static extern EntryGroupState avahi_entry_group_get_state (IntPtr group);
@@ -71,10 +71,10 @@ namespace Avahi
         private static extern bool avahi_entry_group_is_empty (IntPtr group);
 
         [DllImport ("avahi-client")]
-        private static extern void avahi_entry_group_add_service_strlst (IntPtr group, int iface, Protocol proto,
-                                                                         PublishFlags flags, IntPtr name, IntPtr type,
-                                                                         IntPtr domain, IntPtr host, UInt16 port,
-                                                                         IntPtr strlst);
+        private static extern int avahi_entry_group_add_service_strlst (IntPtr group, int iface, Protocol proto,
+                                                                        PublishFlags flags, IntPtr name, IntPtr type,
+                                                                        IntPtr domain, IntPtr host, UInt16 port,
+                                                                        IntPtr strlst);
         
         [DllImport ("avahi-client")]
         private static extern void avahi_entry_group_free (IntPtr group);
@@ -118,7 +118,8 @@ namespace Avahi
 
             lock (client) {
                 handle = avahi_entry_group_new (client.Handle, cb, IntPtr.Zero);
-                client.CheckError ();
+                if (handle == IntPtr.Zero)
+                    client.ThrowError ();
             }
         }
 
@@ -140,16 +141,16 @@ namespace Avahi
         public void Commit ()
         {
             lock (client) {
-                avahi_entry_group_commit (handle);
-                client.CheckError ();
+                if (avahi_entry_group_commit (handle) < 0)
+                    client.ThrowError ();
             }
         }
 
         public void Reset ()
         {
             lock (client) {
-                avahi_entry_group_reset (handle);
-                client.CheckError ();
+                if (avahi_entry_group_reset (handle) < 0)
+                    client.ThrowError ();
             }
         }
 
@@ -184,13 +185,14 @@ namespace Avahi
             IntPtr hostPtr = Utility.StringToPtr (host);
 
             lock (client) {
-                avahi_entry_group_add_service_strlst (handle, iface, proto, flags, namePtr, typePtr, domainPtr,
-                                                      hostPtr, port, list);
+                int ret = avahi_entry_group_add_service_strlst (handle, iface, proto, flags, namePtr, typePtr, domainPtr,
+                                                                hostPtr, port, list);
+                if (ret < 0) {
+                    client.ThrowError ();
+                }
             }
             
             avahi_string_list_free (list);
-
-            client.CheckError ();
         }
 
         public static string GetAlternativeServiceName (string name) {