From d5573240f20d86d2e2117bf8b6b5465a8a7d6437 Mon Sep 17 00:00:00 2001 From: psygames

Date: Tue, 27 Aug 2024 21:49:57 +0800 Subject: [PATCH] [v2.81][bugfix] replace task.yield to thead.sleep(1), fix cpu 100% cost --- Assets/UnityWebSocket/Scripts/Runtime/Core/Settings.cs | 2 +- .../Scripts/Runtime/Implementation/NoWebGL/WebSocket.cs | 7 +++---- ProjectSettings/ProjectSettings.asset | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Assets/UnityWebSocket/Scripts/Runtime/Core/Settings.cs b/Assets/UnityWebSocket/Scripts/Runtime/Core/Settings.cs index d6c8d57..227daa6 100644 --- a/Assets/UnityWebSocket/Scripts/Runtime/Core/Settings.cs +++ b/Assets/UnityWebSocket/Scripts/Runtime/Core/Settings.cs @@ -7,6 +7,6 @@ public static class Settings public const string QQ_GROUP_LINK = "https://qm.qq.com/cgi-bin/qm/qr?k=KcexYJ9aYwogFXbj2aN0XHH5b2G7ICmd"; public const string EMAIL = "799329256@qq.com"; public const string AUHTOR = "psygames"; - public const string VERSION = "2.8.0"; + public const string VERSION = "2.8.1"; } } diff --git a/Assets/UnityWebSocket/Scripts/Runtime/Implementation/NoWebGL/WebSocket.cs b/Assets/UnityWebSocket/Scripts/Runtime/Implementation/NoWebGL/WebSocket.cs index ef8ff92..7c389c1 100644 --- a/Assets/UnityWebSocket/Scripts/Runtime/Implementation/NoWebGL/WebSocket.cs +++ b/Assets/UnityWebSocket/Scripts/Runtime/Implementation/NoWebGL/WebSocket.cs @@ -166,14 +166,13 @@ private async void StartSendTask() { while (!closeProcessing) { - while (!closeProcessing && sendQueue.TryDequeue(out var buffer)) + while (!closeProcessing && sendQueue.Count > 0 && sendQueue.TryDequeue(out var buffer)) { Log($"Send, type: {buffer.type}, size: {buffer.data.Length}, queue left: {sendQueue.Count}"); await socket.SendAsync(new ArraySegment(buffer.data), buffer.type, true, CancellationToken.None); } - await Task.Yield(); + Thread.Sleep(1); } - if (closeProcessing) { CleanSendQueue(); @@ -279,7 +278,7 @@ private void HandleError(Exception exception) internal void Update() { - while (receiveQueue.TryDequeue(out var e)) + while (receiveQueue.Count > 0 && receiveQueue.TryDequeue(out var e)) { if (e is CloseEventArgs) { diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index fc79860..6e7ad0f 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -128,7 +128,7 @@ PlayerSettings: 16:10: 1 16:9: 1 Others: 1 - bundleVersion: 2.8.0 + bundleVersion: 2.8.1 preloadedAssets: [] metroInputSource: 0 wsaTransparentSwapchain: 0