X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FClient.cs;h=02763d40d67be6357ef00355a39b22e1d13dcfe1;hb=d7a988b459bedde8ebd2a34d954c2c1836c5a5f8;hp=8ec6616d4403b956201f9d91c38884631540e5e2;hpb=d8fcf547a8c853ad6b2f92d2671a0389aa65b556;p=catta diff --git a/avahi-sharp/Client.cs b/avahi-sharp/Client.cs index 8ec6616..02763d4 100644 --- a/avahi-sharp/Client.cs +++ b/avahi-sharp/Client.cs @@ -52,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; } } @@ -279,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); + } } } @@ -349,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) { @@ -363,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);