public void ClearTest()
 {
     ReceiveStream target = new ReceiveStream(); // TODO: 初始化为适当的值
     target.Write(new byte[] { 1, 2 }, 0, 2);
     target.Clear();
     Assert.IsTrue(target.Length == 0);
 }
 public void ClearTest1()
 {
     ReceiveStream target = new ReceiveStream(); // TODO: 初始化为适当的值
     target.Write(new byte[] { 1, 2 }, 0, 2);
     int count = 1; // TODO: 初始化为适当的值
     target.Clear(count);
     Assert.IsTrue(target.Length == 1 && target[0] == 2);
 }
 public void CopyToTest()
 {
     ReceiveStream target = new ReceiveStream(); // TODO: 初始化为适当的值
     target.Write(new byte[] { 1, 2, 3, 4 }, 0, 4);
     byte[] dstArray = new byte[2]; // TODO: 初始化为适当的值
     int count = 2; // TODO: 初始化为适当的值
     target.CopyTo(dstArray, count);
     Assert.IsTrue(dstArray[0] == 1 && dstArray[1] == 2);
 }
예제 #4
0
        /// <summary>
        /// 从收到的数据流中解析请求体
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static TelnetRequest Parse(ReceiveStream stream)
        {
            stream.Position = 0;
            var index = stream.IndexOf(Crlf); // 以CRLF为结束标识
            if (index < 0)
            {
                return null;
            }
            var input = stream.ReadString(index, Encoding.ASCII);
            stream.Clear(index + Crlf.Length);

            if (string.IsNullOrWhiteSpace(input) == true) // 空内容
            {
                return TelnetRequest.Parse(stream);
            }

            var items = input.Split(new string[] { " " }, 2, StringSplitOptions.RemoveEmptyEntries);
            var cmd = items.First();
            var arg = items.Length > 1 ? items.Last() : null;
            return new TelnetRequest(cmd, arg);
        }
예제 #5
0
        /// <summary>
        /// 释放资源
        /// </summary>
        /// <param name="disposing">是否也释放托管资源</param>
        protected virtual void Dispose(bool disposing)
        {
            this.CloseInternal(false);
            this.sendArg.Dispose();
            this.recvArg.Dispose();

            if (disposing)
            {
                this.recvStream = null;
                this.recvArg    = null;

                this.byteRangeQueue = null;
                this.sendArg        = null;

                this.socket     = null;
                this.socketRoot = null;

                this.TagBag  = null;
                this.TagData = null;
            }
        }
예제 #6
0
 /// <summary>
 /// 调试视图
 /// </summary>
 /// <param name="view">查看的对象</param>
 public DebugView(ReceiveStream view)
 {
     this.view = view;
 }
        public void ReadAndPositionTest()
        {
            ReceiveStream target = new ReceiveStream(); // TODO: 初始化为适当的值
            var bytes = new byte[]{
                1,
                3,
                0,1,
                0,0,0,1,
                0,0,0,0,0,0,0,5,
                255,
                255,255
            };
            target.Write(bytes, 0, bytes.Length);
            target.Position = 0;

            Assert.IsTrue(target.ReadBoolean() && target.Position == 1);
            Assert.IsTrue(target.ReadByte() == 3 && target.Position == 1 + 1);
            Assert.IsTrue(target.ReadInt16() == 1 && target.Position == 1 + 1 + 2);
            Assert.IsTrue(target.ReadInt32() == 1 && target.Position == 1 + 1 + 2 + 4);
            Assert.IsTrue(target.ReadInt64() == 5 && target.Position == 1 + 1 + 2 + 4 + 8);
            Assert.IsTrue(target.ReadArray(1)[0] == 255 && target.Position == 1 + 1 + 2 + 4 + 8 + 1);
            Assert.IsTrue(target.ReadArray().Length == 2 && target.Position == 1 + 1 + 2 + 4 + 8 + 1 + 2);
        }
 public void ItemTest()
 {
     ReceiveStream target = new ReceiveStream(); // TODO: 初始化为适当的值
     target.Write(new byte[] { 234 }, 0, 1);
     int index = 0; // TODO: 初始化为适当的值
     byte actual;
     actual = target[index];
     Assert.IsTrue(actual == 234);
 }
        public void IndexOfTest()
        {
            ReceiveStream target = new ReceiveStream(); // TODO: 初始化为适当的值
            var bytes = new byte[] { 2, 3, 4, 4 };
            target.Write(bytes, 0, bytes.Length);
            target.Position = 0;

            var actual = target.IndexOf(bytes);
            Assert.AreEqual(0, actual);

            var byte2 = new byte[] { 3, 4 };
            actual = target.IndexOf(byte2);
            Assert.AreEqual(1, actual);

            var byte3 = new byte[] { 3, 4, 5 };
            actual = target.IndexOf(byte3);
            Assert.AreEqual(-1, actual);

            var byte4 = new byte[] { 4 };
            actual = target.IndexOf(byte4);
            Assert.AreEqual(2, actual);

            var byte5 = new byte[] { 2, 3, 4, 4 };
            actual = target.IndexOf(byte5);
            Assert.AreEqual(0, actual);

            var byte6 = new byte[] { 2, 3, 4, 4,5 };
            actual = target.IndexOf(byte6);
            Assert.AreEqual(-1, actual);
        }
 public void CopyToTest2()
 {
     ReceiveStream target = new ReceiveStream(); // TODO: 初始化为适当的值
     target.Write(new byte[] { 1, 2, 3, 4 }, 0, 4);
     int srcOffset = 2; // TODO: 初始化为适当的值
     byte[] dstArray = new byte[3]; ; // TODO: 初始化为适当的值
     int dstOffset = 1; // TODO: 初始化为适当的值
     int count = 2; // TODO: 初始化为适当的值
     target.CopyTo(srcOffset, dstArray, dstOffset, count);
     Assert.IsTrue(dstArray[1] == 3 && dstArray[2] == 4);
 }
예제 #11
0
 /// <summary>
 /// 当接收到远程端的数据时,将触发此方法
 /// </summary>
 /// <param name="buffer">接收到的历史数据</param>
 /// <returns></returns>
 protected abstract void OnReceive(ReceiveStream buffer);
예제 #12
0
        /// <summary>
        /// 释放资源
        /// </summary>
        /// <param name="disposing">是否也释放托管资源</param>
        protected virtual void Dispose(bool disposing)
        {
            this.CloseInternal(false);
            this.sendArg.Dispose();
            this.recvArg.Dispose();

            if (disposing)
            {
                this.recvStream = null;
                this.recvArg = null;

                this.byteRangeQueue = null;
                this.sendArg = null;

                this.socket = null;
                this.socketRoot = null;

                this.TagBag = null;
                this.TagData = null;
            }
        }
예제 #13
0
 /// <summary>
 /// 当接收到会话对象的数据时,将触发此方法
 /// </summary>
 /// <param name="session">会话对象</param>
 /// <param name="buffer">接收到的历史数据</param>
 /// <returns></returns>
 protected abstract void OnReceive(T session, ReceiveStream buffer);
예제 #14
0
 /// <summary>
 /// 调试视图
 /// </summary>
 /// <param name="view">查看的对象</param>
 public DebugView(ReceiveStream view)
 {
     this.view = view;
 }
예제 #15
0
 /// <summary>
 /// 当接收到远程端的数据时,将触发此方法   
 /// </summary>       
 /// <param name="buffer">接收到的历史数据</param>
 /// <returns></returns>
 protected abstract void OnReceive(ReceiveStream buffer);