Beispiel #1
0
        private ErrCode OnRecvPacketData()
        {
            ErrCode errCode = ErrCode.Success;

            if (m_recvPacketSize > GetRecvBufSize())
            {
                return IssueRecvPacketData();
            }

            ISmartStream stream = new ISmartStream();
            uint decodedLen = 0;

            stream.SetBuffer(GetRawRecvBuf(), ref decodedLen);

            if (decodedLen != 0)
            {
                SmartPacket packet = (SmartPacket)PacketFactory.Instance.CreateSmartPacket(m_recvPacketCode);
                //SmartPacket packet = CreateSmartPacket(m_recvPacketCode);
                if (packet != null)
                {
                    if (packet.DoDecoding(stream))
                    {
                        if (m_recvPacketHandler != null)
                        {
                            errCode = m_recvPacketHandler(packet);
                            if (errCode == ErrCode.Success)
                            {
                                if (!Connected)
                                {
                                    errCode = ErrCode.NetworkSocketClosed;
                                }
                                else
                                {
                                    ResetRecvBuf();
                                    errCode = IssueRecvPacketHeader();
                                }
                            }
                        }
                    }
                    else
                    {
                        errCode = ErrCode.PacketData;
                    }

                    packet.Dispose();
                }
                else
                {
                    m_errMessage = string.Format("Received invalid packet code ({0})", m_recvPacketCode);
                    errCode = ErrCode.InvalidPacketCode;
                }
            }
            else
            {
                errCode = ErrCode.PacketSize;
            }

            stream.Dispose();

            return errCode;
        }