mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-19 19:13:11 +08:00
Use latest language features (#2176)
* Make use of language features line AsyncDispose, init etc. * Fix build errors * Improve Unit Tests * Improve Unit Tests * Improve Unit Tests * Update samples * Remove obsolete benchmarks * Code cleanup * Improve unit tests * Improve Unit Tests * Fix Unit Tests * Improve Unit Tests * Improve Unit Tests * Restore unit tests * Exclude load tests from unit tests
This commit is contained in:
@@ -18,11 +18,11 @@ namespace MQTTnet.AspNetCore;
|
||||
public sealed class SocketConnection : ConnectionContext
|
||||
{
|
||||
readonly EndPoint _endPoint;
|
||||
|
||||
volatile bool _aborted;
|
||||
IDuplexPipe _application;
|
||||
SocketReceiver _receiver;
|
||||
SocketSender _sender;
|
||||
|
||||
Socket _socket;
|
||||
|
||||
public SocketConnection(EndPoint endPoint)
|
||||
@@ -40,10 +40,13 @@ public sealed class SocketConnection : ConnectionContext
|
||||
}
|
||||
|
||||
public override string ConnectionId { get; set; }
|
||||
|
||||
public override IFeatureCollection Features { get; }
|
||||
|
||||
public bool IsConnected { get; private set; }
|
||||
|
||||
public override IDictionary<object, object> Items { get; set; }
|
||||
|
||||
public override IDuplexPipe Transport { get; set; }
|
||||
|
||||
public override ValueTask DisposeAsync()
|
||||
@@ -78,7 +81,7 @@ public sealed class SocketConnection : ConnectionContext
|
||||
IsConnected = true;
|
||||
}
|
||||
|
||||
Exception ConnectionAborted()
|
||||
static Exception ConnectionAborted()
|
||||
{
|
||||
return new MqttCommunicationException("Connection Aborted");
|
||||
}
|
||||
@@ -95,8 +98,7 @@ public sealed class SocketConnection : ConnectionContext
|
||||
{
|
||||
error = new MqttCommunicationException(ex);
|
||||
}
|
||||
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted || ex.SocketErrorCode == SocketError.ConnectionAborted ||
|
||||
ex.SocketErrorCode == SocketError.Interrupted || ex.SocketErrorCode == SocketError.InvalidArgument)
|
||||
catch (SocketException ex) when (ex.SocketErrorCode is SocketError.OperationAborted or SocketError.ConnectionAborted or SocketError.Interrupted or SocketError.InvalidArgument)
|
||||
{
|
||||
if (!_aborted)
|
||||
{
|
||||
@@ -123,10 +125,10 @@ public sealed class SocketConnection : ConnectionContext
|
||||
{
|
||||
if (_aborted)
|
||||
{
|
||||
error = error ?? ConnectionAborted();
|
||||
error ??= ConnectionAborted();
|
||||
}
|
||||
|
||||
_application.Output.Complete(error);
|
||||
await _application.Output.CompleteAsync(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user