From 1f7b19938b31b24f9d3ed3e3b8d09b0ba6fa07b8 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 29 Jul 2025 18:12:51 +0800 Subject: [PATCH] :bug: Fix websocket event loop somehow --- .../Connection/WebSocketController.cs | 14 +++++++------- DysonNetwork.sln.DotSettings.user | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/DysonNetwork.Pusher/Connection/WebSocketController.cs b/DysonNetwork.Pusher/Connection/WebSocketController.cs index 8acca46..dd6992a 100644 --- a/DysonNetwork.Pusher/Connection/WebSocketController.cs +++ b/DysonNetwork.Pusher/Connection/WebSocketController.cs @@ -62,7 +62,8 @@ public class WebSocketController(WebSocketService ws, ILogger { 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 var buffer = new byte[1024 * 4]; try { - var receiveResult = await webSocket.ReceiveAsync( - new ArraySegment(buffer), - cancellationToken - ); - while (!receiveResult.CloseStatus.HasValue) + while (true) { - receiveResult = await webSocket.ReceiveAsync( + var receiveResult = await webSocket.ReceiveAsync( new ArraySegment(buffer), cancellationToken ); + if (receiveResult.CloseStatus.HasValue) + break; + var packet = WebSocketPacket.FromBytes(buffer[..receiveResult.Count]); _ = ws.HandlePacket(currentUser, connectionKey.DeviceId, packet, webSocket); } diff --git a/DysonNetwork.sln.DotSettings.user b/DysonNetwork.sln.DotSettings.user index 0332845..4919c7c 100644 --- a/DysonNetwork.sln.DotSettings.user +++ b/DysonNetwork.sln.DotSettings.user @@ -5,6 +5,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded