private TimerAwaitable StartKeepAliveTimer() { Log.StartingKeepAliveTimer(Logger, DefaultKeepAliveInterval); _lastReceiveTimestamp = Stopwatch.GetTimestamp(); _lastSendTimestamp = _lastReceiveTimestamp; var timer = new TimerAwaitable(DefaultKeepAliveInterval, DefaultKeepAliveInterval); _ = KeepAliveAsync(timer); return(timer); }
private async Task KeepAliveAsync(TimerAwaitable timer) { using (timer) { timer.Start(); while (await timer) { if (Stopwatch.GetTimestamp() - Interlocked.Read(ref _lastReceiveTimestamp) > DefaultServiceTimeoutTicks) { AbortConnection(); // We shouldn't get here twice. continue; } } } }
internal Server(ServerBuilder builder) { _logger = builder.ApplicationServices.GetLoggerFactory().CreateLogger <Server>(); _builder = builder; _timerAwaitable = new TimerAwaitable(_builder.HeartBeatInterval, _builder.HeartBeatInterval); }