Let steamkit handle connect timeouts

Ref: #546
pull/554/head
Pavel Djundik 1 year ago
parent 9f64bd0439
commit 177c44ef4a

@ -44,7 +44,6 @@ namespace DepotDownloader
readonly CallbackManager callbacks; readonly CallbackManager callbacks;
readonly bool authenticatedUser; readonly bool authenticatedUser;
bool bConnected;
bool bConnecting; bool bConnecting;
bool bAborted; bool bAborted;
bool bExpectingDisconnectRemote; bool bExpectingDisconnectRemote;
@ -52,15 +51,11 @@ namespace DepotDownloader
bool bIsConnectionRecovery; bool bIsConnectionRecovery;
int connectionBackoff; int connectionBackoff;
int seq; // more hack fixes int seq; // more hack fixes
DateTime connectTime;
AuthSession authSession; AuthSession authSession;
// input // input
readonly SteamUser.LogOnDetails logonDetails; readonly SteamUser.LogOnDetails logonDetails;
static readonly TimeSpan STEAM3_TIMEOUT = TimeSpan.FromSeconds(30);
public Steam3Session(SteamUser.LogOnDetails details) public Steam3Session(SteamUser.LogOnDetails details)
{ {
this.logonDetails = details; this.logonDetails = details;
@ -109,7 +104,7 @@ namespace DepotDownloader
{ {
lock (steamLock) lock (steamLock)
{ {
WaitForCallbacks(); callbacks.RunWaitCallbacks(TimeSpan.FromSeconds(1));
} }
} while (!bAborted && this.seq == seq && !waiter()); } while (!bAborted && this.seq == seq && !waiter());
} }
@ -328,14 +323,11 @@ namespace DepotDownloader
void Connect() void Connect()
{ {
bAborted = false; bAborted = false;
bConnected = false;
bConnecting = true; bConnecting = true;
connectionBackoff = 0; connectionBackoff = 0;
authSession = null; authSession = null;
ResetConnectionFlags(); ResetConnectionFlags();
this.connectTime = DateTime.Now;
this.steamClient.Connect(); this.steamClient.Connect();
} }
@ -352,7 +344,6 @@ namespace DepotDownloader
} }
bAborted = true; bAborted = true;
bConnected = false;
bConnecting = false; bConnecting = false;
bIsConnectionRecovery = false; bIsConnectionRecovery = false;
steamClient.Disconnect(); steamClient.Disconnect();
@ -372,28 +363,13 @@ namespace DepotDownloader
steamClient.Disconnect(); steamClient.Disconnect();
} }
private void WaitForCallbacks()
{
callbacks.RunWaitCallbacks(TimeSpan.FromSeconds(1));
var diff = DateTime.Now - connectTime;
if (diff > STEAM3_TIMEOUT && !bConnected)
{
Console.WriteLine("Timeout connecting to Steam3.");
Abort();
}
}
private async void ConnectedCallback(SteamClient.ConnectedCallback connected) private async void ConnectedCallback(SteamClient.ConnectedCallback connected)
{ {
Console.WriteLine(" Done!"); Console.WriteLine(" Done!");
bConnecting = false; bConnecting = false;
bConnected = true;
// Update our tracking so that we don't time out, even if we need to reconnect multiple times, // Update our tracking so that we don't time out, even if we need to reconnect multiple times,
// e.g. if the authentication phase takes a while and therefore multiple connections. // e.g. if the authentication phase takes a while and therefore multiple connections.
connectTime = DateTime.Now;
connectionBackoff = 0; connectionBackoff = 0;
if (!authenticatedUser) if (!authenticatedUser)
@ -534,16 +510,18 @@ namespace DepotDownloader
} }
else if (!bAborted) else if (!bAborted)
{ {
connectionBackoff += 1;
if (bConnecting) if (bConnecting)
{ {
Console.WriteLine("Connection to Steam failed. Trying again"); Console.WriteLine($"Connection to Steam failed. Trying again (#{connectionBackoff})...");
} }
else else
{ {
Console.WriteLine("Lost connection to Steam. Reconnecting"); Console.WriteLine("Lost connection to Steam. Reconnecting");
} }
Thread.Sleep(1000 * ++connectionBackoff); Thread.Sleep(1000 * connectionBackoff);
// Any connection related flags need to be reset here to match the state after Connect // Any connection related flags need to be reset here to match the state after Connect
ResetConnectionFlags(); ResetConnectionFlags();

Loading…
Cancel
Save