Minor reconnect bugfix, removed unused variables

This commit is contained in:
RogueException
2016-07-29 21:40:40 -03:00
parent 7a36da2b58
commit 4088ec7fa3
3 changed files with 9 additions and 10 deletions

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);

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(); }

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);
}