Cancel work if CDNClientPool is exhausted and can't find more servers

pull/19/head
Ryan Kistner 8 years ago
parent 184ea54020
commit 65036ffa8d

@ -24,6 +24,7 @@ namespace DepotDownloader
private AutoResetEvent populatePoolEvent; private AutoResetEvent populatePoolEvent;
private Task monitorTask; private Task monitorTask;
public CancellationTokenSource ExhaustedToken { get; set; }
public CDNClientPool(Steam3Session steamSession) public CDNClientPool(Steam3Session steamSession)
{ {
@ -61,6 +62,8 @@ namespace DepotDownloader
private async Task ConnectionPoolMonitorAsync() private async Task ConnectionPoolMonitorAsync()
{ {
bool didPopulate = false;
while(true) while(true)
{ {
populatePoolEvent.WaitOne(TimeSpan.FromSeconds(1)); populatePoolEvent.WaitOne(TimeSpan.FromSeconds(1));
@ -86,6 +89,12 @@ namespace DepotDownloader
availableServerEndpoints.Add(endpoint.Item1); availableServerEndpoints.Add(endpoint.Item1);
} }
} }
didPopulate = true;
}
else if ( availableServerEndpoints.Count == 0 && !steamSession.steamClient.IsConnected && didPopulate )
{
ExhaustedToken?.Cancel();
} }
} }
} }

@ -545,6 +545,7 @@ namespace DepotDownloader
Console.WriteLine( "Downloading depot {0} - {1}", depot.id, depot.contentName ); Console.WriteLine( "Downloading depot {0} - {1}", depot.id, depot.contentName );
CancellationTokenSource cts = new CancellationTokenSource(); CancellationTokenSource cts = new CancellationTokenSource();
cdnPool.ExhaustedToken = cts;
ProtoManifest oldProtoManifest = null; ProtoManifest oldProtoManifest = null;
ProtoManifest newProtoManifest = null; ProtoManifest newProtoManifest = null;
@ -874,6 +875,7 @@ namespace DepotDownloader
if ( chunkData == null ) if ( chunkData == null )
{ {
Console.WriteLine( "Failed to find any server with chunk {0} for depot {1}. Aborting.", chunkID, depot.id ); Console.WriteLine( "Failed to find any server with chunk {0} for depot {1}. Aborting.", chunkID, depot.id );
cts.Cancel();
return; return;
} }

Loading…
Cancel
Save