private void TimeoutCheck(CoroutineLockComponent self) { // 超时的锁 if (self.timers.Count == 0) { return; } long timeNow = TimeHelper.ClientFrameTime(); if (timeNow < self.minTime) { return; } foreach (KeyValuePair <long, List <long> > kv in self.timers) { long k = kv.Key; if (k > timeNow) { self.minTime = k; break; } self.timeOutIds.Enqueue(k); } self.timerOutTimer.Clear(); while (self.timeOutIds.Count > 0) { long time = self.timeOutIds.Dequeue(); var list = self.timers[time]; for (int i = 0; i < list.Count; ++i) { self.timerOutTimer.Enqueue(list[i]); } self.timers.Remove(time); } while (self.timerOutTimer.Count > 0) { long CoroutineLockInstanceId = self.timerOutTimer.Dequeue(); CoroutineLock coroutineLock = Game.EventSystem.Get(CoroutineLockInstanceId) as CoroutineLock; if (coroutineLock == null) { continue; } // 超时直接调用下一个锁 self.RunNextCoroutine(coroutineLock.coroutineLockType, coroutineLock.key, coroutineLock.level + 1); coroutineLock.coroutineLockType = CoroutineLockType.None; // 上面调用了下一个, dispose不再调用 } }
private static CoroutineLock CreateCoroutineLock(this CoroutineLockComponent self, int coroutineLockType, long key, int time, int level) { CoroutineLock coroutineLock = self.AddChildWithId <CoroutineLock, int, long, int>(++self.idGenerator, coroutineLockType, key, level, true); if (time > 0) { self.AddTimer(TimeHelper.ClientFrameTime() + time, coroutineLock); } return(coroutineLock); }
public static CoroutineLock CreateCoroutineLock(this CoroutineLockComponent self, CoroutineLockType coroutineLockType, long key, int time, int count) { CoroutineLock coroutineLock = EntityFactory.CreateWithId <CoroutineLock, CoroutineLockType, long, int>(self.Domain, ++self.idGenerator, coroutineLockType, key, count, true); if (time > 0) { self.AddTimer(TimeHelper.ClientFrameTime() + time, coroutineLock); } return(coroutineLock); }
private void TimeoutCheck(CoroutineLockComponent self) { // 超时的锁 if (self.timers.Count == 0) { return; } long timeNow = TimeHelper.ClientFrameTime(); if (timeNow < self.minTime) { return; } foreach (KeyValuePair <long, List <CoroutineLockTimer> > kv in self.timers) { long k = kv.Key; if (k > timeNow) { self.minTime = k; break; } self.timeOutIds.Enqueue(k); } self.timerOutTimer.Clear(); while (self.timeOutIds.Count > 0) { long time = self.timeOutIds.Dequeue(); foreach (CoroutineLockTimer coroutineLockTimer in self.timers[time]) { self.timerOutTimer.Enqueue(coroutineLockTimer); } self.timers.Remove(time); } while (self.timerOutTimer.Count > 0) { CoroutineLockTimer coroutineLockTimer = self.timerOutTimer.Dequeue(); if (coroutineLockTimer.CoroutineLockInstanceId != coroutineLockTimer.CoroutineLock.InstanceId) { continue; } CoroutineLock coroutineLock = coroutineLockTimer.CoroutineLock; // 超时直接调用下一个锁 self.RunNextCoroutine(coroutineLock.coroutineLockType, coroutineLock.key, coroutineLock.level + 1); coroutineLock.coroutineLockType = CoroutineLockType.None; // 上面调用了下一个, dispose不再调用 } }
private void TimeoutCheck(CoroutineLockComponent self) { // 超时的锁 if (self.timers.Count == 0) { return; } self.timeNow = TimeHelper.ClientFrameTime(); if (self.timeNow < self.minTime) { return; } self.timers.ForEachFunc(self.foreachFunc); self.timerOutTimer.Clear(); while (self.timeOutIds.Count > 0) { long time = self.timeOutIds.Dequeue(); var list = self.timers[time]; for (int i = 0; i < list.Count; ++i) { CoroutineLockTimer coroutineLockTimer = list[i]; self.timerOutTimer.Enqueue(coroutineLockTimer); } self.timers.Remove(time); } while (self.timerOutTimer.Count > 0) { CoroutineLockTimer coroutineLockTimer = self.timerOutTimer.Dequeue(); if (coroutineLockTimer.CoroutineLockInstanceId != coroutineLockTimer.CoroutineLock.InstanceId) { continue; } CoroutineLock coroutineLock = coroutineLockTimer.CoroutineLock; // 超时直接调用下一个锁 self.RunNextCoroutine(coroutineLock.coroutineLockType, coroutineLock.key, coroutineLock.level + 1); coroutineLock.coroutineLockType = CoroutineLockType.None; // 上面调用了下一个, dispose不再调用 } }
public void Dispatch(Session session, MemoryStream memoryStream) { ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.KcpOpcodeIndex); Type type = OpcodeTypeComponent.Instance.GetType(opcode); object message = MessageSerializeHelper.DeserializeFrom(opcode, type, memoryStream); if (TimeHelper.ClientFrameTime() - this.lastMessageTime > 3000) { Log.Info($"可能导致卡死的消息: {this.LastMessage}"); } this.lastMessageTime = TimeHelper.ClientFrameTime(); this.LastMessage = message; if (message is IResponse response) { session.OnRead(opcode, response); return; } OpcodeHelper.LogMsg(session.DomainZone(), opcode, message); // 普通消息或者是Rpc请求消息 MessageDispatcherComponent.Instance.Handle(session, opcode, message); }