Skip to content

Commit

Permalink
Add LICENSE
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Nov 15, 2024
1 parent 0a216a9 commit 580257a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -174,7 +173,7 @@ public override void Flush() { }

public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
{
return _webSocket.SendAsync(buffer, WebSocketMessageType.Binary, true, cancellationToken);
return _webSocket.SendAsync(buffer, WebSocketMessageType.Binary, false, cancellationToken);
}

public override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
Expand Down
16 changes: 13 additions & 3 deletions Source/MQTTnet.AspnetCore/Internal/ClientConnectionContext.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,6 +21,8 @@ sealed partial class ClientConnectionContext : ConnectionContext
private readonly Stream _stream;
private readonly CancellationTokenSource _connectionCloseSource = new();

private IDictionary<object, object?>? _items;

public override IDuplexPipe Transport { get; set; }

public override CancellationToken ConnectionClosed
Expand All @@ -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<object, object?> Items { get; set; } = new Dictionary<object, object?>();
public override IDictionary<object, object?> Items
{
get => _items ??= new Dictionary<object, object?>();
set => _items = value;
}

public ClientConnectionContext(Stream stream)
{
Expand All @@ -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));
Expand Down

0 comments on commit 580257a

Please sign in to comment.