public Task Stop() { // check current status if (_status != ProxyServerStatus.Running) { throw new InvalidOperationException("Current status can't be stop."); } // update status _status = ProxyServerStatus.Closing; // stop listener _tcpListener.Stop(); // clear listener _tcpListener = null; // wait listen loop stop _listenLoop.Wait(); // disconnect all session then clear sessions collection return(Task.WhenAll(_sessions.Values.Select(x => x.Disconnect()).ToArray()) .ContinueWith((task) => { _sessions.Clear(); // update status _status = ProxyServerStatus.Shutdown; })); }
public static bool IsBad(this ProxyServerStatus status) { switch (status) { case ProxyServerStatus.ActiveUpGoingDown: case ProxyServerStatus.BackupUpGoingDown: case ProxyServerStatus.Down: return(true); default: return(false); } }
public static string ShortDescription(this ProxyServerStatus status) { switch (status) { case ProxyServerStatus.ActiveUp: return("Active"); case ProxyServerStatus.ActiveUpGoingDown: return("Active (Up -> Down)"); case ProxyServerStatus.ActiveDownGoingUp: return("Active (Down -> Up)"); case ProxyServerStatus.BackupUp: return("Backup"); case ProxyServerStatus.BackupUpGoingDown: return("Backup (Up -> Down)"); case ProxyServerStatus.BackupDownGoingUp: return("Backup (Down -> Up)"); case ProxyServerStatus.NotChecked: return("Not Checked"); case ProxyServerStatus.Down: return("Down"); case ProxyServerStatus.Maintenance: return("Maintenance"); case ProxyServerStatus.Open: return("Open"); //case ProxyServerStatus.None: default: return("Unknown"); } }
private Task StartListenLoop(TaskCompletionSource <bool> tsc) { // update status _status = ProxyServerStatus.Booting; // create new listener _tcpListener = new TcpListener(new IPEndPoint(IPAddress.Any, _listenPort)); // start listener. When initial listen port is 0, will use unused port _tcpListener.Start(); // update current port _listenPort = ((IPEndPoint)_tcpListener.LocalEndpoint).Port; // set result for TSC, `await Start` will continue run tsc.SetResult(true); // update status _status = ProxyServerStatus.Running; return(ListenLoop()); }
public static string ShortDescription(this ProxyServerStatus status) => status switch {