Ejemplo n.º 1
0
        internal bool Receive(byte[] buffer, int offset, int count)
        {
            ReceiveBuffer.WriteBytes(buffer, offset, count);  // 写入数据内容
            bool result = true;

            while (ReceiveBuffer.DataCount > sizeof(int))
            {
                //按照长度分包
                int packetLength = BitConverter.ToInt32(ReceiveBuffer.Buffer, 0);           //获取包长度 // 老版代码

                if ((packetLength > 10 * 1024 * 1024) | (buffer.Length > 10 * 1024 * 1024)) //最大Buffer异常保护
                {
                    App.Logger.Error("内存超出, 数据不进行操作, 关闭远程连接");
                    return(false);
                }

                if ((ReceiveBuffer.DataCount - sizeof(int)) >= packetLength) //收到的数据达到包长度
                {
                    result = PacketProcess.Process(this, ReceiveBuffer.Buffer, sizeof(int), packetLength);
                    if (result)
                    {
                        ReceiveBuffer.Clear(packetLength + sizeof(int));
                    }
                    else
                    {
                        return(result);
                    }
                }
                else
                {
                    return(true);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public void ProcessTest()
        {
            for (int i = 1; i <= 22; i++)
            {
                string s1 = @".\tests\" + String.Format("{0:00}", i);
                string s2 = @".\tests\" + String.Format("{0:00}", i) + ".a";

                string t1 = System.IO.File.ReadAllText(s1);
                string t2 = System.IO.File.ReadAllText(s2);

                string Delimiter = "\r\n";
                var    t1SplitRN = t1.Split(new[] { Delimiter }, StringSplitOptions.None);


                var inputFirstLine = t1SplitRN[0].Split(' ');

                int bufferSize = Int32.Parse(inputFirstLine[0]);
                int packNumber = Int32.Parse(inputFirstLine[1]);

                List <Pack> inputList = new List <Pack>();

                for (int j = 1; j <= packNumber; j++)
                {
                    var  packInput = t1SplitRN[j].Split(' ');
                    Pack thepack   = new Pack(Int32.Parse(packInput[0]), Int32.Parse(packInput[1]), j - 1);
                    inputList.Add(thepack);
                }


                string expected = t2;
                using (var consoleOutput = new ConsoleOutput())
                {
                    PacketProcess.Process(bufferSize, inputList);
                    string error = "Case" + String.Format("{0:00}", i);
                    Assert.AreEqual(expected, consoleOutput.GetOuput(), error);
                }
            }
        }
Ejemplo n.º 3
0
 private void Update()
 {
     PacketProcess.Process(m_packetQueue, Instance);
 }