mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-18 10:26:11 +08:00
Fix UnitTests.
This commit is contained in:
@@ -114,11 +114,11 @@ namespace MQTTnet.Adapter
|
||||
var packetData = PacketFormatterAdapter.Encode(packet);
|
||||
_packetInspectorHandler.BeginSendPacket(packetData);
|
||||
|
||||
_logger.Verbose("TX ({0} bytes) >>> {1}", packetData.Length, packet);
|
||||
|
||||
await packetData.WriteToAsync(_channel, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
Interlocked.Add(ref _bytesReceived, packetData.Length);
|
||||
|
||||
_logger.Verbose("TX ({0} bytes) >>> {1}", packetData.Length, packet);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace MQTTnet.Implementations
|
||||
public MqttTcpChannel(IMqttClientOptions clientOptions)
|
||||
{
|
||||
_clientOptions = clientOptions ?? throw new ArgumentNullException(nameof(clientOptions));
|
||||
_tcpOptions = (MqttClientTcpOptions)clientOptions.ChannelOptions;
|
||||
_tcpOptions = (MqttClientTcpOptions) clientOptions.ChannelOptions;
|
||||
|
||||
IsSecureConnection = clientOptions.ChannelOptions?.TlsOptions?.UseTls == true;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace MQTTnet.Implementations
|
||||
|
||||
socket.ReceiveBufferSize = _tcpOptions.BufferSize;
|
||||
socket.SendBufferSize = _tcpOptions.BufferSize;
|
||||
socket.SendTimeout = (int)_clientOptions.CommunicationTimeout.TotalMilliseconds;
|
||||
socket.SendTimeout = (int) _clientOptions.CommunicationTimeout.TotalMilliseconds;
|
||||
socket.NoDelay = _tcpOptions.NoDelay;
|
||||
|
||||
if (_tcpOptions.DualMode.HasValue)
|
||||
@@ -95,7 +95,8 @@ namespace MQTTnet.Implementations
|
||||
|
||||
await sslStream.AuthenticateAsClientAsync(sslOptions, cancellationToken).ConfigureAwait(false);
|
||||
#else
|
||||
await sslStream.AuthenticateAsClientAsync(_tcpOptions.Server, LoadCertificates(), _tcpOptions.TlsOptions.SslProtocol, !_tcpOptions.TlsOptions.IgnoreCertificateRevocationErrors).ConfigureAwait(false);
|
||||
await sslStream.AuthenticateAsClientAsync(_tcpOptions.Server, LoadCertificates(), _tcpOptions.TlsOptions.SslProtocol,
|
||||
!_tcpOptions.TlsOptions.IgnoreCertificateRevocationErrors).ConfigureAwait(false);
|
||||
#endif
|
||||
}
|
||||
catch
|
||||
@@ -212,6 +213,9 @@ namespace MQTTnet.Implementations
|
||||
// https://stackoverflow.com/questions/3601521/should-i-manually-dispose-the-socket-after-closing-it
|
||||
try
|
||||
{
|
||||
#if !NETSTANDARD1_3
|
||||
_stream?.Close();
|
||||
#endif
|
||||
_stream?.Dispose();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
@@ -220,8 +224,10 @@ namespace MQTTnet.Implementations
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
}
|
||||
|
||||
_stream = null;
|
||||
finally
|
||||
{
|
||||
_stream = null;
|
||||
}
|
||||
}
|
||||
|
||||
bool InternalUserCertificateValidationCallback(object sender, X509Certificate x509Certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
@@ -235,6 +241,7 @@ namespace MQTTnet.Implementations
|
||||
{
|
||||
return certificateValidationCallback(x509Certificate, chain, sslPolicyErrors, _clientOptions);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
var certificateValidationHandler = _tcpOptions?.TlsOptions?.CertificateValidationHandler;
|
||||
@@ -256,7 +263,8 @@ namespace MQTTnet.Implementations
|
||||
return true;
|
||||
}
|
||||
|
||||
if (chain.ChainStatus.Any(c => c.Status == X509ChainStatusFlags.RevocationStatusUnknown || c.Status == X509ChainStatusFlags.Revoked || c.Status == X509ChainStatusFlags.OfflineRevocation))
|
||||
if (chain.ChainStatus.Any(c =>
|
||||
c.Status == X509ChainStatusFlags.RevocationStatusUnknown || c.Status == X509ChainStatusFlags.Revoked || c.Status == X509ChainStatusFlags.OfflineRevocation))
|
||||
{
|
||||
if (_tcpOptions?.TlsOptions?.IgnoreCertificateRevocationErrors != true)
|
||||
{
|
||||
@@ -292,4 +300,4 @@ namespace MQTTnet.Implementations
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -138,6 +138,8 @@ namespace MQTTnet.Server
|
||||
|
||||
_= _sessionsManager.DispatchPublishPacket(Id, willApplicationMessage);
|
||||
Session.WillMessageSent = true;
|
||||
|
||||
_logger.Info("Client '{0}': Published will message.", Id);
|
||||
}
|
||||
|
||||
_logger.Info("Client '{0}': Connection stopped.", Id);
|
||||
@@ -175,6 +177,11 @@ namespace MQTTnet.Server
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
var packet = await ChannelAdapter.ReceivePacketAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (packet == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var interceptingPacketEventArgs = new InterceptingPacketEventArgs
|
||||
{
|
||||
|
||||
@@ -518,15 +518,15 @@ namespace MQTTnet.Server
|
||||
|
||||
if (existingConnection != null)
|
||||
{
|
||||
existingConnection.IsTakenOver = true;
|
||||
await existingConnection.StopAsync(MqttClientDisconnectReason.SessionTakenOver).ConfigureAwait(false);
|
||||
|
||||
await _eventContainer.ClientDisconnectedEvent.InvokeAsync(() => new MqttServerClientDisconnectedEventArgs
|
||||
{
|
||||
ClientId = existingConnection.Id,
|
||||
DisconnectType = MqttClientDisconnectType.Takeover,
|
||||
Endpoint = existingConnection.Endpoint
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
existingConnection.IsTakenOver = true;
|
||||
await existingConnection.StopAsync(MqttClientDisconnectReason.SessionTakenOver).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user