コード例 #1
0
        public async Task CallingTransferBeforeReadAsync()
        {
            var testInput = new TestInput();
            var context = new ConnectionContext();
            context.SocketInput = new SocketInput(new MemoryPool());

            var exchanger = new MessageBodyExchanger(testInput.FrameContext);

            testInput.Add("Hello");

            exchanger.Transfer(5, false);

            var buffer1 = new byte[1024];
            var buffer2 = new byte[1024];
            var task1 = exchanger.ReadAsync(new ArraySegment<byte>(buffer1));
            var task2 = exchanger.ReadAsync(new ArraySegment<byte>(buffer2));

            Assert.True(task1.IsCompleted);
            Assert.False(task2.IsCompleted);

            await task1;

            var count1 = await task1;

            Assert.True(task1.IsCompleted);
            Assert.False(task2.IsCompleted);
            AssertASCII("Hello", new ArraySegment<byte>(buffer1, 0, count1));
        }
コード例 #2
0
        public async Task TransferFinFirstDoesReturnsCompletedReadAsyncs()
        {

            var testInput = new TestInput();
            var context = new ConnectionContext();
            context.SocketInput = new SocketInput(new MemoryPool());

            var exchanger = new MessageBodyExchanger(testInput.FrameContext);

            testInput.Add("Hello");

            exchanger.Transfer(5, true);

            var buffer1 = new byte[1024];
            var buffer2 = new byte[1024];
            var task1 = exchanger.ReadAsync(new ArraySegment<byte>(buffer1));
            var task2 = exchanger.ReadAsync(new ArraySegment<byte>(buffer2));

            Assert.True(task1.IsCompleted);
            Assert.True(task2.IsCompleted);

            var count1 = await task1;
            var count2 = await task2;

            AssertASCII("Hello", new ArraySegment<byte>(buffer1, 0, count1));
            Assert.Equal(0, count2);
        }