From 580257acb1298e51494b627ea6edf3461a085f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Fri, 15 Nov 2024 20:23:14 +0800 Subject: [PATCH] Add LICENSE --- .../Internal/ClientConnectionContext.Tcp.cs | 4 ++++ .../ClientConnectionContext.WebSocket.cs | 15 +++++++-------- .../Internal/ClientConnectionContext.cs | 16 +++++++++++++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.Tcp.cs b/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.Tcp.cs index e7385f13b..b16d27bac 100644 --- a/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.Tcp.cs +++ b/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.Tcp.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http.Features; diff --git a/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.WebSocket.cs b/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.WebSocket.cs index 4cf7a8add..6bea4f91b 100644 --- a/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.WebSocket.cs +++ b/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.WebSocket.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http.Features; using System; @@ -147,14 +151,9 @@ private static void SetupClientWebSocket(ClientWebSocket clientWebSocket, MqttCl } - private class WebSocketStream : Stream + private class WebSocketStream(WebSocket webSocket) : Stream { - private readonly WebSocket _webSocket; - - public WebSocketStream(WebSocket webSocket) - { - _webSocket = webSocket; - } + private readonly WebSocket _webSocket = webSocket; public override bool CanRead => true; public override bool CanSeek => false; @@ -174,7 +173,7 @@ public override void Flush() { } public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) { - return _webSocket.SendAsync(buffer, WebSocketMessageType.Binary, true, cancellationToken); + return _webSocket.SendAsync(buffer, WebSocketMessageType.Binary, false, cancellationToken); } public override async ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) diff --git a/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.cs b/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.cs index 547c7fa9d..f578013a9 100644 --- a/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.cs +++ b/Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http.Features; @@ -17,6 +21,8 @@ sealed partial class ClientConnectionContext : ConnectionContext private readonly Stream _stream; private readonly CancellationTokenSource _connectionCloseSource = new(); + private IDictionary? _items; + public override IDuplexPipe Transport { get; set; } public override CancellationToken ConnectionClosed @@ -25,11 +31,15 @@ public override CancellationToken ConnectionClosed set => throw new InvalidOperationException(); } - public override string ConnectionId { get; set; } = Guid.NewGuid().ToString(); + public override string ConnectionId { get; set; } = string.Empty; public override IFeatureCollection Features { get; } = new FeatureCollection(); - public override IDictionary Items { get; set; } = new Dictionary(); + public override IDictionary Items + { + get => _items ??= new Dictionary(); + set => _items = value; + } public ClientConnectionContext(Stream stream) { @@ -50,7 +60,7 @@ public override void Abort() _connectionCloseSource.Cancel(); } - + private class StreamTransport(Stream stream) : IDuplexPipe { public PipeReader Input { get; } = PipeReader.Create(stream, new StreamPipeReaderOptions(leaveOpen: true));