Browse Source

Refactoring

release/3.x.x
Christian Kratky 7 years ago
parent
commit
40dd620f90
3 changed files with 12 additions and 3 deletions
  1. +5
    -1
      MQTTnet.Core/Adapter/MqttChannelCommunicationAdapter.cs
  2. +6
    -1
      MQTTnet.Core/Adapter/ReceivedMqttPacket.cs
  3. +1
    -1
      MQTTnet.Core/Serializer/MqttPacketWriter.cs

+ 5
- 1
MQTTnet.Core/Adapter/MqttChannelCommunicationAdapter.cs View File

@@ -139,9 +139,9 @@ namespace MQTTnet.Core.Adapter


public async Task<MqttBasePacket> ReceivePacketAsync(TimeSpan timeout, CancellationToken cancellationToken) public async Task<MqttBasePacket> ReceivePacketAsync(TimeSpan timeout, CancellationToken cancellationToken)
{ {
ReceivedMqttPacket receivedMqttPacket = null;
try try
{ {
ReceivedMqttPacket receivedMqttPacket;
if (timeout > TimeSpan.Zero) if (timeout > TimeSpan.Zero)
{ {
receivedMqttPacket = await ReceiveAsync(_channel.ReceiveStream, cancellationToken).TimeoutAfter(timeout).ConfigureAwait(false); receivedMqttPacket = await ReceiveAsync(_channel.ReceiveStream, cancellationToken).TimeoutAfter(timeout).ConfigureAwait(false);
@@ -185,6 +185,10 @@ namespace MQTTnet.Core.Adapter
{ {
throw new MqttCommunicationException(exception); throw new MqttCommunicationException(exception);
} }
finally
{
receivedMqttPacket?.Dispose();
}
} }


private static async Task<ReceivedMqttPacket> ReceiveAsync(Stream stream, CancellationToken cancellationToken) private static async Task<ReceivedMqttPacket> ReceiveAsync(Stream stream, CancellationToken cancellationToken)


+ 6
- 1
MQTTnet.Core/Adapter/ReceivedMqttPacket.cs View File

@@ -4,7 +4,7 @@ using MQTTnet.Core.Packets;


namespace MQTTnet.Core.Adapter namespace MQTTnet.Core.Adapter
{ {
public class ReceivedMqttPacket
public sealed class ReceivedMqttPacket : IDisposable
{ {
public ReceivedMqttPacket(MqttPacketHeader header, MemoryStream body) public ReceivedMqttPacket(MqttPacketHeader header, MemoryStream body)
{ {
@@ -15,5 +15,10 @@ namespace MQTTnet.Core.Adapter
public MqttPacketHeader Header { get; } public MqttPacketHeader Header { get; }


public MemoryStream Body { get; } public MemoryStream Body { get; }

public void Dispose()
{
Body?.Dispose();
}
} }
} }

+ 1
- 1
MQTTnet.Core/Serializer/MqttPacketWriter.cs View File

@@ -9,7 +9,7 @@ namespace MQTTnet.Core.Serializer
public sealed class MqttPacketWriter : BinaryWriter public sealed class MqttPacketWriter : BinaryWriter
{ {
public MqttPacketWriter(Stream stream) public MqttPacketWriter(Stream stream)
: base(stream)
: base(stream, Encoding.UTF8, true)
{ {
} }




Loading…
Cancel
Save