using System; using System.Net; using System.Net.Sockets; namespace Unosquare.Swan { /// /// The event arguments for when connections are accepted. /// /// public class ConnectionAcceptedEventArgs : EventArgs { /// /// Initializes a new instance of the class. /// /// The client. /// client. public ConnectionAcceptedEventArgs(TcpClient client) => this.Client = client ?? throw new ArgumentNullException(nameof(client)); /// /// Gets the client. /// /// /// The client. /// public TcpClient Client { get; } } /// /// Occurs before a connection is accepted. Set the Cancel property to true to prevent the connection from being accepted. /// /// public class ConnectionAcceptingEventArgs : ConnectionAcceptedEventArgs { /// /// Initializes a new instance of the class. /// /// The client. public ConnectionAcceptingEventArgs(TcpClient client) : base(client) { } /// /// Setting Cancel to true rejects the new TcpClient. /// /// /// true if cancel; otherwise, false. /// public Boolean Cancel { get; set; } } /// /// Event arguments for when a server listener is started. /// /// public class ConnectionListenerStartedEventArgs : EventArgs { /// /// Initializes a new instance of the class. /// /// The listener end point. /// listenerEndPoint. public ConnectionListenerStartedEventArgs(IPEndPoint listenerEndPoint) => this.EndPoint = listenerEndPoint ?? throw new ArgumentNullException(nameof(listenerEndPoint)); /// /// Gets the end point. /// /// /// The end point. /// public IPEndPoint EndPoint { get; } } /// /// Event arguments for when a server listener fails to start. /// /// public class ConnectionListenerFailedEventArgs : EventArgs { /// /// Initializes a new instance of the class. /// /// The listener end point. /// The ex. /// /// listenerEndPoint /// or /// ex. /// public ConnectionListenerFailedEventArgs(IPEndPoint listenerEndPoint, Exception ex) { this.EndPoint = listenerEndPoint ?? throw new ArgumentNullException(nameof(listenerEndPoint)); this.Error = ex ?? throw new ArgumentNullException(nameof(ex)); } /// /// Gets the end point. /// /// /// The end point. /// public IPEndPoint EndPoint { get; } /// /// Gets the error. /// /// /// The error. /// public Exception Error { get; } } /// /// Event arguments for when a server listener stopped. /// /// public class ConnectionListenerStoppedEventArgs : EventArgs { /// /// Initializes a new instance of the class. /// /// The listener end point. /// The ex. /// /// listenerEndPoint /// or /// ex. /// public ConnectionListenerStoppedEventArgs(IPEndPoint listenerEndPoint, Exception ex = null) { this.EndPoint = listenerEndPoint ?? throw new ArgumentNullException(nameof(listenerEndPoint)); this.Error = ex; } /// /// Gets the end point. /// /// /// The end point. /// public IPEndPoint EndPoint { get; } /// /// Gets the error. /// /// /// The error. /// public Exception Error { get; } } }