public void Update() { try { if (recv_datas.Count > 0) { lock (recv_datas_obj) { for (int i = 0; i < recv_datas.Count; i++) { process_recv_queue(recv_datas[i]); } recv_datas.Clear(); } } update(KCPServer.iclock()); if (m_KCPServer.m_watch.Elapsed - m_LastRecvTimestamp > UdpLibConfig.MaxTimeNoData) { DisposeReason = ClientSessionDisposeReason.MaxTimeNoData; Dispose(); } } catch (Exception ex) { Log.Error("1111111111111111111111111:" + ex.ToString()); } }
/// <summary> /// 仅仅处理KCP时钟,判断是否好久没有收到数据。 /// </summary> public void Update() { SmartUpdateKCP(KCPServer.iclock()); if (m_KCPServer.m_watch.Elapsed - m_LastRecvTimestamp > UdpLibConfig.MaxTimeNoData) { DisposeReason = ClientSessionDisposeReason.MaxTimeNoData; Dispose(); } }
/// <summary> /// 和Update同一个线程调用 /// </summary> internal void process_recv_queue(byte[] datas) { #if DEV IRQLog.AppLog.Log(this.m_netIndex.ToString() + ",接收1"); #endif if (m_Kcp != null && datas != null) { m_Kcp.Input(datas); m_NeedUpdateFlag = true; for (var size = m_Kcp.PeekSize(); size > 0; size = m_Kcp.PeekSize()) { byte[] buffer; buffer = (UdpLibConfig.UseBytePool ? m_KCPServer.BytePool.Rent(size) : new byte[size]); try { if (m_Kcp.Recv(buffer) > 0) { m_LastRecvTimestamp = m_KCPServer.m_watch.Elapsed; uint key = 0; KCP.ikcp_decode32u(buffer, 0, ref key); if (m_KCPServer.IsClientKeyCorrect(this.m_netIndex, (int)key) == false) { #if DEBUG Console.WriteLine("index:{0} key 不对", this.m_netIndex); #endif m_KCPServer.BytePool.Return(buffer, true); DisposeReason = ClientSessionDisposeReason.IndexKeyError; //key不对 Dispose(); return; } #if DEV IRQLog.AppLog.Log(this.m_netIndex.ToString() + ",接收2"); #endif m_KCPServer.OnRecvData(this, buffer, 0, size); } } finally { if (UdpLibConfig.UseBytePool) { m_KCPServer.BytePool.Return(buffer, true); } } } } }