From 740bc001fb647255709b5385d5a8a19781722097 Mon Sep 17 00:00:00 2001 From: James Willcox Date: Wed, 26 Oct 2005 18:01:56 +0000 Subject: * correct the error handling in EntryGroup * 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 | 17 ++++++----------- avahi-sharp/EntryGroup.cs | 32 +++++++++++++++++--------------- 2 files changed, 23 insertions(+), 26 deletions(-) (limited to 'avahi-sharp') diff --git a/avahi-sharp/Client.cs b/avahi-sharp/Client.cs index 73b6f57..cc77cf8 100644 --- a/avahi-sharp/Client.cs +++ b/avahi-sharp/Client.cs @@ -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); } diff --git a/avahi-sharp/EntryGroup.cs b/avahi-sharp/EntryGroup.cs index 4373178..3f8a94c 100644 --- a/avahi-sharp/EntryGroup.cs +++ b/avahi-sharp/EntryGroup.cs @@ -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) { -- cgit