public void Update() { while (m_queWillDo.Count > 0) { MsgReceiveBase mr = m_queWillDo.Dequeue(); mr.DoMsg(); } }
void ParsePacket() { int nCursor = 0; int nMsgTotalLength = BitConverter.ToInt32(m_buffer, nCursor); nCursor += sizeof(Int32); Array.Reverse(m_buffer, nCursor, sizeof(Int32)); int nHeaderLength = BitConverter.ToInt32(m_buffer, nCursor); nCursor += sizeof(Int32); byte[] headerBytes = new byte[nHeaderLength]; Array.Copy(m_buffer, nCursor, headerBytes, 0, nHeaderLength); nCursor += nHeaderLength; Array.Reverse(m_buffer, nCursor, sizeof(Int32)); int nBodyLength = BitConverter.ToInt32(m_buffer, nCursor); nCursor += sizeof(Int32); byte[] bodyBytes = new byte[nBodyLength]; Array.Copy(m_buffer, nCursor, bodyBytes, 0, nBodyLength); nCursor += nBodyLength; TMemoryBuffer trans = new TMemoryBuffer(headerBytes); TBinaryProtocol proto = new TBinaryProtocol(trans); ProtocolHeader msgThriftHead = new ProtocolHeader(); msgThriftHead.Read(proto); if (m_msgHash.ContainsKey(msgThriftHead.ProtocolHash)) { MsgReceiveBase msgRec = Activator.CreateInstance(m_msgHash[msgThriftHead.ProtocolHash]) as MsgReceiveBase; msgRec.ParsePacket(bodyBytes); m_queWillDo.Enqueue(msgRec); } m_nMsgLength = 0; m_nCurReadPos = 0; // CloseSocket(); }