X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FClient.cs;h=394efc58e22100db7790d83782927e1815a923f2;hb=59d6820e1866dc65cfec7536f95906e186765016;hp=73b6f57c0b85f19db23ea3e84c51d027e928a161;hpb=94d2753047cff1e9223e42736884e4d51348b45a;p=catta diff --git a/avahi-sharp/Client.cs b/avahi-sharp/Client.cs index 73b6f57..394efc5 100644 --- a/avahi-sharp/Client.cs +++ b/avahi-sharp/Client.cs @@ -50,13 +50,20 @@ namespace Avahi IPv4 = 0, IPv6 = 1 } - - public enum ClientState { + + internal enum ServerState { Invalid, Registering, Running, - Collision, - Disconnected = 100 + Collision + } + + public enum ClientState { + Registering = ServerState.Registering, + Running = ServerState.Running, + Collision = ServerState.Collision, + Failure = 100, + Connecting = 101 } [Flags] @@ -76,6 +83,13 @@ namespace Avahi Local = 8, OurOwn = 16, } + + [Flags] + public enum ClientFlags { + None = 0, + IgnoreUserConfig = 1, + NoFail = 2 + } public class Client : IDisposable { @@ -87,7 +101,7 @@ namespace Avahi private Thread thread; [DllImport ("avahi-client")] - private static extern IntPtr avahi_client_new (IntPtr poll, ClientCallback handler, + private static extern IntPtr avahi_client_new (IntPtr poll, ClientFlags flags, ClientCallback handler, IntPtr userData, out int error); [DllImport ("avahi-client")] @@ -206,7 +220,7 @@ namespace Avahi } } - public Client () + public Client (ClientFlags flags) { spoll = avahi_simple_poll_new (); @@ -216,7 +230,7 @@ namespace Avahi cb = OnClientCallback; int error; - handle = avahi_client_new (poll, cb, IntPtr.Zero, out error); + handle = avahi_client_new (poll, flags, cb, IntPtr.Zero, out error); if (error != 0) throw new ClientException (error); @@ -225,6 +239,9 @@ namespace Avahi thread.Start (); } + public Client () : this (ClientFlags.None) { + } + ~Client () { Dispose (); @@ -232,19 +249,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 +283,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); }