X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FClient.cs;h=02763d40d67be6357ef00355a39b22e1d13dcfe1;hb=f8f00d3edbecf619548779dc4244f075d6f4b32f;hp=4e19fabfcb2678f4e1f950da39d9326542da70bb;hpb=029be78f80b011465e1bb736b87ccdb2df0bab57;p=catta diff --git a/avahi-sharp/Client.cs b/avahi-sharp/Client.cs index 4e19fab..02763d4 100644 --- a/avahi-sharp/Client.cs +++ b/avahi-sharp/Client.cs @@ -25,6 +25,9 @@ using System.Threading; using System.Collections; using System.Runtime.InteropServices; using Mono.Unix; +using Mono.Unix.Native; + +using Stdlib = Mono.Unix.Native.Stdlib; namespace Avahi { @@ -49,15 +52,22 @@ namespace Avahi public class ClientStateArgs : EventArgs { private ClientState state; + private ErrorCode error; public ClientState State { get { return state; } } - public ClientStateArgs (ClientState state) + public ErrorCode Error + { + get { return error; } + } + + public ClientStateArgs (ClientState state, ErrorCode error) { this.state = state; + this.error = error; } } @@ -276,10 +286,15 @@ namespace Avahi public void Dispose () { if (handle != IntPtr.Zero) { - avahi_client_free (handle); - avahi_simple_poll_quit (spoll); - avahi_simple_poll_free (spoll); - handle = IntPtr.Zero; + lock (this) { + avahi_client_free (handle); + handle = IntPtr.Zero; + + avahi_simple_poll_quit (spoll); + Monitor.Wait (this); + + avahi_simple_poll_free (spoll); + } } } @@ -346,7 +361,7 @@ namespace Avahi private void OnClientCallback (IntPtr client, ClientState state, IntPtr userData) { if (StateChanged != null) - StateChanged (this, new ClientStateArgs (state)); + StateChanged (this, new ClientStateArgs (state, LastError)); } private int OnPollCallback (IntPtr ufds, uint nfds, int timeout) { @@ -360,6 +375,7 @@ namespace Avahi try { lock (this) { avahi_simple_poll_loop (spoll); + Monitor.Pulse (this); } } catch (Exception e) { Console.Error.WriteLine ("Error in avahi-sharp event loop: " + e);