diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs index d93888ffb5..2fa981ceb4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/FilteredStreamAdapter.cs @@ -15,12 +15,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter private readonly Stream _filteredStream; private readonly Stream _socketInputStream; private readonly IKestrelTrace _log; - private readonly MemoryPool2 _memory; - private MemoryPoolBlock2 _block; + private readonly MemoryPool _memory; + private MemoryPoolBlock _block; public FilteredStreamAdapter( Stream filteredStream, - MemoryPool2 memory, + MemoryPool memory, IKestrelTrace logger, IThreadPool threadPool) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs index ccf0a47384..c01682327d 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamExtensions.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter { public static class StreamExtensions { - public static async Task CopyToAsync(this Stream source, Stream destination, MemoryPoolBlock2 block) + public static async Task CopyToAsync(this Stream source, Stream destination, MemoryPoolBlock block) { int bytesRead; while ((bytesRead = await source.ReadAsync(block.Array, block.Data.Offset, block.Data.Count)) != 0) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs index 4b6b335c77..7460cefdb1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Filter/StreamSocketOutput.cs @@ -17,12 +17,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter private static readonly byte[] _nullBuffer = new byte[0]; private readonly Stream _outputStream; - private readonly MemoryPool2 _memory; - private MemoryPoolBlock2 _producingBlock; + private readonly MemoryPool _memory; + private MemoryPoolBlock _producingBlock; private object _writeLock = new object(); - public StreamSocketOutput(Stream outputStream, MemoryPool2 memory) + public StreamSocketOutput(Stream outputStream, MemoryPool memory) { _outputStream = outputStream; _memory = memory; @@ -54,13 +54,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter return TaskUtilities.CompletedTask; } - public MemoryPoolIterator2 ProducingStart() + public MemoryPoolIterator ProducingStart() { _producingBlock = _memory.Lease(); - return new MemoryPoolIterator2(_producingBlock); + return new MemoryPoolIterator(_producingBlock); } - public void ProducingComplete(MemoryPoolIterator2 end) + public void ProducingComplete(MemoryPoolIterator end) { var block = _producingBlock; while (block != end.Block) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs index e6f99c9d53..62dd3499ad 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ChunkWriter.cs @@ -47,14 +47,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return new ArraySegment(bytes, offset, 10 - offset); } - public static int WriteBeginChunkBytes(ref MemoryPoolIterator2 start, int dataCount) + public static int WriteBeginChunkBytes(ref MemoryPoolIterator start, int dataCount) { var chunkSegment = BeginChunkBytes(dataCount); start.CopyFrom(chunkSegment); return chunkSegment.Count; } - public static void WriteEndChunkBytes(ref MemoryPoolIterator2 start) + public static void WriteEndChunkBytes(ref MemoryPoolIterator start) { start.CopyFrom(_endChunkBytes); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index c0de2ed3b3..3280c4082a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -46,8 +46,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId)); - _rawSocketInput = new SocketInput(Memory2, ThreadPool); - _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, ConnectionId, Log, ThreadPool, WriteReqPool); + _rawSocketInput = new SocketInput(Memory, ThreadPool); + _rawSocketOutput = new SocketOutput(Thread, _socket, Memory, this, ConnectionId, Log, ThreadPool, WriteReqPool); } // Internal for testing @@ -206,7 +206,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (_filterContext.Connection != _libuvStream) { - var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool); + var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory, Log, ThreadPool); SocketInput = filteredStreamAdapter.SocketInput; SocketOutput = filteredStreamAdapter.SocketOutput; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs index e8a93d9b4d..3d9ccbaf3c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -8993,7 +8993,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); } - protected void CopyToFast(ref MemoryPoolIterator2 output) + protected void CopyToFast(ref MemoryPoolIterator output) { if (((_bits & 1L) != 0)) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs index 08b9deca0e..c843e96255 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return GetEnumerator(); } - public void CopyTo(ref MemoryPoolIterator2 output) + public void CopyTo(ref MemoryPoolIterator output) { CopyToFast(ref output); if (MaybeUnknown != null) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs index c526caedf9..51c95b13fe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ISocketOutput.cs @@ -18,10 +18,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// /// Returns an iterator pointing to the tail of the response buffer. Response data can be appended - /// manually or by using . - /// Be careful to ensure all appended blocks are backed by a . + /// manually or by using . + /// Be careful to ensure all appended blocks are backed by a . /// - MemoryPoolIterator2 ProducingStart(); + MemoryPoolIterator ProducingStart(); /// /// Commits the response data appended to the iterator returned from . @@ -30,6 +30,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// or is called afterwards. /// /// Points to the end of the committed data. - void ProducingComplete(MemoryPoolIterator2 end); + void ProducingComplete(MemoryPoolIterator end); } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs index 76b64dacba..1a682f9a40 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Listener.cs @@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http }, this); } - Memory2.Dispose(); + Memory.Dispose(); ListenSocket = null; } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs index a012c15326..607c347981 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerContext.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public ListenerContext(ServiceContext serviceContext) : base(serviceContext) { - Memory2 = new MemoryPool2(); + Memory = new MemoryPool(); WriteReqPool = new Queue(SocketOutput.MaxPooledWriteReqs); } @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { ServerAddress = listenerContext.ServerAddress; Thread = listenerContext.Thread; - Memory2 = listenerContext.Memory2; + Memory = listenerContext.Memory; ConnectionManager = listenerContext.ConnectionManager; WriteReqPool = listenerContext.WriteReqPool; Log = listenerContext.Log; @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public KestrelThread Thread { get; set; } - public MemoryPool2 Memory2 { get; set; } + public MemoryPool Memory { get; set; } public ConnectionManager ConnectionManager { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs index 10426c1cc9..6e45fbf7ed 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ListenerSecondary.cs @@ -192,7 +192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http FreeBuffer(); } - Memory2.Dispose(); + Memory.Dispose(); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs index a534fe9261..98efa48692 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInput.cs @@ -16,20 +16,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private static readonly Action _awaitableIsCompleted = () => { }; private static readonly Action _awaitableIsNotCompleted = () => { }; - private readonly MemoryPool2 _memory; + private readonly MemoryPool _memory; private readonly IThreadPool _threadPool; private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false, 0); private Action _awaitableState; private Exception _awaitableError; - private MemoryPoolBlock2 _head; - private MemoryPoolBlock2 _tail; - private MemoryPoolBlock2 _pinned; + private MemoryPoolBlock _head; + private MemoryPoolBlock _tail; + private MemoryPoolBlock _pinned; private int _consumingState; - public SocketInput(MemoryPool2 memory, IThreadPool threadPool) + public SocketInput(MemoryPool memory, IThreadPool threadPool) { _memory = memory; _threadPool = threadPool; @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public bool IsCompleted => ReferenceEquals(_awaitableState, _awaitableIsCompleted); - public MemoryPoolBlock2 IncomingStart() + public MemoryPoolBlock IncomingStart() { const int minimumSize = 2048; @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _tail = _memory.Lease(); } - var iterator = new MemoryPoolIterator2(_tail, _tail.End); + var iterator = new MemoryPoolIterator(_tail, _tail.End); iterator.CopyFrom(buffer, offset, count); if (_head == null) @@ -148,22 +148,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public MemoryPoolIterator2 ConsumingStart() + public MemoryPoolIterator ConsumingStart() { if (Interlocked.CompareExchange(ref _consumingState, 1, 0) != 0) { throw new InvalidOperationException("Already consuming input."); } - return new MemoryPoolIterator2(_head); + return new MemoryPoolIterator(_head); } public void ConsumingComplete( - MemoryPoolIterator2 consumed, - MemoryPoolIterator2 examined) + MemoryPoolIterator consumed, + MemoryPoolIterator examined) { - MemoryPoolBlock2 returnStart = null; - MemoryPoolBlock2 returnEnd = null; + MemoryPoolBlock returnStart = null; + MemoryPoolBlock returnEnd = null; if (!consumed.IsDefault) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 8804d0255f..f424a7531c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private const int _initialTaskQueues = 64; private const int _maxPooledWriteContexts = 32; - private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); + private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock)state); private static readonly Action _connectionCancellation = (state) => ((SocketOutput)state).CancellationTriggered(); private readonly KestrelThread _thread; @@ -34,10 +34,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http // _head does not require a lock, since it is only used in the ctor and uv thread. private readonly object _returnLock = new object(); - private MemoryPoolBlock2 _head; - private MemoryPoolBlock2 _tail; + private MemoryPoolBlock _head; + private MemoryPoolBlock _tail; - private MemoryPoolIterator2 _lastStart; + private MemoryPoolIterator _lastStart; // This locks access to to all of the below fields private readonly object _contextLock = new object(); @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public SocketOutput( KestrelThread thread, UvStreamHandle socket, - MemoryPool2 memory, + MemoryPool memory, Connection connection, string connectionId, IKestrelTrace log, @@ -222,7 +222,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public MemoryPoolIterator2 ProducingStart() + public MemoryPoolIterator ProducingStart() { lock (_returnLock) { @@ -230,16 +230,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (_tail == null) { - return default(MemoryPoolIterator2); + return default(MemoryPoolIterator); } - _lastStart = new MemoryPoolIterator2(_tail, _tail.End); + _lastStart = new MemoryPoolIterator(_tail, _tail.End); return _lastStart; } } - public void ProducingComplete(MemoryPoolIterator2 end) + public void ProducingComplete(MemoryPoolIterator end) { Debug.Assert(!_lastStart.IsDefault); @@ -254,9 +254,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ProducingCompleteNoPreComplete(end); } - private void ProducingCompleteNoPreComplete(MemoryPoolIterator2 end) + private void ProducingCompleteNoPreComplete(MemoryPoolIterator end) { - MemoryPoolBlock2 blockToReturn = null; + MemoryPoolBlock blockToReturn = null; lock (_returnLock) @@ -275,7 +275,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http blockToReturn = _lastStart.Block; } - _lastStart = default(MemoryPoolIterator2); + _lastStart = default(MemoryPoolIterator); } if (blockToReturn != null) @@ -302,7 +302,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - private static void ReturnBlocks(MemoryPoolBlock2 block) + private static void ReturnBlocks(MemoryPoolBlock block) { while (block != null) { @@ -496,7 +496,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return WriteAsync(buffer, cancellationToken, chunk); } - private static void BytesBetween(MemoryPoolIterator2 start, MemoryPoolIterator2 end, out int bytes, out int buffers) + private static void BytesBetween(MemoryPoolIterator start, MemoryPoolIterator end, out int bytes, out int buffers) { if (start.Block == end.Block) { @@ -520,13 +520,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private class WriteContext { - private static WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock2)state); + private static WaitCallback _returnWrittenBlocks = (state) => ReturnWrittenBlocks((MemoryPoolBlock)state); private static WaitCallback _completeWrite = (state) => ((WriteContext)state).CompleteOnThreadPool(); private SocketOutput Self; private UvWriteReq _writeReq; - private MemoryPoolIterator2 _lockedStart; - private MemoryPoolIterator2 _lockedEnd; + private MemoryPoolIterator _lockedStart; + private MemoryPoolIterator _lockedEnd; private int _bufferCount; public int ByteCount; @@ -698,7 +698,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ThreadPool.QueueUserWorkItem(_returnWrittenBlocks, _lockedStart.Block); } - private static void ReturnWrittenBlocks(MemoryPoolBlock2 block) + private static void ReturnWrittenBlocks(MemoryPoolBlock block) { while (block != null) { @@ -722,16 +722,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - _lockedStart = new MemoryPoolIterator2(head, head.Start); - _lockedEnd = new MemoryPoolIterator2(tail, tail.End); + _lockedStart = new MemoryPoolIterator(head, head.Start); + _lockedEnd = new MemoryPoolIterator(tail, tail.End); BytesBetween(_lockedStart, _lockedEnd, out ByteCount, out _bufferCount); } public void Reset() { - _lockedStart = default(MemoryPoolIterator2); - _lockedEnd = default(MemoryPoolIterator2); + _lockedStart = default(MemoryPoolIterator); + _lockedEnd = default(MemoryPoolIterator); _bufferCount = 0; ByteCount = 0; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs index 60f83303f1..90895fe691 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/UrlPathDecoder.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// The iterator points to the beginning of the sequence. /// The iterator points to the byte behind the end of the sequence. /// The iterator points to the byte behind the end of the processed sequence. - public static MemoryPoolIterator2 Unescape(MemoryPoolIterator2 start, MemoryPoolIterator2 end) + public static MemoryPoolIterator Unescape(MemoryPoolIterator start, MemoryPoolIterator end) { // the slot to read the input var reader = start; @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// The iterator point to the first % char /// The place to write to /// The end of the sequence - private static bool DecodeCore(ref MemoryPoolIterator2 reader, ref MemoryPoolIterator2 writer, MemoryPoolIterator2 end) + private static bool DecodeCore(ref MemoryPoolIterator reader, ref MemoryPoolIterator writer, MemoryPoolIterator end) { // preserves the original head. if the percent-encodings cannot be interpreted as sequence of UTF-8 octets, // bytes from this till the last scanned one will be copied to the memory pointed by writer. @@ -189,7 +189,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return true; } - private static void Copy(MemoryPoolIterator2 head, MemoryPoolIterator2 tail, ref MemoryPoolIterator2 writer) + private static void Copy(MemoryPoolIterator head, MemoryPoolIterator tail, ref MemoryPoolIterator writer) { while (!CompareIterators(ref head, ref tail)) { @@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// The value to read /// The end of the sequence /// The unescaped byte if success. Otherwise return -1. - private static int UnescapePercentEncoding(ref MemoryPoolIterator2 scan, MemoryPoolIterator2 end) + private static int UnescapePercentEncoding(ref MemoryPoolIterator scan, MemoryPoolIterator end) { if (scan.Take() != '%') { @@ -255,7 +255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http /// The value to read /// The end of the sequence /// The hexadecimal value if successes, otherwise -1. - private static int ReadHex(ref MemoryPoolIterator2 scan, MemoryPoolIterator2 end) + private static int ReadHex(ref MemoryPoolIterator scan, MemoryPoolIterator end) { if (CompareIterators(ref scan, ref end)) { @@ -297,7 +297,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return false; } - private static bool CompareIterators(ref MemoryPoolIterator2 lhs, ref MemoryPoolIterator2 rhs) + private static bool CompareIterators(ref MemoryPoolIterator lhs, ref MemoryPoolIterator rhs) { // uses ref parameter to save cost of copying return (lhs.Block == rhs.Block) && (lhs.Index == rhs.Index); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs similarity index 91% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs index 9eb0ebfe60..d5a4e59b7e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPool.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// /// Used to allocate and distribute re-usable blocks of memory. /// - public class MemoryPool2 : IDisposable + public class MemoryPool : IDisposable { /// /// The gap between blocks' starting address. 4096 is chosen because most operating systems are 4k pages in size and alignment. @@ -47,13 +47,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// Thread-safe collection of blocks which are currently in the pool. A slab will pre-allocate all of the block tracking objects /// and add them to this collection. When memory is requested it is taken from here first, and when it is returned it is re-added. /// - private readonly ConcurrentQueue _blocks = new ConcurrentQueue(); + private readonly ConcurrentQueue _blocks = new ConcurrentQueue(); /// /// Thread-safe collection of slabs which have been allocated by this pool. As long as a slab is in this collection and slab.IsActive, /// the blocks will be added to _blocks when returned. /// - private readonly ConcurrentStack _slabs = new ConcurrentStack(); + private readonly ConcurrentStack _slabs = new ConcurrentStack(); /// /// This is part of implementing the IDisposable pattern. @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// The block returned must be at least this size. It may be larger than this minimum size, and if so, /// the caller may write to the block's entire size rather than being limited to the minumumSize requested. /// The block that is reserved for the called. It must be passed to Return when it is no longer being used. - public MemoryPoolBlock2 Lease(int minimumSize = MaxPooledBlockLength) + public MemoryPoolBlock Lease(int minimumSize = MaxPooledBlockLength) { if (minimumSize > _blockLength) { @@ -74,14 +74,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure // Because this is the degenerate case, a one-time-use byte[] array and tracking object are allocated. // When this block tracking object is returned it is not added to the pool - instead it will be // allowed to be garbage collected normally. - return MemoryPoolBlock2.Create( + return MemoryPoolBlock.Create( new ArraySegment(new byte[minimumSize]), dataPtr: IntPtr.Zero, pool: this, slab: null); } - MemoryPoolBlock2 block; + MemoryPoolBlock block; if (_blocks.TryDequeue(out block)) { // block successfully taken from the stack - return it @@ -95,9 +95,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// Internal method called when a block is requested and the pool is empty. It allocates one additional slab, creates all of the /// block tracking objects, and adds them all to the pool. /// - private MemoryPoolBlock2 AllocateSlab() + private MemoryPoolBlock AllocateSlab() { - var slab = MemoryPoolSlab2.Create(_slabLength); + var slab = MemoryPoolSlab.Create(_slabLength); _slabs.Push(slab); var basePtr = slab.ArrayPtr; @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure offset + _blockLength < poolAllocationLength; offset += _blockStride) { - var block = MemoryPoolBlock2.Create( + var block = MemoryPoolBlock.Create( new ArraySegment(slab.Array, offset, _blockLength), basePtr, this, @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } // return last block rather than adding to pool - var newBlock = MemoryPoolBlock2.Create( + var newBlock = MemoryPoolBlock.Create( new ArraySegment(slab.Array, offset, _blockLength), basePtr, this, @@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// leaving "dead zones" in the slab due to lost block tracking objects. /// /// The block to return. It must have been acquired by calling Lease on the same memory pool instance. - public void Return(MemoryPoolBlock2 block) + public void Return(MemoryPoolBlock block) { Debug.Assert(block.Pool == this, "Returned block was not leased from this pool"); @@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { if (disposing) { - MemoryPoolSlab2 slab; + MemoryPoolSlab slab; while (_slabs.TryPop(out slab)) { // dispose managed state (managed objects). diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs similarity index 92% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs index 0dead6c6ae..25cab8c4f4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolBlock.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The /// individual blocks are then treated as independant array segments. /// - public class MemoryPoolBlock2 + public class MemoryPoolBlock { /// /// If this block represents a one-time-use memory object, this GCHandle will hold that memory object at a fixed address @@ -33,19 +33,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// /// This object cannot be instantiated outside of the static Create method /// - protected MemoryPoolBlock2() + protected MemoryPoolBlock() { } /// /// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool. /// - public MemoryPool2 Pool { get; private set; } + public MemoryPool Pool { get; private set; } /// /// Back-reference to the slab from which this block was taken, or null if it is one-time-use memory. /// - public MemoryPoolSlab2 Slab { get; private set; } + public MemoryPoolSlab Slab { get; private set; } /// /// Convenience accessor @@ -72,9 +72,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// working memory. The "active" memory is grown when bytes are copied in, End is increased, and Next is assigned. The "active" /// memory is shrunk when bytes are consumed, Start is increased, and blocks are returned to the pool. /// - public MemoryPoolBlock2 Next { get; set; } + public MemoryPoolBlock Next { get; set; } - ~MemoryPoolBlock2() + ~MemoryPoolBlock() { Debug.Assert(!_pinHandle.IsAllocated, "Ad-hoc memory block wasn't unpinned"); Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool"); @@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure if (Slab != null && Slab.IsActive) { - Pool.Return(new MemoryPoolBlock2 + Pool.Return(new MemoryPoolBlock { _dataArrayPtr = _dataArrayPtr, Data = Data, @@ -130,13 +130,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public static MemoryPoolBlock2 Create( + public static MemoryPoolBlock Create( ArraySegment data, IntPtr dataPtr, - MemoryPool2 pool, - MemoryPoolSlab2 slab) + MemoryPool pool, + MemoryPoolSlab slab) { - return new MemoryPoolBlock2 + return new MemoryPoolBlock { Data = data, _dataArrayPtr = dataPtr, @@ -170,9 +170,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// acquires a cursor pointing into this block at the Start of "active" byte information /// /// - public MemoryPoolIterator2 GetIterator() + public MemoryPoolIterator GetIterator() { - return new MemoryPoolIterator2(this); + return new MemoryPoolIterator(this); } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs index 8e22ee4018..286862ce4b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator.cs @@ -7,19 +7,19 @@ using System.Numerics; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { - public struct MemoryPoolIterator2 + public struct MemoryPoolIterator { private static readonly int _vectorSpan = Vector.Count; - private MemoryPoolBlock2 _block; + private MemoryPoolBlock _block; private int _index; - public MemoryPoolIterator2(MemoryPoolBlock2 block) + public MemoryPoolIterator(MemoryPoolBlock block) { _block = block; _index = _block?.Start ?? 0; } - public MemoryPoolIterator2(MemoryPoolBlock2 block, int index) + public MemoryPoolIterator(MemoryPoolBlock block, int index) { _block = block; _index = index; @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public MemoryPoolBlock2 Block => _block; + public MemoryPoolBlock Block => _block; public int Index => _index; @@ -634,7 +634,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public int GetLength(MemoryPoolIterator2 end) + public int GetLength(MemoryPoolIterator end) { if (IsDefault || end.IsDefault) { @@ -666,7 +666,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public MemoryPoolIterator2 CopyTo(byte[] array, int offset, int count, out int actual) + public MemoryPoolIterator CopyTo(byte[] array, int offset, int count, out int actual) { if (IsDefault) { @@ -687,7 +687,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { Buffer.BlockCopy(block.Array, index, array, offset, remaining); } - return new MemoryPoolIterator2(block, index + remaining); + return new MemoryPoolIterator(block, index + remaining); } else if (block.Next == null) { @@ -696,7 +696,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { Buffer.BlockCopy(block.Array, index, array, offset, following); } - return new MemoryPoolIterator2(block, index + following); + return new MemoryPoolIterator(block, index + following); } else { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs similarity index 97% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs index 7581ff35f2..1f9b3dcd7a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIterator2Extensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolIteratorExtensions.cs @@ -7,7 +7,7 @@ using System.Text; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { - public static class MemoryPoolIterator2Extensions + public static class MemoryPoolIteratorExtensions { private static readonly Encoding _utf8 = Encoding.UTF8; @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure private readonly static Tuple[] _knownMethods = new Tuple[8]; - static MemoryPoolIterator2Extensions() + static MemoryPoolIteratorExtensions() { _knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpPutMethod); _knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpPostMethod); @@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public unsafe static string GetAsciiString(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) + public unsafe static string GetAsciiString(this MemoryPoolIterator start, MemoryPoolIterator end) { if (start.IsDefault || end.IsDefault) { @@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure return asciiString; } - public static string GetUtf8String(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) + public static string GetUtf8String(this MemoryPoolIterator start, MemoryPoolIterator end) { if (start.IsDefault || end.IsDefault) { @@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } } - public static ArraySegment GetArraySegment(this MemoryPoolIterator2 start, MemoryPoolIterator2 end) + public static ArraySegment GetArraySegment(this MemoryPoolIterator start, MemoryPoolIterator end) { if (start.IsDefault || end.IsDefault) { @@ -295,7 +295,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// If we found a valid method, then scan will be updated to new position /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. - public static bool GetKnownMethod(this MemoryPoolIterator2 begin, ref MemoryPoolIterator2 scan, out string knownMethod) + public static bool GetKnownMethod(this MemoryPoolIterator begin, ref MemoryPoolIterator scan, out string knownMethod) { knownMethod = null; var value = begin.PeekLong(); @@ -333,7 +333,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// If we found a valid method, then scan will be updated to new position /// A reference to a pre-allocated known string, if the input matches any. /// true if the input matches a known string, false otherwise. - public static bool GetKnownVersion(this MemoryPoolIterator2 begin, ref MemoryPoolIterator2 scan, out string knownVersion) + public static bool GetKnownVersion(this MemoryPoolIterator begin, ref MemoryPoolIterator scan, out string knownVersion) { knownVersion = null; var value = begin.PeekLong(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab.cs similarity index 95% rename from src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs rename to src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab.cs index c7062d0977..d0acab4d6c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab2.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/MemoryPoolSlab.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// Slab tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The /// individual blocks are then treated as independant array segments. /// - public class MemoryPoolSlab2 : IDisposable + public class MemoryPoolSlab : IDisposable { /// /// This handle pins the managed array in memory until the slab is disposed. This prevents it from being @@ -41,14 +41,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure /// private bool _disposedValue = false; // To detect redundant calls - public static MemoryPoolSlab2 Create(int length) + public static MemoryPoolSlab Create(int length) { // allocate and pin requested memory length var array = new byte[length]; var gcHandle = GCHandle.Alloc(array, GCHandleType.Pinned); // allocate and return slab tracking object - return new MemoryPoolSlab2 + return new MemoryPoolSlab { Array = array, _gcHandle = gcHandle, @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure } // override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. - ~MemoryPoolSlab2() + ~MemoryPoolSlab() { // Do not change this code. Put cleanup code in Dispose(bool disposing) above. Dispose(false); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs index 576fce68c2..bf088950a5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/UvWriteReq.cs @@ -41,8 +41,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking public unsafe void Write( UvStreamHandle handle, - MemoryPoolIterator2 start, - MemoryPoolIterator2 end, + MemoryPoolIterator start, + MemoryPoolIterator end, int nBuffers, Action callback, object state) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs index 4664053bf8..10e95d2e56 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/AsciiDecoder.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var byteRange = Enumerable.Range(0, 256).Select(x => (byte)x).ToArray(); - var mem = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); mem.End = byteRange.Length; var begin = mem.GetIterator(); @@ -44,10 +44,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests .Concat(byteRange) .ToArray(); - var mem0 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem1 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem2 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem3 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem0 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem1 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem2 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem3 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); mem0.End = byteRange.Length; mem1.End = byteRange.Length; mem2.End = byteRange.Length; @@ -79,8 +79,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var byteRange = Enumerable.Range(0, 16384 + 64).Select(x => (byte)x).ToArray(); var expectedByteRange = byteRange.Concat(byteRange).ToArray(); - var mem0 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); - var mem1 = MemoryPoolBlock2.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem0 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); + var mem1 = MemoryPoolBlock.Create(new ArraySegment(byteRange), IntPtr.Zero, null, null); mem0.End = byteRange.Length; mem1.End = byteRange.Length; @@ -102,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - private MemoryPoolIterator2 GetIterator(MemoryPoolIterator2 begin, int displacement) + private MemoryPoolIterator GetIterator(MemoryPoolIterator begin, int displacement) { var result = begin; for (int i = 0; i < displacement; ++i) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs index 203a807267..3b710b508b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var mockLibuv = new MockLibuv(); - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var engine = new KestrelEngine(mockLibuv, new TestServiceContext())) { engine.Start(count: 1); @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { FrameFactory = connectionContext => new Frame( new DummyApplication(httpContext => TaskUtilities.CompletedTask), connectionContext), - Memory2 = memory, + Memory = memory, ServerAddress = ServerAddress.FromUrl($"http://localhost:{TestServer.GetNextPort()}"), Thread = engine.Threads[0] }; diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs index 78d46f5d6c..8d6133a5f3 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) using (var socketInput = new SocketInput(pool, ltp)) { var connectionContext = new ConnectionContext() diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs similarity index 95% rename from test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs index f5f58465b9..73bb3b2ef8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlock2Tests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolBlockTests.cs @@ -6,12 +6,12 @@ using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class MemoryPoolBlock2Tests + public class MemoryPoolBlockTests { [Fact] public void SeekWorks() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block = pool.Lease(256); foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x)) @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Console.WriteLine($"Vector.IsHardwareAccelerated == {Vector.IsHardwareAccelerated}"); Console.WriteLine($"Vector.Count == {Vector.Count}"); - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block1 = pool.Lease(256); var block2 = block1.Next = pool.Lease(256); @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void GetLengthBetweenIteratorsWorks() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block = pool.Lease(256); block.End += 256; @@ -148,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - private void TestAllLengths(MemoryPoolBlock2 block, int lengths) + private void TestAllLengths(MemoryPoolBlock block, int lengths) { for (var firstIndex = 0; firstIndex <= lengths; ++firstIndex) { @@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void AddDoesNotAdvanceAtEndOfCurrentBlock() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block1 = pool.Lease(256); var block2 = block1.Next = pool.Lease(256); @@ -207,7 +207,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void CopyToCorrectlyTraversesBlocks() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block1 = pool.Lease(128); var block2 = block1.Next = pool.Lease(128); @@ -245,7 +245,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void CopyFromCorrectlyTraversesBlocks() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block1 = pool.Lease(128); var start = block1.GetIterator(); @@ -287,7 +287,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void IsEndCorrectlyTraversesBlocks() { - using (var pool = new MemoryPool2()) + using (var pool = new MemoryPool()) { var block1 = pool.Lease(128); var block2 = block1.Next = pool.Lease(128); @@ -313,7 +313,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } } - private void AssertIterator(MemoryPoolIterator2 iter, MemoryPoolBlock2 block, int index) + private void AssertIterator(MemoryPoolIterator iter, MemoryPoolBlock block, int index) { Assert.Same(block, iter.Block); Assert.Equal(index, iter.Index); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs index d822185aee..e2cd3bdfa8 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolExtensions.cs @@ -4,7 +4,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { public static class MemoryPoolExtensions { - public static MemoryPoolIterator2 Add(this MemoryPoolIterator2 iterator, int count) + public static MemoryPoolIterator Add(this MemoryPoolIterator iterator, int count) { int actual; return iterator.CopyTo(new byte[count], 0, count, out actual); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs similarity index 92% rename from test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs rename to test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 90d66690e9..18fdeb5afd 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -6,13 +6,13 @@ using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests { - public class MemoryPoolIterator2Tests : IDisposable + public class MemoryPoolIteratorTests : IDisposable { - private readonly MemoryPool2 _pool; + private readonly MemoryPool _pool; - public MemoryPoolIterator2Tests() + public MemoryPoolIteratorTests() { - _pool = new MemoryPool2(); + _pool = new MemoryPool(); } public void Dispose() @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (int i = 0; i < Vector.Count; i++) { Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByte(ref vector)); + Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByte(ref vector)); bytes[i] = 0; } @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { bytes[i] = 1; Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByte(ref vector)); + Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByte(ref vector)); bytes[i] = 0; } } @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests for (int i = 0; i < Vector.Count; i++) { Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByteSlow(ref vector)); + Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByteSlow(ref vector)); bytes[i] = 0; } @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { bytes[i] = 1; Vector vector = new Vector(bytes); - Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByteSlow(ref vector)); + Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByteSlow(ref vector)); bytes[i] = 0; } } @@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void Put() { - var blocks = new MemoryPoolBlock2[4]; + var blocks = new MemoryPoolBlock[4]; for (var i = 0; i < 4; ++i) { blocks[i] = _pool.Lease(16); @@ -286,15 +286,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [InlineData("CONNECT / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpConnectMethod)] - [InlineData("DELETE / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpDeleteMethod)] - [InlineData("GET / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpGetMethod)] - [InlineData("HEAD / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpHeadMethod)] - [InlineData("PATCH / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPatchMethod)] - [InlineData("POST / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPostMethod)] - [InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPutMethod)] - [InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpOptionsMethod)] - [InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpTraceMethod)] + [InlineData("CONNECT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpConnectMethod)] + [InlineData("DELETE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpDeleteMethod)] + [InlineData("GET / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpGetMethod)] + [InlineData("HEAD / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpHeadMethod)] + [InlineData("PATCH / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPatchMethod)] + [InlineData("POST / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPostMethod)] + [InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPutMethod)] + [InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpOptionsMethod)] + [InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpTraceMethod)] [InlineData("GET/ HTTP/1.1", ' ', false, null)] [InlineData("get / HTTP/1.1", ' ', false, null)] [InlineData("GOT / HTTP/1.1", ' ', false, null)] @@ -324,8 +324,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Theory] - [InlineData("HTTP/1.0\r", '\r', true, MemoryPoolIterator2Extensions.Http10Version)] - [InlineData("HTTP/1.1\r", '\r', true, MemoryPoolIterator2Extensions.Http11Version)] + [InlineData("HTTP/1.0\r", '\r', true, MemoryPoolIteratorExtensions.Http10Version)] + [InlineData("HTTP/1.1\r", '\r', true, MemoryPoolIteratorExtensions.Http11Version)] [InlineData("HTTP/3.0\r", '\r', false, null)] [InlineData("http/1.0\r", '\r', false, null)] [InlineData("http/1.1\r", '\r', false, null)] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs index 790d654fca..c5b8c30c5b 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MultipleLoopTests.cs @@ -64,13 +64,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); writeRequest.Init(loop); - var block = MemoryPoolBlock2.Create( + var block = MemoryPoolBlock.Create( new ArraySegment(new byte[] { 1, 2, 3, 4 }), dataPtr: IntPtr.Zero, pool: null, slab: null); - var start = new MemoryPoolIterator2(block, 0); - var end = new MemoryPoolIterator2(block, block.Data.Count); + var start = new MemoryPoolIterator(block, 0); + var end = new MemoryPoolIterator(block, block.Data.Count); writeRequest.Write( serverConnectionPipe, start, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs index 33ff9b70d9..c299331818 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs @@ -178,13 +178,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); req.Init(loop); - var block = MemoryPoolBlock2.Create( + var block = MemoryPoolBlock.Create( new ArraySegment(new byte[] { 65, 66, 67, 68, 69 }), dataPtr: IntPtr.Zero, pool: null, slab: null); - var start = new MemoryPoolIterator2(block, 0); - var end = new MemoryPoolIterator2(block, block.Data.Count); + var start = new MemoryPoolIterator(block, 0); + var end = new MemoryPoolIterator(block, block.Data.Count); req.Write( tcp2, start, diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs index 29e2597f5f..2a0d792051 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketInputTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests // Arrange var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - using (var memory2 = new MemoryPool2()) + using (var memory2 = new MemoryPool()) using (var socketInput = new SocketInput(memory2, ltp)) { var task0Threw = false; @@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests [Fact] public void ConsumingOutOfOrderFailsGracefully() { - var defultIter = new MemoryPoolIterator2(); + var defultIter = new MemoryPoolIterator(); // Calling ConsumingComplete without a preceding calling to ConsumingStart fails using (var socketInput = new SocketInput(null, null)) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index f0132e0c82..853b22f577 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -152,7 +152,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -225,7 +225,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -335,7 +335,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -423,7 +423,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -509,7 +509,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } }; - using (var memory = new MemoryPool2()) + using (var memory = new MemoryPool()) using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext())) { kestrelEngine.Start(count: 1); @@ -529,7 +529,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests block2.End = block2.Data.Offset + block2.Data.Count; start.Block.Next = block2; - var end = new MemoryPoolIterator2(block2, block2.End); + var end = new MemoryPoolIterator(block2, block2.End); socketOutput.ProducingComplete(end); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 3214c94ed8..764e0a521c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { class TestInput : IConnectionControl, IFrameControl, IDisposable { - private MemoryPool2 _memoryPool; + private MemoryPool _memoryPool; public TestInput() { @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests }; FrameContext = new Frame(null, context); - _memoryPool = new MemoryPool2(); + _memoryPool = new MemoryPool(); FrameContext.SocketInput = new SocketInput(_memoryPool, ltp); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs index aab03b1a21..711297fd95 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/UrlPathDecoder.cs @@ -120,16 +120,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests Assert.Equal(expect, result); } - private MemoryPoolIterator2 BuildSample(string data) + private MemoryPoolIterator BuildSample(string data) { var store = data.Select(c => (byte)c).ToArray(); - var mem = MemoryPoolBlock2.Create(new ArraySegment(store), IntPtr.Zero, null, null); + var mem = MemoryPoolBlock.Create(new ArraySegment(store), IntPtr.Zero, null, null); mem.End = store.Length; return mem.GetIterator(); } - private MemoryPoolIterator2 GetIterator(MemoryPoolIterator2 begin, int displacement) + private MemoryPoolIterator GetIterator(MemoryPoolIterator begin, int displacement) { var result = begin; for (int i = 0; i < displacement; ++i) diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index 1593da3ac4..9f47fdfae0 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -390,7 +390,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); }} {(loop.ClassName == "FrameResponseHeaders" ? $@" - protected void CopyToFast(ref MemoryPoolIterator2 output) + protected void CopyToFast(ref MemoryPoolIterator output) {{ {Each(loop.Headers, header => $@" if ({header.TestBit()})