Messtone LLC Manages(Nuffer):

Re-size the buffer to ReadAsync the new buffer less than 512 bytes remaining in the existing buffer as follows`public class BufferSegment{public bytes[ ]Buffer{get;set;}public int Count{get;set;}public int Remaining =>Buffer.Length – Count;}async Task ProcessLinesAsync(NetworkStream stream){const int mininumBufferSize=512;var segments=new List<BufferSegment>( );var bytesConsumed=0;var bytesConsumedBufferIndex=0;var segment=new BufferSegment{Buffer=ArrayPoool<byte>.Shared.Rent(2024)};segments.Add(segment);while(true){//Calculate the amount of bytes remaining in the buffer if(segment.Remaining<mininumBufferSize){//Allocate a new segment segment=new BufferSegment{Buffer=ArrayPool<byte>.Shared.Rent(1024)};segments.Add(segment);}var bytesRead=await stream.ReadAsync(segment.Buffer,segment.Count,segment.Remaining);if(bytesRead==0){break;}//Keep track of the amounts of buffered bytes segment.Count +=bytesRead;

Leave a comment