Skip to content

Commit

Permalink
WebSocket.SendAll时要阻塞等待,否则数据包被回收后无法使用
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Sep 11, 2024
1 parent 8f73218 commit 5fb3e73
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion NewLife.Core/Http/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void SendAll(IPacket data, WebSocketMessageType type, Func<INetSession, B
var session = (Context?.Connection) ?? throw new ObjectDisposedException(nameof(Context));
var msg = new WebSocketMessage { Type = type, Payload = data };
using var data2 = msg.ToPacket();
session.Host.SendAllAsync(data2, predicate);
session.Host.SendAllAsync(data2, predicate).Wait();
}

/// <summary>想所有连接发送文本消息</summary>
Expand Down
2 changes: 1 addition & 1 deletion NewLife.Core/Http/WebSocketMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public virtual IOwnerPacket ToPacket()
if (!StatusDescription.IsNullOrEmpty()) len += Encoding.UTF8.GetByteCount(StatusDescription);
}

var rs = new OwnerPacket(1 + 1 + 8 + 4 + len);
var rs = new ArrayPacket(1 + 1 + 8 + 4 + len);
var writer = new SpanWriter(rs.GetSpan())
{
IsLittleEndian = false
Expand Down

0 comments on commit 5fb3e73

Please sign in to comment.