Don't activate the canceltoken in websockets before the disconnectreason has been set.

This commit is contained in:
Brandon Smith
2015-09-04 19:07:05 -03:00
parent 7376769581
commit ce2a4dfa2b
3 changed files with 3 additions and 11 deletions

View File

@@ -42,7 +42,7 @@ namespace Discord
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {
throw _disconnectReason; throw _disconnectReason;// ?? new Exception("Operation was cancelled");
} }
try { _connectWaitOnLogin2.Wait(cancelToken); } //Waiting on READY handler try { _connectWaitOnLogin2.Wait(cancelToken); } //Waiting on READY handler
catch (OperationCanceledException) { return; } catch (OperationCanceledException) { return; }

View File

@@ -58,7 +58,7 @@ namespace Discord
protected override void OnConnect() protected override void OnConnect()
{ {
_udp = new UdpClient(new IPEndPoint(IPAddress.Any, 0)); _udp = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
#if !DNX451 #if !DNX451 && !MONO
_udp.AllowNatTraversal(true); _udp.AllowNatTraversal(true);
#endif #endif
_isReady = false; _isReady = false;
@@ -132,7 +132,6 @@ namespace Discord
catch (OperationCanceledException) { } catch (OperationCanceledException) { }
catch (ObjectDisposedException) { } catch (ObjectDisposedException) { }
catch (Exception ex) { DisconnectInternal(ex); } catch (Exception ex) { DisconnectInternal(ex); }
finally { DisconnectInternal(); }
} }
#if USE_THREAD #if USE_THREAD
@@ -213,7 +212,6 @@ namespace Discord
catch (OperationCanceledException) { } catch (OperationCanceledException) { }
catch (ObjectDisposedException) { } catch (ObjectDisposedException) { }
catch (Exception ex) { DisconnectInternal(ex); } catch (Exception ex) { DisconnectInternal(ex); }
finally { DisconnectInternal(); }
} }
#endif #endif
//Closes the UDP socket when _disconnectToken is triggered, since UDPClient doesn't allow passing a canceltoken //Closes the UDP socket when _disconnectToken is triggered, since UDPClient doesn't allow passing a canceltoken

View File

@@ -97,11 +97,7 @@ namespace Discord
try { await _task; } catch (NullReferenceException) { } try { await _task; } catch (NullReferenceException) { }
} }
} }
protected void DisconnectInternal()
{
_disconnectToken.Cancel();
}
protected void DisconnectInternal(Exception ex, bool isUnexpected = true) protected void DisconnectInternal(Exception ex, bool isUnexpected = true)
{ {
if (_disconnectReason == null) if (_disconnectReason == null)
@@ -186,7 +182,6 @@ namespace Discord
} }
catch (OperationCanceledException) { } catch (OperationCanceledException) { }
catch (Exception ex) { DisconnectInternal(ex); } catch (Exception ex) { DisconnectInternal(ex); }
finally { DisconnectInternal(); }
} }
private async Task SendAsync() private async Task SendAsync()
{ {
@@ -215,7 +210,6 @@ namespace Discord
} }
catch (OperationCanceledException) { } catch (OperationCanceledException) { }
catch (Exception ex) { DisconnectInternal(ex); } catch (Exception ex) { DisconnectInternal(ex); }
finally { DisconnectInternal(); }
} }
protected abstract Task ProcessMessage(string json); protected abstract Task ProcessMessage(string json);