ProcessIncomingStream() private method

private ProcessIncomingStream ( int bytesRead, StateObject state ) : bool
bytesRead int
state StateObject
return bool
コード例 #1
0
ファイル: TcpReceiveEndpointTest.cs プロジェクト: lulzzz/HIE
        public void TcpReceiveEndpointMultiByteDelimitersTest()
        {
            var options = new TcpReceieveOptions();

            options.SohDelimiters = new byte[] { TcpReceieveOptions.SOH, 0x06 };
            options.StxDelimiters = new byte[] { TcpReceieveOptions.STX, 0x06 };
            options.EtxDelimiters = new byte[] { TcpReceieveOptions.ETX, 0x06 };
            options.EotDelimiters = new byte[] { TcpReceieveOptions.EOT, 0x07 };
            //BUG: If the end-delimiter of STX and EOT match it will not detect EOT
            //options.EOTDelimiters = new byte[] {TcpReceiveEndpoint.EOT, 0x06};

            TcpReceiveEndpoint endpoint = new TcpReceiveEndpoint(new IPEndPoint(IPAddress.Any, 6789), options);
            var host = new Mock <IApplicationHost>();

            endpoint.Initialize(host.Object, options);

            StateObject state = new StateObject(null);

            List <byte> data = new List <byte>();

            data.AddRange(options.SohDelimiters);
            data.AddRange(options.StxDelimiters);
            data.AddRange(new byte[] { 0x41, 0x41, 0x41, 0x41 });
            data.AddRange(options.EtxDelimiters);
            data.AddRange(options.EotDelimiters);
            data.CopyTo(state.Buffer, 0);

            bool isEot = endpoint.ProcessIncomingStream(state.Buffer.Length, state);

            Assert.IsTrue(isEot);
            host.Verify(app => app.ProcessInPipeline(It.IsAny <TcpReceiveEndpoint>(), It.IsNotNull <byte[]>()), Times.Once);
            host.Verify(app => app.ProcessInPipeline(It.IsAny <TcpReceiveEndpoint>(), It.Is <byte[]>(indata => indata.SequenceEqual(new byte[] { 0x41, 0x41, 0x41, 0x41 }))));
        }
コード例 #2
0
ファイル: TcpReceiveEndpointTest.cs プロジェクト: lulzzz/HIE
        public void TcpReceiveEndpointMissingTransmissionDelimitersTest()
        {
            var options = new TcpReceieveOptions();

            options.SohDelimiters = new byte[] { };
            options.EotDelimiters = new byte[] { };

            TcpReceiveEndpoint endpoint = new TcpReceiveEndpoint(new IPEndPoint(IPAddress.Any, 6789), options);
            var host = new Mock <IApplicationHost>();

            endpoint.Initialize(host.Object, options);

            StateObject state = new StateObject(null);

            List <byte> data = new List <byte>();

            data.AddRange(options.SohDelimiters);
            data.AddRange(options.StxDelimiters);
            data.AddRange(new byte[] { 0x41, 0x41, 0x41, 0x41 });
            data.AddRange(options.EtxDelimiters);
            data.AddRange(options.EotDelimiters);
            data.CopyTo(state.Buffer, 0);

            bool isEot = endpoint.ProcessIncomingStream(state.Buffer.Length, state);

            Assert.IsFalse(isEot);

            host.Verify(app => app.ProcessInPipeline(It.IsAny <TcpReceiveEndpoint>(), It.IsNotNull <byte[]>()), Times.Once);
            host.Verify(app => app.ProcessInPipeline(It.IsAny <TcpReceiveEndpoint>(), It.Is <byte[]>(indata => indata.SequenceEqual(new byte[] { 0x41, 0x41, 0x41, 0x41 }))));
        }
コード例 #3
0
ファイル: TcpReceiveEndpointTest.cs プロジェクト: lulzzz/HIE
        public void TcpReceiveEndpointMultiByteDelimitersSplittedBufferTest()
        {
            var options = new TcpReceieveOptions();

            options.SohDelimiters = new byte[] { TcpReceieveOptions.SOH, 0x06 };
            options.StxDelimiters = new byte[] { TcpReceieveOptions.STX, 0x06 };
            options.EtxDelimiters = new byte[] { TcpReceieveOptions.ETX, 0x06 };
            options.EotDelimiters = new byte[] { TcpReceieveOptions.EOT, 0x07 };

            TcpReceiveEndpoint endpoint = new TcpReceiveEndpoint(new IPEndPoint(IPAddress.Any, 6789), options);
            var host = new Mock <IApplicationHost>();

            endpoint.Initialize(host.Object, options);

            StateObject state = new StateObject(null);

            List <byte> data = new List <byte>();

            data.AddRange(options.SohDelimiters);
            data.AddRange(options.StxDelimiters);
            data.AddRange(new byte[] { 0x41, 0x41, 0x41, 0x41 });
            data.AddRange(options.EtxDelimiters);
            data.AddRange(options.EotDelimiters);

            bool isEot = false;

            for (int i = 0; i < data.Count; i++)
            {
                state.State = StateObject.FrameState.FindSoh;

                int noBytesInFirstBuffer = i;
                data.CopyTo(0, state.Buffer, 0, noBytesInFirstBuffer);

                isEot = endpoint.ProcessIncomingStream(noBytesInFirstBuffer, state);
                Assert.IsFalse(isEot);

                data.CopyTo(noBytesInFirstBuffer, state.Buffer, 0, data.Count - noBytesInFirstBuffer);
                isEot = endpoint.ProcessIncomingStream(data.Count - noBytesInFirstBuffer, state);
                Assert.IsTrue(isEot);
            }

            host.Verify(app => app.ProcessInPipeline(It.IsAny <TcpReceiveEndpoint>(), It.IsNotNull <byte[]>()), Times.AtLeast(3));
            host.Verify(app => app.ProcessInPipeline(It.IsAny <TcpReceiveEndpoint>(), It.Is <byte[]>(indata => indata.SequenceEqual(new byte[] { 0x41, 0x41, 0x41, 0x41 }))));
        }
