🐛 Fix websocket event loop somehow

This commit is contained in:
2025-07-29 18:12:51 +08:00
parent 05c6410550
commit 1f7b19938b
2 changed files with 8 additions and 7 deletions

View File

@@ -62,7 +62,8 @@ public class WebSocketController(WebSocketService ws, ILogger<WebSocketContext>
{
ws.Disconnect(connectionKey);
logger.LogInformation(
$"Connection disconnected with user @{currentUser.Name}#{currentUser.Id} and device #{deviceId}");
$"Connection disconnected with user @{currentUser.Name}#{currentUser.Id} and device #{deviceId}"
);
}
}
@@ -78,17 +79,16 @@ public class WebSocketController(WebSocketService ws, ILogger<WebSocketContext>
var buffer = new byte[1024 * 4];
try
{
var receiveResult = await webSocket.ReceiveAsync(
new ArraySegment<byte>(buffer),
cancellationToken
);
while (!receiveResult.CloseStatus.HasValue)
while (true)
{
receiveResult = await webSocket.ReceiveAsync(
var receiveResult = await webSocket.ReceiveAsync(
new ArraySegment<byte>(buffer),
cancellationToken
);
if (receiveResult.CloseStatus.HasValue)
break;
var packet = WebSocketPacket.FromBytes(buffer[..receiveResult.Count]);
_ = ws.HandlePacket(currentUser, connectionKey.DeviceId, packet, webSocket);
}