Fix wrong QoS level handling for server.

This commit is contained in:
Christian Kratky
2017-08-07 20:28:49 +02:00
parent 0172606747
commit 59b0b79a32
15 changed files with 31 additions and 32 deletions
+1 -1
View File
@@ -267,7 +267,7 @@ namespace MQTTnet.Core.Client
return SendAsync(new MqttPubRecPacket { PacketIdentifier = publishPacket.PacketIdentifier });
}
throw new InvalidOperationException();
throw new MqttCommunicationException("Received a not supported QoS level.");
}
private async Task ProcessReceivedPubRelPacket(MqttPubRelPacket pubRelPacket)
+2 -2
View File
@@ -16,8 +16,8 @@
<PackageIconUrl></PackageIconUrl>
<RepositoryUrl></RepositoryUrl>
<PackageTags></PackageTags>
<FileVersion>2.1.4.0</FileVersion>
<AssemblyVersion>2.1.4.0</AssemblyVersion>
<FileVersion>2.1.5.1</FileVersion>
<AssemblyVersion>2.1.5.1</AssemblyVersion>
<PackageLicenseUrl></PackageLicenseUrl>
</PropertyGroup>
@@ -9,8 +9,10 @@ using MQTTnet.Core.Protocol;
namespace MQTTnet.Core.Serializer
{
public sealed class DefaultMqttV311PacketSerializer : IMqttPacketSerializer
public sealed class MqttV311PacketSerializer : IMqttPacketSerializer
{
private static readonly byte[] MqttV311Prefix = Encoding.UTF8.GetBytes("MQTT");
public Task SerializeAsync(MqttBasePacket packet, IMqttCommunicationChannel destination)
{
if (packet == null) throw new ArgumentNullException(nameof(packet));
@@ -351,8 +353,6 @@ namespace MQTTnet.Core.Serializer
}
}
private static readonly byte[] MqttPrefix = Encoding.UTF8.GetBytes("MQTT");
private static Task SerializeAsync(MqttConnectPacket packet, IMqttCommunicationChannel destination)
{
ValidateConnectPacket(packet);
@@ -361,7 +361,7 @@ namespace MQTTnet.Core.Serializer
{
// Write variable header
output.Write(0x00, 0x04); // 3.1.2.1 Protocol Name
output.Write(MqttPrefix);
output.Write(MqttV311Prefix);
output.Write(0x04); // 3.1.2.2 Protocol Level
var connectFlags = new ByteWriter(); // 3.1.2.3 Connect Flags
+6 -3
View File
@@ -153,13 +153,16 @@ namespace MQTTnet.Core.Server
if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.AtMostOnce)
{
_publishPacketReceivedCallback(this, publishPacket);
return Task.FromResult(0);
}
else if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.AtLeastOnce)
if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.AtLeastOnce)
{
_publishPacketReceivedCallback(this, publishPacket);
return _adapter.SendPacketAsync(new MqttPubAckPacket { PacketIdentifier = publishPacket.PacketIdentifier }, _options.DefaultCommunicationTimeout);
}
else if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.ExactlyOnce)
if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.ExactlyOnce)
{
// QoS 2 is implement as method "B" [4.3.3 QoS 2: Exactly once delivery]
lock (_unacknowledgedPublishPackets)
@@ -172,7 +175,7 @@ namespace MQTTnet.Core.Server
return _adapter.SendPacketAsync(new MqttPubRecPacket { PacketIdentifier = publishPacket.PacketIdentifier }, _options.DefaultCommunicationTimeout);
}
throw new MqttCommunicationException("Received not supported QoS level.");
throw new MqttCommunicationException("Received a not supported QoS level.");
}
private Task HandleIncomingPubRelPacketAsync(MqttPubRelPacket pubRelPacket)