void ProccessMessage() { // while (true) { //yield return new WaitForFixedUpdate(); //检查是否有连接错误 CheckConnectError(); if (m_CurrentSocketClient != null && m_MessageEventHandler != null) { recvMessageCount = 0; QueueNode <IPackageData> node = null; do { node = m_oRecieveQueue.Pop(); if (null != node) { executePacket(node.item); recvMessageCount++; if (m_oRecieveRecycle.Size() < MAX_CACHE_SIZE) { PackageData packData = (PackageData)node.item; if (null != packData) { // packData.m_senddata = null; packData.Release(m_oRecieveMemPool); } m_oRecieveRecycle.Push(node); } else { node.item.Release(m_oRecieveMemPool); node.item = null; } } } while (null != node); } } }
//发送一个数据包完毕 public void OnFinishSendData(QueueNode <IPackageData> node) { if (m_oSendRecycle.Size() < MAX_CACHE_SIZE) { PackageData packData = (PackageData)node.item; if (null != packData) { packData.Release(m_oRecieveMemPool); } m_oSendRecycle.Push(node); } else { node.item.Release(m_oRecieveMemPool); node.item = null; } }
//接收数据 public void OnReceive(uint nSocketID, byte[] buffer, int nOffset, int size) { if (null == m_CurrentSocketClient || m_nCurSocketID != nSocketID) { return; } QueueNode <IPackageData> node = m_oRecieveRecycle.Pop(); if (null == node) { node = new QueueNode <IPackageData>(); node.item = new PackageData(); } node.item.Unpack(buffer, nOffset, size, m_oRecieveMemPool); node.item.SetClassID(nSocketID); //压到接收队列 m_oRecieveQueue.Push(node); }