| @@ -61,7 +61,7 @@ namespace Discord.API | |||||
| private readonly IWebSocketClient _webSocketClient; | private readonly IWebSocketClient _webSocketClient; | ||||
| private readonly SemaphoreSlim _connectionLock; | private readonly SemaphoreSlim _connectionLock; | ||||
| private readonly string _clientId; | private readonly string _clientId; | ||||
| private CancellationTokenSource _loginCancelToken, _connectCancelToken; | |||||
| private CancellationTokenSource _stateCancelToken; | |||||
| private string _origin; | private string _origin; | ||||
| public ConnectionState ConnectionState { get; private set; } | public ConnectionState ConnectionState { get; private set; } | ||||
| @@ -120,7 +120,7 @@ namespace Discord.API | |||||
| { | { | ||||
| if (disposing) | if (disposing) | ||||
| { | { | ||||
| _connectCancelToken?.Dispose(); | |||||
| _stateCancelToken?.Dispose(); | |||||
| (_webSocketClient as IDisposable)?.Dispose(); | (_webSocketClient as IDisposable)?.Dispose(); | ||||
| } | } | ||||
| _isDisposed = true; | _isDisposed = true; | ||||
| @@ -144,9 +144,9 @@ namespace Discord.API | |||||
| ConnectionState = ConnectionState.Connecting; | ConnectionState = ConnectionState.Connecting; | ||||
| try | try | ||||
| { | { | ||||
| _connectCancelToken = new CancellationTokenSource(); | |||||
| _stateCancelToken = new CancellationTokenSource(); | |||||
| if (_webSocketClient != null) | if (_webSocketClient != null) | ||||
| _webSocketClient.SetCancelToken(_connectCancelToken.Token); | |||||
| _webSocketClient.SetCancelToken(_stateCancelToken.Token); | |||||
| bool success = false; | bool success = false; | ||||
| int port; | int port; | ||||
| @@ -196,7 +196,7 @@ namespace Discord.API | |||||
| if (ConnectionState == ConnectionState.Disconnected) return; | if (ConnectionState == ConnectionState.Disconnected) return; | ||||
| ConnectionState = ConnectionState.Disconnecting; | ConnectionState = ConnectionState.Disconnecting; | ||||
| try { _connectCancelToken?.Cancel(false); } | |||||
| try { _stateCancelToken?.Cancel(false); } | |||||
| catch { } | catch { } | ||||
| await _webSocketClient.DisconnectAsync().ConfigureAwait(false); | await _webSocketClient.DisconnectAsync().ConfigureAwait(false); | ||||
| @@ -20,7 +20,6 @@ namespace Discord.Rpc | |||||
| private TaskCompletionSource<bool> _connectTask; | private TaskCompletionSource<bool> _connectTask; | ||||
| private CancellationTokenSource _cancelToken, _reconnectCancelToken; | private CancellationTokenSource _cancelToken, _reconnectCancelToken; | ||||
| private Task _reconnectTask; | private Task _reconnectTask; | ||||
| private bool _isReconnecting; | |||||
| private bool _canReconnect; | private bool _canReconnect; | ||||
| public ConnectionState ConnectionState { get; private set; } | public ConnectionState ConnectionState { get; private set; } | ||||
| @@ -76,7 +75,6 @@ namespace Discord.Rpc | |||||
| await _connectionLock.WaitAsync().ConfigureAwait(false); | await _connectionLock.WaitAsync().ConfigureAwait(false); | ||||
| try | try | ||||
| { | { | ||||
| _isReconnecting = false; | |||||
| await ConnectInternalAsync(ignoreLoginCheck, false).ConfigureAwait(false); | await ConnectInternalAsync(ignoreLoginCheck, false).ConfigureAwait(false); | ||||
| } | } | ||||
| finally { _connectionLock.Release(); } | finally { _connectionLock.Release(); } | ||||
| @@ -103,7 +101,8 @@ namespace Discord.Rpc | |||||
| await _connectedEvent.InvokeAsync().ConfigureAwait(false); | await _connectedEvent.InvokeAsync().ConfigureAwait(false); | ||||
| await _connectTask.Task.ConfigureAwait(false); | await _connectTask.Task.ConfigureAwait(false); | ||||
| _canReconnect = true; | |||||
| if (!isReconnecting) | |||||
| _canReconnect = true; | |||||
| ConnectionState = ConnectionState.Connected; | ConnectionState = ConnectionState.Connected; | ||||
| await _rpcLogger.InfoAsync("Connected").ConfigureAwait(false); | await _rpcLogger.InfoAsync("Connected").ConfigureAwait(false); | ||||
| } | } | ||||
| @@ -119,7 +118,6 @@ namespace Discord.Rpc | |||||
| await _connectionLock.WaitAsync().ConfigureAwait(false); | await _connectionLock.WaitAsync().ConfigureAwait(false); | ||||
| try | try | ||||
| { | { | ||||
| _isReconnecting = false; | |||||
| await DisconnectInternalAsync(null, false).ConfigureAwait(false); | await DisconnectInternalAsync(null, false).ConfigureAwait(false); | ||||
| } | } | ||||
| finally { _connectionLock.Release(); } | finally { _connectionLock.Release(); } | ||||
| @@ -169,7 +169,8 @@ namespace Discord.WebSocket | |||||
| await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards:TotalShards).ConfigureAwait(false); | await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards:TotalShards).ConfigureAwait(false); | ||||
| await _connectTask.Task.ConfigureAwait(false); | await _connectTask.Task.ConfigureAwait(false); | ||||
| _canReconnect = true; | |||||
| if (!isReconnecting) | |||||
| _canReconnect = true; | |||||
| ConnectionState = ConnectionState.Connected; | ConnectionState = ConnectionState.Connected; | ||||
| await _gatewayLogger.InfoAsync("Connected").ConfigureAwait(false); | await _gatewayLogger.InfoAsync("Connected").ConfigureAwait(false); | ||||
| } | } | ||||