namespace Unosquare.Swan
{
using System;
using System.Net;
using System.Net.Sockets;
///
/// 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)
{
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 bool 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)
{
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)
{
EndPoint = listenerEndPoint ?? throw new ArgumentNullException(nameof(listenerEndPoint));
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)
{
EndPoint = listenerEndPoint ?? throw new ArgumentNullException(nameof(listenerEndPoint));
Error = ex;
}
///
/// Gets the end point.
///
///
/// The end point.
///
public IPEndPoint EndPoint { get; }
///
/// Gets the error.
///
///
/// The error.
///
public Exception Error { get; }
}
}