private void KeepAlive(double pingInterval, double pingTimeout, PingTimeoutAction timeoutCallback) { if (pingInterval <= 0) { return; } if (pingTimeout <= 0) { throw new ArgumentException("pingTimeout <= 0"); } this.pingWatchTimer = new System.Timers.Timer(pingTimeout); this.pingWatchTimer.Elapsed += (sender, e) => { if (timeoutCallback != null && timeoutCallback()) { this.pingWatchTimer.Stop(); this.keepAliveTimer.Start(); } else { this.Close(); } }; this.pingWatchTimer.Stop(); this.keepAliveTimer = new System.Timers.Timer(pingInterval); this.keepAliveTimer.Elapsed += (sender, e) => { this.keepAliveTimer.Stop(); this.pingWatchTimer.Start(); Ping(); }; this.keepAliveTimer.Start(); }
public EndPoint(Stream s, double pingInterval, double pingTimeout, PingTimeoutAction timeoutCallback) { this.s = s; this.headBuf = new byte[8]; this.waitAccept = new Queue <Conn> (); this.dialWait = new Dictionary <uint, List <Conn> > (); this.connections = new Dictionary <uint, Conn> (); this.ReadHead(); this.KeepAlive(pingInterval, pingTimeout, timeoutCallback); }