Skip to content

Commit d557324

Browse files
author
psygames
committed
[v2.81][bugfix] replace task.yield to thead.sleep(1), fix cpu 100% cost
1 parent c57bed0 commit d557324

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

Assets/UnityWebSocket/Scripts/Runtime/Core/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ public static class Settings
77
public const string QQ_GROUP_LINK = "https://qm.qq.com/cgi-bin/qm/qr?k=KcexYJ9aYwogFXbj2aN0XHH5b2G7ICmd";
88
public const string EMAIL = "[email protected]";
99
public const string AUHTOR = "psygames";
10-
public const string VERSION = "2.8.0";
10+
public const string VERSION = "2.8.1";
1111
}
1212
}

Assets/UnityWebSocket/Scripts/Runtime/Implementation/NoWebGL/WebSocket.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,13 @@ private async void StartSendTask()
166166
{
167167
while (!closeProcessing)
168168
{
169-
while (!closeProcessing && sendQueue.TryDequeue(out var buffer))
169+
while (!closeProcessing && sendQueue.Count > 0 && sendQueue.TryDequeue(out var buffer))
170170
{
171171
Log($"Send, type: {buffer.type}, size: {buffer.data.Length}, queue left: {sendQueue.Count}");
172172
await socket.SendAsync(new ArraySegment<byte>(buffer.data), buffer.type, true, CancellationToken.None);
173173
}
174-
await Task.Yield();
174+
Thread.Sleep(1);
175175
}
176-
177176
if (closeProcessing)
178177
{
179178
CleanSendQueue();
@@ -279,7 +278,7 @@ private void HandleError(Exception exception)
279278

280279
internal void Update()
281280
{
282-
while (receiveQueue.TryDequeue(out var e))
281+
while (receiveQueue.Count > 0 && receiveQueue.TryDequeue(out var e))
283282
{
284283
if (e is CloseEventArgs)
285284
{

ProjectSettings/ProjectSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ PlayerSettings:
128128
16:10: 1
129129
16:9: 1
130130
Others: 1
131-
bundleVersion: 2.8.0
131+
bundleVersion: 2.8.1
132132
preloadedAssets: []
133133
metroInputSource: 0
134134
wsaTransparentSwapchain: 0

0 commit comments

Comments
 (0)