mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-18 18:43:10 +08:00
fixed clients overlapping from one test to another by:
- adding client and server wrappers to verify the clientid starts with the testname - adding disposable baseclass - clear disconnect handler from client so it does not try to reconnect after it is disposed - moved code from dispose to cleanup in case it is called in a stop method as dispose may only be called once while start / stop may be called multiple times
This commit is contained in:
@@ -8,11 +8,12 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.Internal;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Implementations
|
||||
{
|
||||
public class MqttTcpServerAdapter : IMqttServerAdapter
|
||||
public class MqttTcpServerAdapter : Disposable, IMqttServerAdapter
|
||||
{
|
||||
private readonly List<MqttTcpServerListener> _listeners = new List<MqttTcpServerListener>();
|
||||
private readonly IMqttNetChildLogger _logger;
|
||||
@@ -72,11 +73,11 @@ namespace MQTTnet.Implementations
|
||||
|
||||
public Task StopAsync()
|
||||
{
|
||||
Dispose();
|
||||
Cleanup();
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
private void Cleanup()
|
||||
{
|
||||
_cancellationTokenSource?.Cancel(false);
|
||||
_cancellationTokenSource?.Dispose();
|
||||
@@ -90,6 +91,15 @@ namespace MQTTnet.Implementations
|
||||
_listeners.Clear();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Cleanup();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void RegisterListeners(MqttServerTcpEndpointBaseOptions options, X509Certificate2 tlsCertificate, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!options.BoundInterNetworkAddress.Equals(IPAddress.None))
|
||||
|
||||
@@ -6,10 +6,11 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Channel;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Internal;
|
||||
|
||||
namespace MQTTnet.Implementations
|
||||
{
|
||||
public class MqttWebSocketChannel : IMqttChannel
|
||||
public class MqttWebSocketChannel : Disposable, IMqttChannel
|
||||
{
|
||||
private readonly MqttClientWebSocketOptions _options;
|
||||
|
||||
@@ -141,22 +142,26 @@ namespace MQTTnet.Implementations
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_sendLock?.Dispose();
|
||||
_sendLock = null;
|
||||
if (disposing)
|
||||
{
|
||||
_sendLock?.Dispose();
|
||||
_sendLock = null;
|
||||
|
||||
try
|
||||
{
|
||||
_webSocket?.Dispose();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
_webSocket = null;
|
||||
try
|
||||
{
|
||||
_webSocket?.Dispose();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
_webSocket = null;
|
||||
}
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private IWebProxy CreateProxy()
|
||||
|
||||
Reference in New Issue
Block a user