From bab00cb022cc8d50e84e4e8bec40b92b7f60983a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 11 Jul 2025 17:47:30 -0500 Subject: reset on option changes --- src/slskd/Core/ConnectionWatchdog.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Core/ConnectionWatchdog.cs b/src/slskd/Core/ConnectionWatchdog.cs index f8461033..a598ff7a 100644 --- a/src/slskd/Core/ConnectionWatchdog.cs +++ b/src/slskd/Core/ConnectionWatchdog.cs @@ -48,7 +48,7 @@ namespace slskd IStateMonitor state) { Client = soulseekClient; - Options = optionsMonitor; + OptionsMonitor = optionsMonitor; State = state; WatchdogTimer = new System.Timers.Timer() @@ -59,6 +59,8 @@ namespace slskd }; WatchdogTimer.Elapsed += (sender, args) => _ = AttemptReconnect(); + + OptionsMonitor.OnChange(options => OptionsChanged(options)); } /// @@ -69,7 +71,7 @@ namespace slskd private ISoulseekClient Client { get; } private bool Disposed { get; set; } private ILogger Log { get; } = Serilog.Log.ForContext(); - private IOptionsMonitor Options { get; set; } + private IOptionsMonitor OptionsMonitor { get; set; } private IStateMonitor State { get; } private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1, 1); private System.Timers.Timer WatchdogTimer { get; } @@ -141,6 +143,17 @@ namespace slskd } } + private void OptionsChanged(Options options) + { + // it's possible that a user begins changing connection settings in an attempt to get the client to connect + // if they edit the options _at all_, assume this is the case and restart the retry loop from the beginning + if (IsEnabled) + { + Log.Information("Options changed, restarting (re)connection process..."); + Restart(); + } + } + private async Task AttemptReconnect(int attempts = 1) { // semaphore is obtained here and released only when the reconnect attempt is complete, so -- cgit v1.2.3