public async Task CanHandleLargeBlocks() { var input = new TestInput(); var body = MessageBody.For("HTTP/1.0", new Dictionary<string, StringValues>(), input.FrameContext); var stream = new FrameRequestStream(body); // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. var largeInput = new string('a', 8192); input.Add(largeInput, true); // Add a smaller block to the end so that SocketInput attempts to return the large // block to the memory pool. input.Add("Hello", true); var readBuffer = new byte[8192]; var count1 = await stream.ReadAsync(readBuffer, 0, 8192); Assert.Equal(8192, count1); AssertASCII(largeInput, new ArraySegment<byte>(readBuffer, 0, 8192)); var count2 = await stream.ReadAsync(readBuffer, 0, 8192); Assert.Equal(5, count2); AssertASCII("Hello", new ArraySegment<byte>(readBuffer, 0, 5)); var count3 = await stream.ReadAsync(readBuffer, 0, 8192); Assert.Equal(0, count3); }
public async Task CanHandleLargeBlocks() { var input = new TestInput(); var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); var stream = new FrameRequestStream().StartAcceptingReads(body); // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab. var largeInput = new string('a', 8192); input.Add(largeInput, true); // Add a smaller block to the end so that SocketInput attempts to return the large // block to the memory pool. input.Add("Hello", true); var readBuffer = new byte[8192]; var count1 = await stream.ReadAsync(readBuffer, 0, 8192); Assert.Equal(8192, count1); AssertASCII(largeInput, new ArraySegment <byte>(readBuffer, 0, 8192)); var count2 = await stream.ReadAsync(readBuffer, 0, 8192); Assert.Equal(5, count2); AssertASCII("Hello", new ArraySegment <byte>(readBuffer, 0, 5)); var count3 = await stream.ReadAsync(readBuffer, 0, 8192); Assert.Equal(0, count3); }
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)); }
public async Task TransferZeroBytesDoesNotReleaseReadAsync() { var testInput = new TestInput(); var context = new ConnectionContext(); context.SocketInput = new SocketInput(new MemoryPool()); var exchanger = new MessageBodyExchanger(testInput.FrameContext); 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.False(task1.IsCompleted); Assert.False(task2.IsCompleted); testInput.Add("Hello"); exchanger.Transfer(3, false); var count1 = await task1; Assert.True(task1.IsCompleted); Assert.False(task2.IsCompleted); AssertASCII("Hel", new ArraySegment <byte>(buffer1, 0, count1)); exchanger.Transfer(0, false); Assert.True(task1.IsCompleted); Assert.False(task2.IsCompleted); }
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); }
public async Task Http10ConnectionCloseAsync() { var input = new TestInput(); var body = MessageBody.For("HTTP/1.0", new Dictionary<string, StringValues>(), input.FrameContext); var stream = new FrameRequestStream(body); input.Add("Hello", true); var buffer1 = new byte[1024]; var count1 = await stream.ReadAsync(buffer1, 0, 1024); AssertASCII("Hello", new ArraySegment<byte>(buffer1, 0, 5)); var buffer2 = new byte[1024]; var count2 = await stream.ReadAsync(buffer2, 0, 1024); Assert.Equal(0, count2); }
public void Http10ConnectionClose() { var input = new TestInput(); var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); var stream = new FrameRequestStream().StartAcceptingReads(body); input.Add("Hello", true); var buffer1 = new byte[1024]; var count1 = stream.Read(buffer1, 0, 1024); AssertASCII("Hello", new ArraySegment<byte>(buffer1, 0, 5)); var buffer2 = new byte[1024]; var count2 = stream.Read(buffer2, 0, 1024); Assert.Equal(0, count2); }
public async Task Http10ConnectionCloseAsync() { var input = new TestInput(); var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); var stream = new FrameRequestStream().StartAcceptingReads(body); input.Add("Hello", true); var buffer1 = new byte[1024]; var count1 = await stream.ReadAsync(buffer1, 0, 1024); AssertASCII("Hello", new ArraySegment <byte>(buffer1, 0, 5)); var buffer2 = new byte[1024]; var count2 = await stream.ReadAsync(buffer2, 0, 1024); Assert.Equal(0, count2); }
public void Http10ConnectionClose() { var input = new TestInput(); var body = MessageBody.For("HTTP/1.0", new Dictionary <string, StringValues>(), input.FrameContext); var stream = new FrameRequestStream(body); input.Add("Hello", true); var buffer1 = new byte[1024]; var count1 = stream.Read(buffer1, 0, 1024); AssertASCII("Hello", new ArraySegment <byte>(buffer1, 0, 5)); var buffer2 = new byte[1024]; var count2 = stream.Read(buffer2, 0, 1024); Assert.Equal(0, count2); }
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); }