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]
Local = 8,
OurOwn = 16,
}
+
+ [Flags]
+ public enum ClientFlags {
+ None = 0,
+ IgnoreUserConfig = 1,
+ NoFail = 2
+ }
public class Client : IDisposable
{
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")]
}
}
- public Client ()
+ public Client (ClientFlags flags)
{
spoll = avahi_simple_poll_new ();
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);
thread.Start ();
}
+ public Client () : this (ClientFlags.None) {
+ }
+
~Client ()
{
Dispose ();
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;
lock (this) {
avahi_simple_poll_loop (spoll);
}
- } catch (ThreadAbortException e) {
} catch (Exception e) {
Console.Error.WriteLine ("Error in avahi-sharp event loop: " + e);
}