Exemplo n.º 1
0
        private List <NetPacketV1> recvPacketList()
        {
            if (!this.isConnected())
            {
                return(null);
            }
            List <NetPacketV1> list = new List <NetPacketV1>();

            try
            {
                NetPacketV1 tv;
                byte[]      buffer  = new byte[0x40000];
                SocketError success = SocketError.Success;
                int         length  = this.socket_.Receive(buffer, 0, buffer.Length, SocketFlags.None, out success);
                switch (success)
                {
                case SocketError.TimedOut:
                case SocketError.WouldBlock:
                case SocketError.IOPending:
                    return(list);
                }
                if ((success != SocketError.Success) || (length == 0))
                {
                    this.socket_.Close();
                    this.socket_ = null;
                    return(list);
                }
                byte[] destinationArray = new byte[0x40000];
                Array.Copy(this.left_buf_, 0, destinationArray, 0, this.left_buf_len_);
                Array.Copy(buffer, 0, destinationArray, this.left_buf_len_, length);
                int num2 = length + this.left_buf_len_;
                this.left_buf_len_ = 0;
                for (int i = num2; i > 0; i -= tv.getPacketLen())
                {
                    byte[] buffer3 = new byte[i];
                    Array.Copy(destinationArray, num2 - i, buffer3, 0, i);
                    tv = new NetPacketV1();
                    PacketStatus status = tv.deserialize(ref buffer3);
                    if (status != PacketStatus.PACKET_CORRECT)
                    {
                        if (status == PacketStatus.PACKET_NOT_COMPLETE)
                        {
                            this.left_buf_len_ = i;
                            Array.Copy(buffer3, 0, this.left_buf_, 0, this.left_buf_len_);
                        }
                        return(list);
                    }
                    list.Add(tv);
                }
            }
            catch (SystemException)
            {
                if (this.isConnected())
                {
                }
            }
            return(list);
        }