コード例 #4
0
		public void TcpReceiveEndpointSingleByteDelimitersTest()
		{
			var options = new TcpReceieveOptions();
			TcpReceiveEndpoint endpoint = new TcpReceiveEndpoint(new IPEndPoint(IPAddress.Any, 6789), options);
			var host = new Mock<IApplicationHost>();
			endpoint.Initialize(host.Object, options);

			StateObject state = new StateObject(null);

			List<byte> data = new List<byte>();
			data.AddRange(new byte[] { TcpReceieveOptions.SOH });
			data.AddRange(new byte[] { TcpReceieveOptions.STX, 0x41, 0x41, 0x41, 0x41, TcpReceieveOptions.ETX });
			data.AddRange(new byte[] { TcpReceieveOptions.EOT });
			data.CopyTo(state.Buffer, 0);

			bool isEot = endpoint.ProcessIncomingStream(state.Buffer.Length, state);

			Assert.IsTrue(isEot);
			host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.IsNotNull<byte[]>()), Times.Once);
			host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.Is<byte[]>(indata => indata.SequenceEqual(new byte[] { 0x41, 0x41, 0x41, 0x41 }))));
		}
コード例 #5
0
		public void TcpReceiveEndpointMultiByteDelimitersTest()
		{
			var options = new TcpReceieveOptions();
			options.SohDelimiters = new byte[] { TcpReceieveOptions.SOH, 0x06 };
			options.StxDelimiters = new byte[] { TcpReceieveOptions.STX, 0x06 };
			options.EtxDelimiters = new byte[] { TcpReceieveOptions.ETX, 0x06 };
			options.EotDelimiters = new byte[] { TcpReceieveOptions.EOT, 0x07 };
			//BUG: If the end-delimiter of STX and EOT match it will not detect EOT
			//options.EOTDelimiters = new byte[] {TcpReceiveEndpoint.EOT, 0x06};

			TcpReceiveEndpoint endpoint = new TcpReceiveEndpoint(new IPEndPoint(IPAddress.Any, 6789), options);
			var host = new Mock<IApplicationHost>();
			endpoint.Initialize(host.Object, options);

			StateObject state = new StateObject(null);

			List<byte> data = new List<byte>();
			data.AddRange(options.SohDelimiters);
			data.AddRange(options.StxDelimiters);
			data.AddRange(new byte[] { 0x41, 0x41, 0x41, 0x41 });
			data.AddRange(options.EtxDelimiters);
			data.AddRange(options.EotDelimiters);
			data.CopyTo(state.Buffer, 0);

			bool isEot = endpoint.ProcessIncomingStream(state.Buffer.Length, state);

			Assert.IsTrue(isEot);
			host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.IsNotNull<byte[]>()), Times.Once);
			host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.Is<byte[]>(indata => indata.SequenceEqual(new byte[] { 0x41, 0x41, 0x41, 0x41 }))));
		}
コード例 #6
0
		public void TcpReceiveEndpointMultiByteDelimitersSplittedBufferTest()
		{
			var options = new TcpReceieveOptions();
			options.SohDelimiters = new byte[] { TcpReceieveOptions.SOH, 0x06 };
			options.StxDelimiters = new byte[] { TcpReceieveOptions.STX, 0x06 };
			options.EtxDelimiters = new byte[] { TcpReceieveOptions.ETX, 0x06 };
			options.EotDelimiters = new byte[] { TcpReceieveOptions.EOT, 0x07 };

			TcpReceiveEndpoint endpoint = new TcpReceiveEndpoint(new IPEndPoint(IPAddress.Any, 6789), options);
			var host = new Mock<IApplicationHost>();
			endpoint.Initialize(host.Object, options);

			StateObject state = new StateObject(null);

			List<byte> data = new List<byte>();
			data.AddRange(options.SohDelimiters);
			data.AddRange(options.StxDelimiters);
			data.AddRange(new byte[] { 0x41, 0x41, 0x41, 0x41 });
			data.AddRange(options.EtxDelimiters);
			data.AddRange(options.EotDelimiters);

			bool isEot = false;

			for (int i = 0; i < data.Count; i++)
			{
				state.State = StateObject.FrameState.FindSoh;

				int noBytesInFirstBuffer = i;
				data.CopyTo(0, state.Buffer, 0, noBytesInFirstBuffer);

				isEot = endpoint.ProcessIncomingStream(noBytesInFirstBuffer, state);
				Assert.IsFalse(isEot);

				data.CopyTo(noBytesInFirstBuffer, state.Buffer, 0, data.Count - noBytesInFirstBuffer);
				isEot = endpoint.ProcessIncomingStream(data.Count - noBytesInFirstBuffer, state);
				Assert.IsTrue(isEot);
			}

			host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.IsNotNull<byte[]>()), Times.AtLeast(3));
			host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.Is<byte[]>(indata => indata.SequenceEqual(new byte[] { 0x41, 0x41, 0x41, 0x41 }))));
		}