Exemplo n.º 1
0
    /// <summary>
    /// 交给Command,这里不想关心发给谁。
    /// </summary>
    void Update()
    {
        if (sEvents.Count > 0)
        {
            lock (sEvents)
            {
                while (sEvents.Count > 0)
                {
                    ServerEvent _event = sEvents.Dequeue();
                    if (_event == null)
                    {
                        Util.LogError("ServerType is null");
                        continue;
                    }
                    Distribute(_event._type, _event.Key, _event.Value);
                }
            }
        }
        lock (timeOutList)
        {
            if (timeOutList.Count > 0)
            {
                float curTime = Time.unscaledTime;

                for (int i = timeOutList.Count - 1; i >= 0; i--)
                {
                    if (isStopUpdate)
                    {
                        isStopUpdate = false;
                        break;
                    }
                    MessageTimeOut mto = timeOutList[i];
                    if (curTime - mto.beginTime >= AppConst.SendMessageTimeOut)
                    {     //超时了
                        if (IsHandleTimeOut(mto.protocal))
                        { //超时处理
                            Util.LogError("server->" + mto.server + "--protocal-->" + mto.protocal + "--messageID-->" + mto.messageID + "--timeout");

                            ByteBuffer buffer = new ByteBuffer();
                            buffer.WriteShort((short)mto.server);
                            buffer.WriteShort(mto.protocal);

                            ByteBuffer _buffer = new ByteBuffer(buffer.ToBytes());
                            buffer.Close();
                            AddEvent(ServerType.Logic, ClientProtocal.TimeOut, _buffer);
                            //EventManager.instance.NotifyEvent(NetEventType.TimeOut, mto.protocal);
                        }
                        timeOutList.Remove(mto);
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
 /// <summary>
 /// 移除超时检测
 /// </summary>
 /// <param name="server"></param>
 /// <param name="protocal"></param>
 public void RemoveTimeOut(ServerType server, short messageID)
 {
     if (timeOutList.Count > 0)
     {
         lock (timeOutList)
         {
             for (int i = timeOutList.Count - 1; i >= 0; i--)
             {
                 MessageTimeOut mto = timeOutList[i];
                 if (mto.server == server && mto.messageID == messageID)
                 {
                     timeOutList.RemoveAt(i);
                 }
             }
         }
     }
 }