removed dead code and make new connection context an opt in so kestrel 2.0 still works

This commit is contained in:
JanEggers
2018-06-16 17:20:01 +02:00
parent d5ac8c7183
commit 7c2adf636f
4 changed files with 19 additions and 66 deletions
@@ -97,46 +97,12 @@ namespace MQTTnet.AspNetCore
{
foreach (var packet in packets)
{
await WriteAsync(packet);
var buffer = PacketSerializer.Serialize(packet);
await Connection.Transport.Output.WriteAsync(buffer.AsMemory());
}
}
public async Task WriteAsync(MqttBasePacket packet)
{
var buffer = PacketSerializer.Serialize(packet);
await Connection.Transport.Output.WriteAsync(buffer.AsMemory());
}
private int messageId;
public event EventHandler ReadingPacketStarted;
public event EventHandler ReadingPacketCompleted;
public Task PublishAsync(MqttPublishPacket packet)
{
if (!packet.PacketIdentifier.HasValue && packet.QualityOfServiceLevel > MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce)
{
packet.PacketIdentifier = (ushort)Interlocked.Increment(ref messageId);
}
return WriteAsync(packet);
}
public Task SubscribeAsync(MqttSubscribePacket packet)
{
if (!packet.PacketIdentifier.HasValue)
{
packet.PacketIdentifier = (ushort)Interlocked.Increment(ref messageId);
}
return WriteAsync(packet);
}
public Task ConnectAsync(MqttConnectPacket packet)
{
if (string.IsNullOrEmpty(packet.ClientId))
{
packet.ClientId = Guid.NewGuid().ToString();
}
return WriteAsync(packet);
}
}
}
@@ -4,7 +4,6 @@ using System.IO;
using MQTTnet.Adapter;
using MQTTnet.Exceptions;
using MQTTnet.Packets;
using MQTTnet.Protocol;
using MQTTnet.Serializer;
namespace MQTTnet.AspNetCore
@@ -59,30 +58,6 @@ namespace MQTTnet.AspNetCore
return input.ToArray();
}
public static bool TryDeserialize(this IMqttPacketSerializer serializer, ref ReadOnlySequence<byte> input, out MqttBasePacket packet)
{
packet = null;
var copy = input;
if (copy.Length < 2)
{
return false;
}
var fixedheader = copy.First.Span[0];
if (!TryReadBodyLength(ref copy, out var bodyLength))
{
return false;
}
input = copy.Slice(bodyLength);
var bodySlice = copy.Slice(0, bodyLength);
using (var body = new MemoryStream(bodySlice.GetArray()))
{
packet = serializer.Deserialize(new ReceivedMqttPacket(fixedheader, body));
return true;
}
}
public static bool TryDeserialize(this IMqttPacketSerializer serializer, in ReadOnlySequence<byte> input, out MqttBasePacket packet, out SequencePosition consumed, out SequencePosition observed)
{
packet = null;
@@ -30,11 +30,19 @@ namespace MQTTnet.AspNetCore
if (options.DefaultEndpointOptions.IsEnabled)
{
services.AddSingleton<MqttConnectionHandler>();
services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttConnectionHandler>());
services.AddSingleton<MqttTcpServerAdapter>();
services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttTcpServerAdapter>());
}
return services;
}
public static IServiceCollection AddMqttConnectionHandler(this IServiceCollection services)
{
services.AddSingleton<MqttConnectionHandler>();
services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttConnectionHandler>());
return services;
}
}
}
+6 -2
View File
@@ -17,8 +17,12 @@ namespace MQTTnet.TestApp.AspNetCore2
public void ConfigureServices(IServiceCollection services)
{
var mqttServerOptions = new MqttServerOptionsBuilder().Build();
services.AddHostedMqttServer(mqttServerOptions);
var mqttServerOptions = new MqttServerOptionsBuilder()
.WithoutDefaultEndpoint()
.Build();
services
.AddHostedMqttServer(mqttServerOptions)
.AddMqttConnectionHandler();
}
// In class _Startup_ of the ASP.NET Core 2.0 project.