diff --git a/src/Discord.Net/DiscordDataSocket.cs b/src/Discord.Net/DiscordDataSocket.cs index 1dc31198d..822264cdd 100644 --- a/src/Discord.Net/DiscordDataSocket.cs +++ b/src/Discord.Net/DiscordDataSocket.cs @@ -42,7 +42,7 @@ namespace Discord } catch (OperationCanceledException) { - throw _disconnectReason; + throw _disconnectReason;// ?? new Exception("Operation was cancelled"); } try { _connectWaitOnLogin2.Wait(cancelToken); } //Waiting on READY handler catch (OperationCanceledException) { return; } diff --git a/src/Discord.Net/DiscordVoiceSocket.cs b/src/Discord.Net/DiscordVoiceSocket.cs index 15c275067..102e1dd3c 100644 --- a/src/Discord.Net/DiscordVoiceSocket.cs +++ b/src/Discord.Net/DiscordVoiceSocket.cs @@ -58,7 +58,7 @@ namespace Discord protected override void OnConnect() { _udp = new UdpClient(new IPEndPoint(IPAddress.Any, 0)); -#if !DNX451 +#if !DNX451 && !MONO _udp.AllowNatTraversal(true); #endif _isReady = false; @@ -132,7 +132,6 @@ namespace Discord catch (OperationCanceledException) { } catch (ObjectDisposedException) { } catch (Exception ex) { DisconnectInternal(ex); } - finally { DisconnectInternal(); } } #if USE_THREAD @@ -213,7 +212,6 @@ namespace Discord catch (OperationCanceledException) { } catch (ObjectDisposedException) { } catch (Exception ex) { DisconnectInternal(ex); } - finally { DisconnectInternal(); } } #endif //Closes the UDP socket when _disconnectToken is triggered, since UDPClient doesn't allow passing a canceltoken diff --git a/src/Discord.Net/DiscordWebSocket.cs b/src/Discord.Net/DiscordWebSocket.cs index e2c67d17b..2b5b3eacf 100644 --- a/src/Discord.Net/DiscordWebSocket.cs +++ b/src/Discord.Net/DiscordWebSocket.cs @@ -97,11 +97,7 @@ namespace Discord try { await _task; } catch (NullReferenceException) { } } } - - protected void DisconnectInternal() - { - _disconnectToken.Cancel(); - } + protected void DisconnectInternal(Exception ex, bool isUnexpected = true) { if (_disconnectReason == null) @@ -186,7 +182,6 @@ namespace Discord } catch (OperationCanceledException) { } catch (Exception ex) { DisconnectInternal(ex); } - finally { DisconnectInternal(); } } private async Task SendAsync() { @@ -215,7 +210,6 @@ namespace Discord } catch (OperationCanceledException) { } catch (Exception ex) { DisconnectInternal(ex); } - finally { DisconnectInternal(); } } protected abstract Task ProcessMessage(string json);