internal void OnHeartbeat(long timeout) { if (this.PingTimeoutTimer != null) { PingTimeoutTimer.Stop(); PingTimeoutTimer = null; } if (timeout <= 0) { timeout = this.PingInterval + this.PingTimeout; } PingTimeoutTimer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("EasyTimer OnHeartbeat start"); if (ReadyState == ReadyStateEnum.CLOSED) { log2.Info("EasyTimer OnHeartbeat ReadyState == ReadyStateEnum.CLOSED finish"); return; } OnClose("ping timeout"); log2.Info("EasyTimer OnHeartbeat finish"); }, (int)timeout); }
private void SetPing() { //var log = LogManager.GetLogger(Global.CallerName()); if (this.PingIntervalTimer != null) { PingIntervalTimer.Stop(); } var log = LogManager.GetLogger(Global.CallerName()); log.Info(string.Format("writing ping packet - expecting pong within {0}ms", PingTimeout)); PingIntervalTimer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("EasyTimer SetPing start"); if (Upgrading) { // skip this ping during upgrade SetPing(); log2.Info("skipping Ping during upgrade"); } else { Ping(); OnHeartbeat(PingTimeout); log2.Info("EasyTimer SetPing finish"); } }, (int)PingInterval); }
internal void OnHeartbeat(long timeout) { if (_pingTimeoutTimer != null) { _pingTimeoutTimer.Stop(); _pingTimeoutTimer = null; } if (timeout <= 0) { timeout = PingInterval + PingTimeout; } _pingTimeoutTimer = EasyTimer.SetTimeout(() => { Logger.Log("EasyTimer OnHeartbeat start"); if (ReadyState == ReadyStateEnum.CLOSED) { Logger.Log("EasyTimer OnHeartbeat ReadyState == ReadyStateEnum.CLOSED finish"); return; } OnClose("ping timeout"); Logger.Log("EasyTimer OnHeartbeat finish"); }, (int)timeout); }
internal void SetPing() { _pingIntervalTimer?.Stop(); Logger.Log($"writing ping packet - expecting pong within {PingTimeout}ms"); _pingIntervalTimer = EasyTimer.SetTimeout(() => { Logger.Log("EasyTimer SetPing start"); if (Upgrading) { // skip this ping during upgrade SetPing(); Logger.Log("skipping Ping during upgrade"); } else if (ReadyState == ReadyStateEnum.OPEN) { Ping(); OnHeartbeat(PingTimeout); Logger.Log("EasyTimer SetPing finish"); } }, (int)PingInterval); }
internal void OnClose(string reason, Exception desc = null) { if (ReadyState == ReadyStateEnum.OPENING || ReadyState == ReadyStateEnum.OPEN) { Logger.Log($"OnClose socket close with reason: {reason}"); // clear timers _pingIntervalTimer?.Stop(); _pingTimeoutTimer?.Stop(); //WriteBuffer = WriteBuffer.Clear(); //CallbackBuffer = CallbackBuffer.Clear(); //PrevBufferLen = 0; EasyTimer.SetTimeout(() => { WriteBuffer = ImmutableList <Packet> .Empty; CallbackBuffer = ImmutableList <Action> .Empty; PrevBufferLen = 0; }, 1); if (Transport != null) { // stop event from firing again for transport Transport.Off(EVENT_CLOSE); // ensure transport won't stay open Transport.Close(); // ignore further transport communication Transport.Off(); } // set ready state ReadyState = ReadyStateEnum.CLOSED; // clear session id Id = null; // emit close events Emit(EVENT_CLOSE, reason, desc); } }
private void SetPing() { var log = LogManager.GetLogger(Global.CallerName()); if (this.PingIntervalTimer != null) { log.Info("SetPing::Stopping the PingIntervalTimer."); PingIntervalTimer.Stop(); } log.Info(string.Format("writing ping packet - expecting pong within {0}ms", PingTimeout)); log.Info(string.Format("PingInterval is {0}ms", PingInterval)); PingIntervalTimer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("EasyTimer SetPing start"); Ping(); log2.Info("EasyTimer SetPing finish"); }, (int)PingInterval); }