Browse Source

Minor reconnect bugfix, removed unused variables

tags/1.0-rc
RogueException 8 years ago
parent
commit
4088ec7fa3
3 changed files with 9 additions and 10 deletions
  1. +5
    -5
      src/Discord.Net/API/DiscordRpcAPIClient.cs
  2. +2
    -4
      src/Discord.Net/Rpc/DiscordRpcClient.cs
  3. +2
    -1
      src/Discord.Net/WebSocket/DiscordSocketClient.cs

+ 5
- 5
src/Discord.Net/API/DiscordRpcAPIClient.cs View File

@@ -61,7 +61,7 @@ namespace Discord.API
private readonly IWebSocketClient _webSocketClient;
private readonly SemaphoreSlim _connectionLock;
private readonly string _clientId;
private CancellationTokenSource _loginCancelToken, _connectCancelToken;
private CancellationTokenSource _stateCancelToken;
private string _origin;

public ConnectionState ConnectionState { get; private set; }
@@ -120,7 +120,7 @@ namespace Discord.API
{
if (disposing)
{
_connectCancelToken?.Dispose();
_stateCancelToken?.Dispose();
(_webSocketClient as IDisposable)?.Dispose();
}
_isDisposed = true;
@@ -144,9 +144,9 @@ namespace Discord.API
ConnectionState = ConnectionState.Connecting;
try
{
_connectCancelToken = new CancellationTokenSource();
_stateCancelToken = new CancellationTokenSource();
if (_webSocketClient != null)
_webSocketClient.SetCancelToken(_connectCancelToken.Token);
_webSocketClient.SetCancelToken(_stateCancelToken.Token);

bool success = false;
int port;
@@ -196,7 +196,7 @@ namespace Discord.API
if (ConnectionState == ConnectionState.Disconnected) return;
ConnectionState = ConnectionState.Disconnecting;
try { _connectCancelToken?.Cancel(false); }
try { _stateCancelToken?.Cancel(false); }
catch { }

await _webSocketClient.DisconnectAsync().ConfigureAwait(false);


+ 2
- 4
src/Discord.Net/Rpc/DiscordRpcClient.cs View File

@@ -20,7 +20,6 @@ namespace Discord.Rpc
private TaskCompletionSource<bool> _connectTask;
private CancellationTokenSource _cancelToken, _reconnectCancelToken;
private Task _reconnectTask;
private bool _isReconnecting;
private bool _canReconnect;

public ConnectionState ConnectionState { get; private set; }
@@ -76,7 +75,6 @@ namespace Discord.Rpc
await _connectionLock.WaitAsync().ConfigureAwait(false);
try
{
_isReconnecting = false;
await ConnectInternalAsync(ignoreLoginCheck, false).ConfigureAwait(false);
}
finally { _connectionLock.Release(); }
@@ -103,7 +101,8 @@ namespace Discord.Rpc
await _connectedEvent.InvokeAsync().ConfigureAwait(false);

await _connectTask.Task.ConfigureAwait(false);
_canReconnect = true;
if (!isReconnecting)
_canReconnect = true;
ConnectionState = ConnectionState.Connected;
await _rpcLogger.InfoAsync("Connected").ConfigureAwait(false);
}
@@ -119,7 +118,6 @@ namespace Discord.Rpc
await _connectionLock.WaitAsync().ConfigureAwait(false);
try
{
_isReconnecting = false;
await DisconnectInternalAsync(null, false).ConfigureAwait(false);
}
finally { _connectionLock.Release(); }


+ 2
- 1
src/Discord.Net/WebSocket/DiscordSocketClient.cs View File

@@ -169,7 +169,8 @@ namespace Discord.WebSocket
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards:TotalShards).ConfigureAwait(false);

await _connectTask.Task.ConfigureAwait(false);
_canReconnect = true;
if (!isReconnecting)
_canReconnect = true;
ConnectionState = ConnectionState.Connected;
await _gatewayLogger.InfoAsync("Connected").ConfigureAwait(false);
}


Loading…
Cancel
Save