1546 possible bug in server repeatedly sending the same message to client subscribed with cleansession=false (#1569)

This commit is contained in:
Christian
2022-11-11 08:14:15 +01:00
committed by GitHub
parent bfec9dc5ad
commit db1fc7625d
18 changed files with 475 additions and 172 deletions
+22 -26
View File
@@ -10,40 +10,36 @@ namespace MQTTnet.Internal
{
public sealed class MqttPacketBusItem
{
readonly AsyncTaskCompletionSource<int> _promise = new AsyncTaskCompletionSource<int>();
readonly AsyncTaskCompletionSource<bool> _promise = new AsyncTaskCompletionSource<bool>();
public MqttPacketBusItem(MqttPacket packet)
{
Packet = packet ?? throw new ArgumentNullException(nameof(packet));
}
public event EventHandler Completed;
public MqttPacket Packet { get; }
public event EventHandler Delivered;
public Task WaitForDeliveryAsync()
{
return _promise.Task;
}
public void MarkAsDelivered()
{
if (_promise.TrySetResult(0))
{
Delivered?.Invoke(this, EventArgs.Empty);
}
}
public void MarkAsFailed(Exception exception)
{
if (exception == null) throw new ArgumentNullException(nameof(exception));
_promise.TrySetException(exception);
}
public void MarkAsCancelled()
public void Cancel()
{
_promise.TrySetCanceled();
}
public void Complete()
{
_promise.TrySetResult(true);
Completed?.Invoke(this, EventArgs.Empty);
}
public void Fail(Exception exception)
{
_promise.TrySetException(exception);
}
public Task WaitAsync()
{
return _promise.Task;
}
}
}