fix negative download limit maybe

This commit is contained in:
rootdarkarchon
2024-02-10 00:28:03 +01:00
committed by Loporrit
parent a15348b293
commit 782d6001a4

View File

@@ -34,7 +34,7 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
_httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("MareSynchronos", ver!.Major + "." + ver!.Minor + "." + ver!.Build)); _httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("MareSynchronos", ver!.Major + "." + ver!.Minor + "." + ver!.Build));
_availableDownloadSlots = mareConfig.Current.ParallelDownloads; _availableDownloadSlots = mareConfig.Current.ParallelDownloads;
_downloadSemaphore = new(_availableDownloadSlots); _downloadSemaphore = new(_availableDownloadSlots, _availableDownloadSlots);
Mediator.Subscribe<ConnectedMessage>(this, (msg) => Mediator.Subscribe<ConnectedMessage>(this, (msg) =>
{ {
@@ -72,8 +72,15 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
public void ReleaseDownloadSlot() public void ReleaseDownloadSlot()
{ {
_downloadSemaphore.Release(); try
Mediator.Publish(new DownloadLimitChangedMessage()); {
_downloadSemaphore.Release();
Mediator.Publish(new DownloadLimitChangedMessage());
}
catch (SemaphoreFullException)
{
// ignore
}
} }
public async Task<HttpResponseMessage> SendRequestAsync(HttpMethod method, Uri uri, public async Task<HttpResponseMessage> SendRequestAsync(HttpMethod method, Uri uri,
@@ -107,7 +114,7 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
if (_availableDownloadSlots != _mareConfig.Current.ParallelDownloads && _availableDownloadSlots == _downloadSemaphore.CurrentCount) if (_availableDownloadSlots != _mareConfig.Current.ParallelDownloads && _availableDownloadSlots == _downloadSemaphore.CurrentCount)
{ {
_availableDownloadSlots = _mareConfig.Current.ParallelDownloads; _availableDownloadSlots = _mareConfig.Current.ParallelDownloads;
_downloadSemaphore = new(_availableDownloadSlots); _downloadSemaphore = new(_availableDownloadSlots, _availableDownloadSlots);
} }
} }