Refactor channel adapter.

This commit is contained in:
Christian Kratky
2018-06-06 22:08:46 +02:00
parent 840d8ab4fd
commit 841a22b2b2
@@ -177,34 +177,17 @@ namespace MQTTnet.Adapter
{ {
await action().ConfigureAwait(false); await action().ConfigureAwait(false);
} }
catch (TaskCanceledException) catch (Exception exception)
{ {
throw; if (exception is TaskCanceledException ||
} exception is OperationCanceledException ||
catch (OperationCanceledException) exception is MqttCommunicationTimedOutException ||
{ exception is MqttCommunicationException)
throw;
}
catch (MqttCommunicationTimedOutException)
{
throw;
}
catch (MqttCommunicationException)
{
throw;
}
catch (COMException comException)
{
if ((uint)comException.HResult == ErrorOperationAborted)
{ {
throw new OperationCanceledException(); throw;
} }
throw new MqttCommunicationException(comException); if (exception is IOException && exception.InnerException is SocketException socketException)
}
catch (IOException exception)
{
if (exception.InnerException is SocketException socketException)
{ {
if (socketException.SocketErrorCode == SocketError.ConnectionAborted) if (socketException.SocketErrorCode == SocketError.ConnectionAborted)
{ {
@@ -212,10 +195,14 @@ namespace MQTTnet.Adapter
} }
} }
throw new MqttCommunicationException(exception); if (exception is COMException comException)
} {
catch (Exception exception) if ((uint)comException.HResult == ErrorOperationAborted)
{ {
throw new OperationCanceledException();
}
}
throw new MqttCommunicationException(exception); throw new MqttCommunicationException(exception);
} }
} }