X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FClient.cs;h=02763d40d67be6357ef00355a39b22e1d13dcfe1;hb=b2a161037f30c49e6128e7a42dd08f92d08d3b08;hp=be9deff7491bfb2021faff5b887532bd758d760a;hpb=6cc9575148671ed743b86687b0d7e1b876a99114;p=catta diff --git a/avahi-sharp/Client.cs b/avahi-sharp/Client.cs index be9deff..02763d4 100644 --- a/avahi-sharp/Client.cs +++ b/avahi-sharp/Client.cs @@ -27,6 +27,8 @@ using System.Runtime.InteropServices; using Mono.Unix; using Mono.Unix.Native; +using Stdlib = Mono.Unix.Native.Stdlib; + namespace Avahi { internal enum ResolverEvent { @@ -50,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; } } @@ -277,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); + } } } @@ -347,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) { @@ -361,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);