Remove 2 from MemoryPool2 and related types
- This was merely an artifact from when this was the second of 2 pools
This commit is contained in:
parent
bb2e76c7f1
commit
f15471bcf2
|
|
@ -15,12 +15,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter
|
||||||
private readonly Stream _filteredStream;
|
private readonly Stream _filteredStream;
|
||||||
private readonly Stream _socketInputStream;
|
private readonly Stream _socketInputStream;
|
||||||
private readonly IKestrelTrace _log;
|
private readonly IKestrelTrace _log;
|
||||||
private readonly MemoryPool2 _memory;
|
private readonly MemoryPool _memory;
|
||||||
private MemoryPoolBlock2 _block;
|
private MemoryPoolBlock _block;
|
||||||
|
|
||||||
public FilteredStreamAdapter(
|
public FilteredStreamAdapter(
|
||||||
Stream filteredStream,
|
Stream filteredStream,
|
||||||
MemoryPool2 memory,
|
MemoryPool memory,
|
||||||
IKestrelTrace logger,
|
IKestrelTrace logger,
|
||||||
IThreadPool threadPool)
|
IThreadPool threadPool)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter
|
||||||
{
|
{
|
||||||
public static class StreamExtensions
|
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;
|
int bytesRead;
|
||||||
while ((bytesRead = await source.ReadAsync(block.Array, block.Data.Offset, block.Data.Count)) != 0)
|
while ((bytesRead = await source.ReadAsync(block.Array, block.Data.Offset, block.Data.Count)) != 0)
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter
|
||||||
private static readonly byte[] _nullBuffer = new byte[0];
|
private static readonly byte[] _nullBuffer = new byte[0];
|
||||||
|
|
||||||
private readonly Stream _outputStream;
|
private readonly Stream _outputStream;
|
||||||
private readonly MemoryPool2 _memory;
|
private readonly MemoryPool _memory;
|
||||||
private MemoryPoolBlock2 _producingBlock;
|
private MemoryPoolBlock _producingBlock;
|
||||||
|
|
||||||
private object _writeLock = new object();
|
private object _writeLock = new object();
|
||||||
|
|
||||||
public StreamSocketOutput(Stream outputStream, MemoryPool2 memory)
|
public StreamSocketOutput(Stream outputStream, MemoryPool memory)
|
||||||
{
|
{
|
||||||
_outputStream = outputStream;
|
_outputStream = outputStream;
|
||||||
_memory = memory;
|
_memory = memory;
|
||||||
|
|
@ -54,13 +54,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter
|
||||||
return TaskUtilities.CompletedTask;
|
return TaskUtilities.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemoryPoolIterator2 ProducingStart()
|
public MemoryPoolIterator ProducingStart()
|
||||||
{
|
{
|
||||||
_producingBlock = _memory.Lease();
|
_producingBlock = _memory.Lease();
|
||||||
return new MemoryPoolIterator2(_producingBlock);
|
return new MemoryPoolIterator(_producingBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProducingComplete(MemoryPoolIterator2 end)
|
public void ProducingComplete(MemoryPoolIterator end)
|
||||||
{
|
{
|
||||||
var block = _producingBlock;
|
var block = _producingBlock;
|
||||||
while (block != end.Block)
|
while (block != end.Block)
|
||||||
|
|
|
||||||
|
|
@ -47,14 +47,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
return new ArraySegment<byte>(bytes, offset, 10 - offset);
|
return new ArraySegment<byte>(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);
|
var chunkSegment = BeginChunkBytes(dataCount);
|
||||||
start.CopyFrom(chunkSegment);
|
start.CopyFrom(chunkSegment);
|
||||||
return chunkSegment.Count;
|
return chunkSegment.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteEndChunkBytes(ref MemoryPoolIterator2 start)
|
public static void WriteEndChunkBytes(ref MemoryPoolIterator start)
|
||||||
{
|
{
|
||||||
start.CopyFrom(_endChunkBytes);
|
start.CopyFrom(_endChunkBytes);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
|
|
||||||
ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId));
|
ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId));
|
||||||
|
|
||||||
_rawSocketInput = new SocketInput(Memory2, ThreadPool);
|
_rawSocketInput = new SocketInput(Memory, ThreadPool);
|
||||||
_rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, ConnectionId, Log, ThreadPool, WriteReqPool);
|
_rawSocketOutput = new SocketOutput(Thread, _socket, Memory, this, ConnectionId, Log, ThreadPool, WriteReqPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal for testing
|
// Internal for testing
|
||||||
|
|
@ -206,7 +206,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
|
|
||||||
if (_filterContext.Connection != _libuvStream)
|
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;
|
SocketInput = filteredStreamAdapter.SocketInput;
|
||||||
SocketOutput = filteredStreamAdapter.SocketOutput;
|
SocketOutput = filteredStreamAdapter.SocketOutput;
|
||||||
|
|
|
||||||
|
|
@ -8993,7 +8993,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
((ICollection<KeyValuePair<string, StringValues>>)MaybeUnknown)?.CopyTo(array, arrayIndex);
|
((ICollection<KeyValuePair<string, StringValues>>)MaybeUnknown)?.CopyTo(array, arrayIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void CopyToFast(ref MemoryPoolIterator2 output)
|
protected void CopyToFast(ref MemoryPoolIterator output)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (((_bits & 1L) != 0))
|
if (((_bits & 1L) != 0))
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
return GetEnumerator();
|
return GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CopyTo(ref MemoryPoolIterator2 output)
|
public void CopyTo(ref MemoryPoolIterator output)
|
||||||
{
|
{
|
||||||
CopyToFast(ref output);
|
CopyToFast(ref output);
|
||||||
if (MaybeUnknown != null)
|
if (MaybeUnknown != null)
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns an iterator pointing to the tail of the response buffer. Response data can be appended
|
/// Returns an iterator pointing to the tail of the response buffer. Response data can be appended
|
||||||
/// manually or by using <see cref="MemoryPoolIterator2.CopyFrom(ArraySegment{byte})"/>.
|
/// manually or by using <see cref="MemoryPoolIterator.CopyFrom(ArraySegment{byte})"/>.
|
||||||
/// Be careful to ensure all appended blocks are backed by a <see cref="MemoryPoolSlab2"/>.
|
/// Be careful to ensure all appended blocks are backed by a <see cref="MemoryPoolSlab"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
MemoryPoolIterator2 ProducingStart();
|
MemoryPoolIterator ProducingStart();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Commits the response data appended to the iterator returned from <see cref="ProducingStart"/>.
|
/// Commits the response data appended to the iterator returned from <see cref="ProducingStart"/>.
|
||||||
|
|
@ -30,6 +30,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
/// or <see cref="WriteAsync(ArraySegment{byte}, bool, CancellationToken)"/> is called afterwards.
|
/// or <see cref="WriteAsync(ArraySegment{byte}, bool, CancellationToken)"/> is called afterwards.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="end">Points to the end of the committed data.</param>
|
/// <param name="end">Points to the end of the committed data.</param>
|
||||||
void ProducingComplete(MemoryPoolIterator2 end);
|
void ProducingComplete(MemoryPoolIterator end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Memory2.Dispose();
|
Memory.Dispose();
|
||||||
ListenSocket = null;
|
ListenSocket = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
public ListenerContext(ServiceContext serviceContext)
|
public ListenerContext(ServiceContext serviceContext)
|
||||||
: base(serviceContext)
|
: base(serviceContext)
|
||||||
{
|
{
|
||||||
Memory2 = new MemoryPool2();
|
Memory = new MemoryPool();
|
||||||
WriteReqPool = new Queue<UvWriteReq>(SocketOutput.MaxPooledWriteReqs);
|
WriteReqPool = new Queue<UvWriteReq>(SocketOutput.MaxPooledWriteReqs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
ServerAddress = listenerContext.ServerAddress;
|
ServerAddress = listenerContext.ServerAddress;
|
||||||
Thread = listenerContext.Thread;
|
Thread = listenerContext.Thread;
|
||||||
Memory2 = listenerContext.Memory2;
|
Memory = listenerContext.Memory;
|
||||||
ConnectionManager = listenerContext.ConnectionManager;
|
ConnectionManager = listenerContext.ConnectionManager;
|
||||||
WriteReqPool = listenerContext.WriteReqPool;
|
WriteReqPool = listenerContext.WriteReqPool;
|
||||||
Log = listenerContext.Log;
|
Log = listenerContext.Log;
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
|
|
||||||
public KestrelThread Thread { get; set; }
|
public KestrelThread Thread { get; set; }
|
||||||
|
|
||||||
public MemoryPool2 Memory2 { get; set; }
|
public MemoryPool Memory { get; set; }
|
||||||
|
|
||||||
public ConnectionManager ConnectionManager { get; set; }
|
public ConnectionManager ConnectionManager { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
FreeBuffer();
|
FreeBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
Memory2.Dispose();
|
Memory.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,20 +16,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
private static readonly Action _awaitableIsCompleted = () => { };
|
private static readonly Action _awaitableIsCompleted = () => { };
|
||||||
private static readonly Action _awaitableIsNotCompleted = () => { };
|
private static readonly Action _awaitableIsNotCompleted = () => { };
|
||||||
|
|
||||||
private readonly MemoryPool2 _memory;
|
private readonly MemoryPool _memory;
|
||||||
private readonly IThreadPool _threadPool;
|
private readonly IThreadPool _threadPool;
|
||||||
private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false, 0);
|
private readonly ManualResetEventSlim _manualResetEvent = new ManualResetEventSlim(false, 0);
|
||||||
|
|
||||||
private Action _awaitableState;
|
private Action _awaitableState;
|
||||||
private Exception _awaitableError;
|
private Exception _awaitableError;
|
||||||
|
|
||||||
private MemoryPoolBlock2 _head;
|
private MemoryPoolBlock _head;
|
||||||
private MemoryPoolBlock2 _tail;
|
private MemoryPoolBlock _tail;
|
||||||
private MemoryPoolBlock2 _pinned;
|
private MemoryPoolBlock _pinned;
|
||||||
|
|
||||||
private int _consumingState;
|
private int _consumingState;
|
||||||
|
|
||||||
public SocketInput(MemoryPool2 memory, IThreadPool threadPool)
|
public SocketInput(MemoryPool memory, IThreadPool threadPool)
|
||||||
{
|
{
|
||||||
_memory = memory;
|
_memory = memory;
|
||||||
_threadPool = threadPool;
|
_threadPool = threadPool;
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
|
|
||||||
public bool IsCompleted => ReferenceEquals(_awaitableState, _awaitableIsCompleted);
|
public bool IsCompleted => ReferenceEquals(_awaitableState, _awaitableIsCompleted);
|
||||||
|
|
||||||
public MemoryPoolBlock2 IncomingStart()
|
public MemoryPoolBlock IncomingStart()
|
||||||
{
|
{
|
||||||
const int minimumSize = 2048;
|
const int minimumSize = 2048;
|
||||||
|
|
||||||
|
|
@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
_tail = _memory.Lease();
|
_tail = _memory.Lease();
|
||||||
}
|
}
|
||||||
|
|
||||||
var iterator = new MemoryPoolIterator2(_tail, _tail.End);
|
var iterator = new MemoryPoolIterator(_tail, _tail.End);
|
||||||
iterator.CopyFrom(buffer, offset, count);
|
iterator.CopyFrom(buffer, offset, count);
|
||||||
|
|
||||||
if (_head == null)
|
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)
|
if (Interlocked.CompareExchange(ref _consumingState, 1, 0) != 0)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Already consuming input.");
|
throw new InvalidOperationException("Already consuming input.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MemoryPoolIterator2(_head);
|
return new MemoryPoolIterator(_head);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ConsumingComplete(
|
public void ConsumingComplete(
|
||||||
MemoryPoolIterator2 consumed,
|
MemoryPoolIterator consumed,
|
||||||
MemoryPoolIterator2 examined)
|
MemoryPoolIterator examined)
|
||||||
{
|
{
|
||||||
MemoryPoolBlock2 returnStart = null;
|
MemoryPoolBlock returnStart = null;
|
||||||
MemoryPoolBlock2 returnEnd = null;
|
MemoryPoolBlock returnEnd = null;
|
||||||
|
|
||||||
if (!consumed.IsDefault)
|
if (!consumed.IsDefault)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
private const int _initialTaskQueues = 64;
|
private const int _initialTaskQueues = 64;
|
||||||
private const int _maxPooledWriteContexts = 32;
|
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<object> _connectionCancellation = (state) => ((SocketOutput)state).CancellationTriggered();
|
private static readonly Action<object> _connectionCancellation = (state) => ((SocketOutput)state).CancellationTriggered();
|
||||||
|
|
||||||
private readonly KestrelThread _thread;
|
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.
|
// _head does not require a lock, since it is only used in the ctor and uv thread.
|
||||||
private readonly object _returnLock = new object();
|
private readonly object _returnLock = new object();
|
||||||
|
|
||||||
private MemoryPoolBlock2 _head;
|
private MemoryPoolBlock _head;
|
||||||
private MemoryPoolBlock2 _tail;
|
private MemoryPoolBlock _tail;
|
||||||
|
|
||||||
private MemoryPoolIterator2 _lastStart;
|
private MemoryPoolIterator _lastStart;
|
||||||
|
|
||||||
// This locks access to to all of the below fields
|
// This locks access to to all of the below fields
|
||||||
private readonly object _contextLock = new object();
|
private readonly object _contextLock = new object();
|
||||||
|
|
@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
public SocketOutput(
|
public SocketOutput(
|
||||||
KestrelThread thread,
|
KestrelThread thread,
|
||||||
UvStreamHandle socket,
|
UvStreamHandle socket,
|
||||||
MemoryPool2 memory,
|
MemoryPool memory,
|
||||||
Connection connection,
|
Connection connection,
|
||||||
string connectionId,
|
string connectionId,
|
||||||
IKestrelTrace log,
|
IKestrelTrace log,
|
||||||
|
|
@ -222,7 +222,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemoryPoolIterator2 ProducingStart()
|
public MemoryPoolIterator ProducingStart()
|
||||||
{
|
{
|
||||||
lock (_returnLock)
|
lock (_returnLock)
|
||||||
{
|
{
|
||||||
|
|
@ -230,16 +230,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
|
|
||||||
if (_tail == null)
|
if (_tail == null)
|
||||||
{
|
{
|
||||||
return default(MemoryPoolIterator2);
|
return default(MemoryPoolIterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
_lastStart = new MemoryPoolIterator2(_tail, _tail.End);
|
_lastStart = new MemoryPoolIterator(_tail, _tail.End);
|
||||||
|
|
||||||
return _lastStart;
|
return _lastStart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProducingComplete(MemoryPoolIterator2 end)
|
public void ProducingComplete(MemoryPoolIterator end)
|
||||||
{
|
{
|
||||||
Debug.Assert(!_lastStart.IsDefault);
|
Debug.Assert(!_lastStart.IsDefault);
|
||||||
|
|
||||||
|
|
@ -254,9 +254,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
ProducingCompleteNoPreComplete(end);
|
ProducingCompleteNoPreComplete(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProducingCompleteNoPreComplete(MemoryPoolIterator2 end)
|
private void ProducingCompleteNoPreComplete(MemoryPoolIterator end)
|
||||||
{
|
{
|
||||||
MemoryPoolBlock2 blockToReturn = null;
|
MemoryPoolBlock blockToReturn = null;
|
||||||
|
|
||||||
|
|
||||||
lock (_returnLock)
|
lock (_returnLock)
|
||||||
|
|
@ -275,7 +275,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
blockToReturn = _lastStart.Block;
|
blockToReturn = _lastStart.Block;
|
||||||
}
|
}
|
||||||
|
|
||||||
_lastStart = default(MemoryPoolIterator2);
|
_lastStart = default(MemoryPoolIterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockToReturn != null)
|
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)
|
while (block != null)
|
||||||
{
|
{
|
||||||
|
|
@ -496,7 +496,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
return WriteAsync(buffer, cancellationToken, chunk);
|
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)
|
if (start.Block == end.Block)
|
||||||
{
|
{
|
||||||
|
|
@ -520,13 +520,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
|
|
||||||
private class WriteContext
|
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 static WaitCallback _completeWrite = (state) => ((WriteContext)state).CompleteOnThreadPool();
|
||||||
|
|
||||||
private SocketOutput Self;
|
private SocketOutput Self;
|
||||||
private UvWriteReq _writeReq;
|
private UvWriteReq _writeReq;
|
||||||
private MemoryPoolIterator2 _lockedStart;
|
private MemoryPoolIterator _lockedStart;
|
||||||
private MemoryPoolIterator2 _lockedEnd;
|
private MemoryPoolIterator _lockedEnd;
|
||||||
private int _bufferCount;
|
private int _bufferCount;
|
||||||
|
|
||||||
public int ByteCount;
|
public int ByteCount;
|
||||||
|
|
@ -698,7 +698,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
ThreadPool.QueueUserWorkItem(_returnWrittenBlocks, _lockedStart.Block);
|
ThreadPool.QueueUserWorkItem(_returnWrittenBlocks, _lockedStart.Block);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ReturnWrittenBlocks(MemoryPoolBlock2 block)
|
private static void ReturnWrittenBlocks(MemoryPoolBlock block)
|
||||||
{
|
{
|
||||||
while (block != null)
|
while (block != null)
|
||||||
{
|
{
|
||||||
|
|
@ -722,16 +722,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_lockedStart = new MemoryPoolIterator2(head, head.Start);
|
_lockedStart = new MemoryPoolIterator(head, head.Start);
|
||||||
_lockedEnd = new MemoryPoolIterator2(tail, tail.End);
|
_lockedEnd = new MemoryPoolIterator(tail, tail.End);
|
||||||
|
|
||||||
BytesBetween(_lockedStart, _lockedEnd, out ByteCount, out _bufferCount);
|
BytesBetween(_lockedStart, _lockedEnd, out ByteCount, out _bufferCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
_lockedStart = default(MemoryPoolIterator2);
|
_lockedStart = default(MemoryPoolIterator);
|
||||||
_lockedEnd = default(MemoryPoolIterator2);
|
_lockedEnd = default(MemoryPoolIterator);
|
||||||
_bufferCount = 0;
|
_bufferCount = 0;
|
||||||
ByteCount = 0;
|
ByteCount = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
/// <param name="start">The iterator points to the beginning of the sequence.</param>
|
/// <param name="start">The iterator points to the beginning of the sequence.</param>
|
||||||
/// <param name="end">The iterator points to the byte behind the end of the sequence.</param>
|
/// <param name="end">The iterator points to the byte behind the end of the sequence.</param>
|
||||||
/// <returns>The iterator points to the byte behind the end of the processed sequence.</returns>
|
/// <returns>The iterator points to the byte behind the end of the processed sequence.</returns>
|
||||||
public static MemoryPoolIterator2 Unescape(MemoryPoolIterator2 start, MemoryPoolIterator2 end)
|
public static MemoryPoolIterator Unescape(MemoryPoolIterator start, MemoryPoolIterator end)
|
||||||
{
|
{
|
||||||
// the slot to read the input
|
// the slot to read the input
|
||||||
var reader = start;
|
var reader = start;
|
||||||
|
|
@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
/// <param name="reader">The iterator point to the first % char</param>
|
/// <param name="reader">The iterator point to the first % char</param>
|
||||||
/// <param name="writer">The place to write to</param>
|
/// <param name="writer">The place to write to</param>
|
||||||
/// <param name="end">The end of the sequence</param>
|
/// <param name="end">The end of the sequence</param>
|
||||||
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,
|
// 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.
|
// 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;
|
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))
|
while (!CompareIterators(ref head, ref tail))
|
||||||
{
|
{
|
||||||
|
|
@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
/// <param name="scan">The value to read</param>
|
/// <param name="scan">The value to read</param>
|
||||||
/// <param name="end">The end of the sequence</param>
|
/// <param name="end">The end of the sequence</param>
|
||||||
/// <returns>The unescaped byte if success. Otherwise return -1.</returns>
|
/// <returns>The unescaped byte if success. Otherwise return -1.</returns>
|
||||||
private static int UnescapePercentEncoding(ref MemoryPoolIterator2 scan, MemoryPoolIterator2 end)
|
private static int UnescapePercentEncoding(ref MemoryPoolIterator scan, MemoryPoolIterator end)
|
||||||
{
|
{
|
||||||
if (scan.Take() != '%')
|
if (scan.Take() != '%')
|
||||||
{
|
{
|
||||||
|
|
@ -255,7 +255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
/// <param name="scan">The value to read</param>
|
/// <param name="scan">The value to read</param>
|
||||||
/// <param name="end">The end of the sequence</param>
|
/// <param name="end">The end of the sequence</param>
|
||||||
/// <returns>The hexadecimal value if successes, otherwise -1.</returns>
|
/// <returns>The hexadecimal value if successes, otherwise -1.</returns>
|
||||||
private static int ReadHex(ref MemoryPoolIterator2 scan, MemoryPoolIterator2 end)
|
private static int ReadHex(ref MemoryPoolIterator scan, MemoryPoolIterator end)
|
||||||
{
|
{
|
||||||
if (CompareIterators(ref scan, ref end))
|
if (CompareIterators(ref scan, ref end))
|
||||||
{
|
{
|
||||||
|
|
@ -297,7 +297,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
return false;
|
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
|
// uses ref parameter to save cost of copying
|
||||||
return (lhs.Block == rhs.Block) && (lhs.Index == rhs.Index);
|
return (lhs.Block == rhs.Block) && (lhs.Index == rhs.Index);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to allocate and distribute re-usable blocks of memory.
|
/// Used to allocate and distribute re-usable blocks of memory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MemoryPool2 : IDisposable
|
public class MemoryPool : IDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The gap between blocks' starting address. 4096 is chosen because most operating systems are 4k pages in size and alignment.
|
/// 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
|
/// 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.
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly ConcurrentQueue<MemoryPoolBlock2> _blocks = new ConcurrentQueue<MemoryPoolBlock2>();
|
private readonly ConcurrentQueue<MemoryPoolBlock> _blocks = new ConcurrentQueue<MemoryPoolBlock>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Thread-safe collection of slabs which have been allocated by this pool. As long as a slab is in this collection and slab.IsActive,
|
/// 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.
|
/// the blocks will be added to _blocks when returned.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly ConcurrentStack<MemoryPoolSlab2> _slabs = new ConcurrentStack<MemoryPoolSlab2>();
|
private readonly ConcurrentStack<MemoryPoolSlab> _slabs = new ConcurrentStack<MemoryPoolSlab>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is part of implementing the IDisposable pattern.
|
/// This is part of implementing the IDisposable pattern.
|
||||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
/// <param name="minimumSize">The block returned must be at least this size. It may be larger than this minimum size, and if so,
|
/// <param name="minimumSize">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.</param>
|
/// the caller may write to the block's entire size rather than being limited to the minumumSize requested.</param>
|
||||||
/// <returns>The block that is reserved for the called. It must be passed to Return when it is no longer being used.</returns>
|
/// <returns>The block that is reserved for the called. It must be passed to Return when it is no longer being used.</returns>
|
||||||
public MemoryPoolBlock2 Lease(int minimumSize = MaxPooledBlockLength)
|
public MemoryPoolBlock Lease(int minimumSize = MaxPooledBlockLength)
|
||||||
{
|
{
|
||||||
if (minimumSize > _blockLength)
|
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.
|
// 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
|
// When this block tracking object is returned it is not added to the pool - instead it will be
|
||||||
// allowed to be garbage collected normally.
|
// allowed to be garbage collected normally.
|
||||||
return MemoryPoolBlock2.Create(
|
return MemoryPoolBlock.Create(
|
||||||
new ArraySegment<byte>(new byte[minimumSize]),
|
new ArraySegment<byte>(new byte[minimumSize]),
|
||||||
dataPtr: IntPtr.Zero,
|
dataPtr: IntPtr.Zero,
|
||||||
pool: this,
|
pool: this,
|
||||||
slab: null);
|
slab: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryPoolBlock2 block;
|
MemoryPoolBlock block;
|
||||||
if (_blocks.TryDequeue(out block))
|
if (_blocks.TryDequeue(out block))
|
||||||
{
|
{
|
||||||
// block successfully taken from the stack - return it
|
// 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
|
/// 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.
|
/// block tracking objects, and adds them all to the pool.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private MemoryPoolBlock2 AllocateSlab()
|
private MemoryPoolBlock AllocateSlab()
|
||||||
{
|
{
|
||||||
var slab = MemoryPoolSlab2.Create(_slabLength);
|
var slab = MemoryPoolSlab.Create(_slabLength);
|
||||||
_slabs.Push(slab);
|
_slabs.Push(slab);
|
||||||
|
|
||||||
var basePtr = slab.ArrayPtr;
|
var basePtr = slab.ArrayPtr;
|
||||||
|
|
@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
offset + _blockLength < poolAllocationLength;
|
offset + _blockLength < poolAllocationLength;
|
||||||
offset += _blockStride)
|
offset += _blockStride)
|
||||||
{
|
{
|
||||||
var block = MemoryPoolBlock2.Create(
|
var block = MemoryPoolBlock.Create(
|
||||||
new ArraySegment<byte>(slab.Array, offset, _blockLength),
|
new ArraySegment<byte>(slab.Array, offset, _blockLength),
|
||||||
basePtr,
|
basePtr,
|
||||||
this,
|
this,
|
||||||
|
|
@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
}
|
}
|
||||||
|
|
||||||
// return last block rather than adding to pool
|
// return last block rather than adding to pool
|
||||||
var newBlock = MemoryPoolBlock2.Create(
|
var newBlock = MemoryPoolBlock.Create(
|
||||||
new ArraySegment<byte>(slab.Array, offset, _blockLength),
|
new ArraySegment<byte>(slab.Array, offset, _blockLength),
|
||||||
basePtr,
|
basePtr,
|
||||||
this,
|
this,
|
||||||
|
|
@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
/// leaving "dead zones" in the slab due to lost block tracking objects.
|
/// leaving "dead zones" in the slab due to lost block tracking objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="block">The block to return. It must have been acquired by calling Lease on the same memory pool instance.</param>
|
/// <param name="block">The block to return. It must have been acquired by calling Lease on the same memory pool instance.</param>
|
||||||
public void Return(MemoryPoolBlock2 block)
|
public void Return(MemoryPoolBlock block)
|
||||||
{
|
{
|
||||||
Debug.Assert(block.Pool == this, "Returned block was not leased from this pool");
|
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)
|
if (disposing)
|
||||||
{
|
{
|
||||||
MemoryPoolSlab2 slab;
|
MemoryPoolSlab slab;
|
||||||
while (_slabs.TryPop(out slab))
|
while (_slabs.TryPop(out slab))
|
||||||
{
|
{
|
||||||
// dispose managed state (managed objects).
|
// dispose managed state (managed objects).
|
||||||
|
|
@ -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
|
/// 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.
|
/// individual blocks are then treated as independant array segments.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MemoryPoolBlock2
|
public class MemoryPoolBlock
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If this block represents a one-time-use memory object, this GCHandle will hold that memory object at a fixed address
|
/// 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
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This object cannot be instantiated outside of the static Create method
|
/// This object cannot be instantiated outside of the static Create method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected MemoryPoolBlock2()
|
protected MemoryPoolBlock()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool.
|
/// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MemoryPool2 Pool { get; private set; }
|
public MemoryPool Pool { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Back-reference to the slab from which this block was taken, or null if it is one-time-use memory.
|
/// Back-reference to the slab from which this block was taken, or null if it is one-time-use memory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MemoryPoolSlab2 Slab { get; private set; }
|
public MemoryPoolSlab Slab { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convenience accessor
|
/// 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"
|
/// 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.
|
/// memory is shrunk when bytes are consumed, Start is increased, and blocks are returned to the pool.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
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(!_pinHandle.IsAllocated, "Ad-hoc memory block wasn't unpinned");
|
||||||
Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool");
|
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)
|
if (Slab != null && Slab.IsActive)
|
||||||
{
|
{
|
||||||
Pool.Return(new MemoryPoolBlock2
|
Pool.Return(new MemoryPoolBlock
|
||||||
{
|
{
|
||||||
_dataArrayPtr = _dataArrayPtr,
|
_dataArrayPtr = _dataArrayPtr,
|
||||||
Data = Data,
|
Data = Data,
|
||||||
|
|
@ -130,13 +130,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MemoryPoolBlock2 Create(
|
public static MemoryPoolBlock Create(
|
||||||
ArraySegment<byte> data,
|
ArraySegment<byte> data,
|
||||||
IntPtr dataPtr,
|
IntPtr dataPtr,
|
||||||
MemoryPool2 pool,
|
MemoryPool pool,
|
||||||
MemoryPoolSlab2 slab)
|
MemoryPoolSlab slab)
|
||||||
{
|
{
|
||||||
return new MemoryPoolBlock2
|
return new MemoryPoolBlock
|
||||||
{
|
{
|
||||||
Data = data,
|
Data = data,
|
||||||
_dataArrayPtr = dataPtr,
|
_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
|
/// acquires a cursor pointing into this block at the Start of "active" byte information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public MemoryPoolIterator2 GetIterator()
|
public MemoryPoolIterator GetIterator()
|
||||||
{
|
{
|
||||||
return new MemoryPoolIterator2(this);
|
return new MemoryPoolIterator(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,19 +7,19 @@ using System.Numerics;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
{
|
{
|
||||||
public struct MemoryPoolIterator2
|
public struct MemoryPoolIterator
|
||||||
{
|
{
|
||||||
private static readonly int _vectorSpan = Vector<byte>.Count;
|
private static readonly int _vectorSpan = Vector<byte>.Count;
|
||||||
|
|
||||||
private MemoryPoolBlock2 _block;
|
private MemoryPoolBlock _block;
|
||||||
private int _index;
|
private int _index;
|
||||||
|
|
||||||
public MemoryPoolIterator2(MemoryPoolBlock2 block)
|
public MemoryPoolIterator(MemoryPoolBlock block)
|
||||||
{
|
{
|
||||||
_block = block;
|
_block = block;
|
||||||
_index = _block?.Start ?? 0;
|
_index = _block?.Start ?? 0;
|
||||||
}
|
}
|
||||||
public MemoryPoolIterator2(MemoryPoolBlock2 block, int index)
|
public MemoryPoolIterator(MemoryPoolBlock block, int index)
|
||||||
{
|
{
|
||||||
_block = block;
|
_block = block;
|
||||||
_index = index;
|
_index = index;
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemoryPoolBlock2 Block => _block;
|
public MemoryPoolBlock Block => _block;
|
||||||
|
|
||||||
public int Index => _index;
|
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)
|
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)
|
if (IsDefault)
|
||||||
{
|
{
|
||||||
|
|
@ -687,7 +687,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
{
|
{
|
||||||
Buffer.BlockCopy(block.Array, index, array, offset, remaining);
|
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)
|
else if (block.Next == null)
|
||||||
{
|
{
|
||||||
|
|
@ -696,7 +696,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
{
|
{
|
||||||
Buffer.BlockCopy(block.Array, index, array, offset, following);
|
Buffer.BlockCopy(block.Array, index, array, offset, following);
|
||||||
}
|
}
|
||||||
return new MemoryPoolIterator2(block, index + following);
|
return new MemoryPoolIterator(block, index + following);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Text;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
{
|
{
|
||||||
public static class MemoryPoolIterator2Extensions
|
public static class MemoryPoolIteratorExtensions
|
||||||
{
|
{
|
||||||
private static readonly Encoding _utf8 = Encoding.UTF8;
|
private static readonly Encoding _utf8 = Encoding.UTF8;
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
|
|
||||||
private readonly static Tuple<long, long, string>[] _knownMethods = new Tuple<long, long, string>[8];
|
private readonly static Tuple<long, long, string>[] _knownMethods = new Tuple<long, long, string>[8];
|
||||||
|
|
||||||
static MemoryPoolIterator2Extensions()
|
static MemoryPoolIteratorExtensions()
|
||||||
{
|
{
|
||||||
_knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpPutMethod);
|
_knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpPutMethod);
|
||||||
_knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpPostMethod);
|
_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)
|
if (start.IsDefault || end.IsDefault)
|
||||||
{
|
{
|
||||||
|
|
@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
return asciiString;
|
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)
|
if (start.IsDefault || end.IsDefault)
|
||||||
{
|
{
|
||||||
|
|
@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArraySegment<byte> GetArraySegment(this MemoryPoolIterator2 start, MemoryPoolIterator2 end)
|
public static ArraySegment<byte> GetArraySegment(this MemoryPoolIterator start, MemoryPoolIterator end)
|
||||||
{
|
{
|
||||||
if (start.IsDefault || end.IsDefault)
|
if (start.IsDefault || end.IsDefault)
|
||||||
{
|
{
|
||||||
|
|
@ -295,7 +295,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
/// <param name="scan">If we found a valid method, then scan will be updated to new position</param>
|
/// <param name="scan">If we found a valid method, then scan will be updated to new position</param>
|
||||||
/// <param name="knownMethod">A reference to a pre-allocated known string, if the input matches any.</param>
|
/// <param name="knownMethod">A reference to a pre-allocated known string, if the input matches any.</param>
|
||||||
/// <returns><c>true</c> if the input matches a known string, <c>false</c> otherwise.</returns>
|
/// <returns><c>true</c> if the input matches a known string, <c>false</c> otherwise.</returns>
|
||||||
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;
|
knownMethod = null;
|
||||||
var value = begin.PeekLong();
|
var value = begin.PeekLong();
|
||||||
|
|
@ -333,7 +333,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
/// <param name="scan">If we found a valid method, then scan will be updated to new position</param>
|
/// <param name="scan">If we found a valid method, then scan will be updated to new position</param>
|
||||||
/// <param name="knownVersion">A reference to a pre-allocated known string, if the input matches any.</param>
|
/// <param name="knownVersion">A reference to a pre-allocated known string, if the input matches any.</param>
|
||||||
/// <returns><c>true</c> if the input matches a known string, <c>false</c> otherwise.</returns>
|
/// <returns><c>true</c> if the input matches a known string, <c>false</c> otherwise.</returns>
|
||||||
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;
|
knownVersion = null;
|
||||||
var value = begin.PeekLong();
|
var value = begin.PeekLong();
|
||||||
|
|
@ -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
|
/// 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.
|
/// individual blocks are then treated as independant array segments.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MemoryPoolSlab2 : IDisposable
|
public class MemoryPoolSlab : IDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This handle pins the managed array in memory until the slab is disposed. This prevents it from being
|
/// 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
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool _disposedValue = false; // To detect redundant calls
|
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
|
// allocate and pin requested memory length
|
||||||
var array = new byte[length];
|
var array = new byte[length];
|
||||||
var gcHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
|
var gcHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
|
||||||
|
|
||||||
// allocate and return slab tracking object
|
// allocate and return slab tracking object
|
||||||
return new MemoryPoolSlab2
|
return new MemoryPoolSlab
|
||||||
{
|
{
|
||||||
Array = array,
|
Array = array,
|
||||||
_gcHandle = gcHandle,
|
_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.
|
// 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.
|
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
|
||||||
Dispose(false);
|
Dispose(false);
|
||||||
|
|
@ -41,8 +41,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking
|
||||||
|
|
||||||
public unsafe void Write(
|
public unsafe void Write(
|
||||||
UvStreamHandle handle,
|
UvStreamHandle handle,
|
||||||
MemoryPoolIterator2 start,
|
MemoryPoolIterator start,
|
||||||
MemoryPoolIterator2 end,
|
MemoryPoolIterator end,
|
||||||
int nBuffers,
|
int nBuffers,
|
||||||
Action<UvWriteReq, int, Exception, object> callback,
|
Action<UvWriteReq, int, Exception, object> callback,
|
||||||
object state)
|
object state)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
var byteRange = Enumerable.Range(0, 256).Select(x => (byte)x).ToArray();
|
var byteRange = Enumerable.Range(0, 256).Select(x => (byte)x).ToArray();
|
||||||
|
|
||||||
var mem = MemoryPoolBlock2.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
var mem = MemoryPoolBlock.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
||||||
mem.End = byteRange.Length;
|
mem.End = byteRange.Length;
|
||||||
|
|
||||||
var begin = mem.GetIterator();
|
var begin = mem.GetIterator();
|
||||||
|
|
@ -44,10 +44,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
.Concat(byteRange)
|
.Concat(byteRange)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
var mem0 = MemoryPoolBlock2.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
var mem0 = MemoryPoolBlock.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
||||||
var mem1 = MemoryPoolBlock2.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
var mem1 = MemoryPoolBlock.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
||||||
var mem2 = MemoryPoolBlock2.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
var mem2 = MemoryPoolBlock.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
||||||
var mem3 = MemoryPoolBlock2.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
var mem3 = MemoryPoolBlock.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
||||||
mem0.End = byteRange.Length;
|
mem0.End = byteRange.Length;
|
||||||
mem1.End = byteRange.Length;
|
mem1.End = byteRange.Length;
|
||||||
mem2.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 byteRange = Enumerable.Range(0, 16384 + 64).Select(x => (byte)x).ToArray();
|
||||||
var expectedByteRange = byteRange.Concat(byteRange).ToArray();
|
var expectedByteRange = byteRange.Concat(byteRange).ToArray();
|
||||||
|
|
||||||
var mem0 = MemoryPoolBlock2.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
var mem0 = MemoryPoolBlock.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
||||||
var mem1 = MemoryPoolBlock2.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
var mem1 = MemoryPoolBlock.Create(new ArraySegment<byte>(byteRange), IntPtr.Zero, null, null);
|
||||||
mem0.End = byteRange.Length;
|
mem0.End = byteRange.Length;
|
||||||
mem1.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;
|
var result = begin;
|
||||||
for (int i = 0; i < displacement; ++i)
|
for (int i = 0; i < displacement; ++i)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
var mockLibuv = new MockLibuv();
|
var mockLibuv = new MockLibuv();
|
||||||
|
|
||||||
using (var memory = new MemoryPool2())
|
using (var memory = new MemoryPool())
|
||||||
using (var engine = new KestrelEngine(mockLibuv, new TestServiceContext()))
|
using (var engine = new KestrelEngine(mockLibuv, new TestServiceContext()))
|
||||||
{
|
{
|
||||||
engine.Start(count: 1);
|
engine.Start(count: 1);
|
||||||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
FrameFactory = connectionContext => new Frame<HttpContext>(
|
FrameFactory = connectionContext => new Frame<HttpContext>(
|
||||||
new DummyApplication(httpContext => TaskUtilities.CompletedTask), connectionContext),
|
new DummyApplication(httpContext => TaskUtilities.CompletedTask), connectionContext),
|
||||||
Memory2 = memory,
|
Memory = memory,
|
||||||
ServerAddress = ServerAddress.FromUrl($"http://localhost:{TestServer.GetNextPort()}"),
|
ServerAddress = ServerAddress.FromUrl($"http://localhost:{TestServer.GetNextPort()}"),
|
||||||
Thread = engine.Threads[0]
|
Thread = engine.Threads[0]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
var trace = new KestrelTrace(new TestKestrelTrace());
|
var trace = new KestrelTrace(new TestKestrelTrace());
|
||||||
var ltp = new LoggingThreadPool(trace);
|
var ltp = new LoggingThreadPool(trace);
|
||||||
using (var pool = new MemoryPool2())
|
using (var pool = new MemoryPool())
|
||||||
using (var socketInput = new SocketInput(pool, ltp))
|
using (var socketInput = new SocketInput(pool, ltp))
|
||||||
{
|
{
|
||||||
var connectionContext = new ConnectionContext()
|
var connectionContext = new ConnectionContext()
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.KestrelTests
|
namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
public class MemoryPoolBlock2Tests
|
public class MemoryPoolBlockTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SeekWorks()
|
public void SeekWorks()
|
||||||
{
|
{
|
||||||
using (var pool = new MemoryPool2())
|
using (var pool = new MemoryPool())
|
||||||
{
|
{
|
||||||
var block = pool.Lease(256);
|
var block = pool.Lease(256);
|
||||||
foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x))
|
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.IsHardwareAccelerated == {Vector.IsHardwareAccelerated}");
|
||||||
Console.WriteLine($"Vector<byte>.Count == {Vector<byte>.Count}");
|
Console.WriteLine($"Vector<byte>.Count == {Vector<byte>.Count}");
|
||||||
|
|
||||||
using (var pool = new MemoryPool2())
|
using (var pool = new MemoryPool())
|
||||||
{
|
{
|
||||||
var block1 = pool.Lease(256);
|
var block1 = pool.Lease(256);
|
||||||
var block2 = block1.Next = pool.Lease(256);
|
var block2 = block1.Next = pool.Lease(256);
|
||||||
|
|
@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetLengthBetweenIteratorsWorks()
|
public void GetLengthBetweenIteratorsWorks()
|
||||||
{
|
{
|
||||||
using (var pool = new MemoryPool2())
|
using (var pool = new MemoryPool())
|
||||||
{
|
{
|
||||||
var block = pool.Lease(256);
|
var block = pool.Lease(256);
|
||||||
block.End += 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)
|
for (var firstIndex = 0; firstIndex <= lengths; ++firstIndex)
|
||||||
{
|
{
|
||||||
|
|
@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AddDoesNotAdvanceAtEndOfCurrentBlock()
|
public void AddDoesNotAdvanceAtEndOfCurrentBlock()
|
||||||
{
|
{
|
||||||
using (var pool = new MemoryPool2())
|
using (var pool = new MemoryPool())
|
||||||
{
|
{
|
||||||
var block1 = pool.Lease(256);
|
var block1 = pool.Lease(256);
|
||||||
var block2 = block1.Next = pool.Lease(256);
|
var block2 = block1.Next = pool.Lease(256);
|
||||||
|
|
@ -207,7 +207,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CopyToCorrectlyTraversesBlocks()
|
public void CopyToCorrectlyTraversesBlocks()
|
||||||
{
|
{
|
||||||
using (var pool = new MemoryPool2())
|
using (var pool = new MemoryPool())
|
||||||
{
|
{
|
||||||
var block1 = pool.Lease(128);
|
var block1 = pool.Lease(128);
|
||||||
var block2 = block1.Next = pool.Lease(128);
|
var block2 = block1.Next = pool.Lease(128);
|
||||||
|
|
@ -245,7 +245,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CopyFromCorrectlyTraversesBlocks()
|
public void CopyFromCorrectlyTraversesBlocks()
|
||||||
{
|
{
|
||||||
using (var pool = new MemoryPool2())
|
using (var pool = new MemoryPool())
|
||||||
{
|
{
|
||||||
var block1 = pool.Lease(128);
|
var block1 = pool.Lease(128);
|
||||||
var start = block1.GetIterator();
|
var start = block1.GetIterator();
|
||||||
|
|
@ -287,7 +287,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void IsEndCorrectlyTraversesBlocks()
|
public void IsEndCorrectlyTraversesBlocks()
|
||||||
{
|
{
|
||||||
using (var pool = new MemoryPool2())
|
using (var pool = new MemoryPool())
|
||||||
{
|
{
|
||||||
var block1 = pool.Lease(128);
|
var block1 = pool.Lease(128);
|
||||||
var block2 = block1.Next = 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.Same(block, iter.Block);
|
||||||
Assert.Equal(index, iter.Index);
|
Assert.Equal(index, iter.Index);
|
||||||
|
|
@ -4,7 +4,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
public static class MemoryPoolExtensions
|
public static class MemoryPoolExtensions
|
||||||
{
|
{
|
||||||
public static MemoryPoolIterator2 Add(this MemoryPoolIterator2 iterator, int count)
|
public static MemoryPoolIterator Add(this MemoryPoolIterator iterator, int count)
|
||||||
{
|
{
|
||||||
int actual;
|
int actual;
|
||||||
return iterator.CopyTo(new byte[count], 0, count, out actual);
|
return iterator.CopyTo(new byte[count], 0, count, out actual);
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@ using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.KestrelTests
|
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()
|
public void Dispose()
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
for (int i = 0; i < Vector<byte>.Count; i++)
|
for (int i = 0; i < Vector<byte>.Count; i++)
|
||||||
{
|
{
|
||||||
Vector<byte> vector = new Vector<byte>(bytes);
|
Vector<byte> vector = new Vector<byte>(bytes);
|
||||||
Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByte(ref vector));
|
Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByte(ref vector));
|
||||||
bytes[i] = 0;
|
bytes[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
bytes[i] = 1;
|
bytes[i] = 1;
|
||||||
Vector<byte> vector = new Vector<byte>(bytes);
|
Vector<byte> vector = new Vector<byte>(bytes);
|
||||||
Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByte(ref vector));
|
Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByte(ref vector));
|
||||||
bytes[i] = 0;
|
bytes[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
for (int i = 0; i < Vector<byte>.Count; i++)
|
for (int i = 0; i < Vector<byte>.Count; i++)
|
||||||
{
|
{
|
||||||
Vector<byte> vector = new Vector<byte>(bytes);
|
Vector<byte> vector = new Vector<byte>(bytes);
|
||||||
Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByteSlow(ref vector));
|
Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByteSlow(ref vector));
|
||||||
bytes[i] = 0;
|
bytes[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
bytes[i] = 1;
|
bytes[i] = 1;
|
||||||
Vector<byte> vector = new Vector<byte>(bytes);
|
Vector<byte> vector = new Vector<byte>(bytes);
|
||||||
Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByteSlow(ref vector));
|
Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByteSlow(ref vector));
|
||||||
bytes[i] = 0;
|
bytes[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Put()
|
public void Put()
|
||||||
{
|
{
|
||||||
var blocks = new MemoryPoolBlock2[4];
|
var blocks = new MemoryPoolBlock[4];
|
||||||
for (var i = 0; i < 4; ++i)
|
for (var i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
blocks[i] = _pool.Lease(16);
|
blocks[i] = _pool.Lease(16);
|
||||||
|
|
@ -286,15 +286,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("CONNECT / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpConnectMethod)]
|
[InlineData("CONNECT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpConnectMethod)]
|
||||||
[InlineData("DELETE / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpDeleteMethod)]
|
[InlineData("DELETE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpDeleteMethod)]
|
||||||
[InlineData("GET / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpGetMethod)]
|
[InlineData("GET / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpGetMethod)]
|
||||||
[InlineData("HEAD / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpHeadMethod)]
|
[InlineData("HEAD / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpHeadMethod)]
|
||||||
[InlineData("PATCH / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPatchMethod)]
|
[InlineData("PATCH / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPatchMethod)]
|
||||||
[InlineData("POST / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPostMethod)]
|
[InlineData("POST / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPostMethod)]
|
||||||
[InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpPutMethod)]
|
[InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPutMethod)]
|
||||||
[InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpOptionsMethod)]
|
[InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpOptionsMethod)]
|
||||||
[InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIterator2Extensions.HttpTraceMethod)]
|
[InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpTraceMethod)]
|
||||||
[InlineData("GET/ HTTP/1.1", ' ', false, null)]
|
[InlineData("GET/ HTTP/1.1", ' ', false, null)]
|
||||||
[InlineData("get / HTTP/1.1", ' ', false, null)]
|
[InlineData("get / HTTP/1.1", ' ', false, null)]
|
||||||
[InlineData("GOT / HTTP/1.1", ' ', false, null)]
|
[InlineData("GOT / HTTP/1.1", ' ', false, null)]
|
||||||
|
|
@ -324,8 +324,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("HTTP/1.0\r", '\r', true, MemoryPoolIterator2Extensions.Http10Version)]
|
[InlineData("HTTP/1.0\r", '\r', true, MemoryPoolIteratorExtensions.Http10Version)]
|
||||||
[InlineData("HTTP/1.1\r", '\r', true, MemoryPoolIterator2Extensions.Http11Version)]
|
[InlineData("HTTP/1.1\r", '\r', true, MemoryPoolIteratorExtensions.Http11Version)]
|
||||||
[InlineData("HTTP/3.0\r", '\r', false, null)]
|
[InlineData("HTTP/3.0\r", '\r', false, null)]
|
||||||
[InlineData("http/1.0\r", '\r', false, null)]
|
[InlineData("http/1.0\r", '\r', false, null)]
|
||||||
[InlineData("http/1.1\r", '\r', false, null)]
|
[InlineData("http/1.1\r", '\r', false, null)]
|
||||||
|
|
@ -64,13 +64,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
|
|
||||||
var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace()));
|
var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace()));
|
||||||
writeRequest.Init(loop);
|
writeRequest.Init(loop);
|
||||||
var block = MemoryPoolBlock2.Create(
|
var block = MemoryPoolBlock.Create(
|
||||||
new ArraySegment<byte>(new byte[] { 1, 2, 3, 4 }),
|
new ArraySegment<byte>(new byte[] { 1, 2, 3, 4 }),
|
||||||
dataPtr: IntPtr.Zero,
|
dataPtr: IntPtr.Zero,
|
||||||
pool: null,
|
pool: null,
|
||||||
slab: null);
|
slab: null);
|
||||||
var start = new MemoryPoolIterator2(block, 0);
|
var start = new MemoryPoolIterator(block, 0);
|
||||||
var end = new MemoryPoolIterator2(block, block.Data.Count);
|
var end = new MemoryPoolIterator(block, block.Data.Count);
|
||||||
writeRequest.Write(
|
writeRequest.Write(
|
||||||
serverConnectionPipe,
|
serverConnectionPipe,
|
||||||
start,
|
start,
|
||||||
|
|
|
||||||
|
|
@ -178,13 +178,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace()));
|
var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace()));
|
||||||
req.Init(loop);
|
req.Init(loop);
|
||||||
var block = MemoryPoolBlock2.Create(
|
var block = MemoryPoolBlock.Create(
|
||||||
new ArraySegment<byte>(new byte[] { 65, 66, 67, 68, 69 }),
|
new ArraySegment<byte>(new byte[] { 65, 66, 67, 68, 69 }),
|
||||||
dataPtr: IntPtr.Zero,
|
dataPtr: IntPtr.Zero,
|
||||||
pool: null,
|
pool: null,
|
||||||
slab: null);
|
slab: null);
|
||||||
var start = new MemoryPoolIterator2(block, 0);
|
var start = new MemoryPoolIterator(block, 0);
|
||||||
var end = new MemoryPoolIterator2(block, block.Data.Count);
|
var end = new MemoryPoolIterator(block, block.Data.Count);
|
||||||
req.Write(
|
req.Write(
|
||||||
tcp2,
|
tcp2,
|
||||||
start,
|
start,
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
// Arrange
|
// Arrange
|
||||||
var trace = new KestrelTrace(new TestKestrelTrace());
|
var trace = new KestrelTrace(new TestKestrelTrace());
|
||||||
var ltp = new LoggingThreadPool(trace);
|
var ltp = new LoggingThreadPool(trace);
|
||||||
using (var memory2 = new MemoryPool2())
|
using (var memory2 = new MemoryPool())
|
||||||
using (var socketInput = new SocketInput(memory2, ltp))
|
using (var socketInput = new SocketInput(memory2, ltp))
|
||||||
{
|
{
|
||||||
var task0Threw = false;
|
var task0Threw = false;
|
||||||
|
|
@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ConsumingOutOfOrderFailsGracefully()
|
public void ConsumingOutOfOrderFailsGracefully()
|
||||||
{
|
{
|
||||||
var defultIter = new MemoryPoolIterator2();
|
var defultIter = new MemoryPoolIterator();
|
||||||
|
|
||||||
// Calling ConsumingComplete without a preceding calling to ConsumingStart fails
|
// Calling ConsumingComplete without a preceding calling to ConsumingStart fails
|
||||||
using (var socketInput = new SocketInput(null, null))
|
using (var socketInput = new SocketInput(null, null))
|
||||||
|
|
|
||||||
|
|
@ -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()))
|
using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext()))
|
||||||
{
|
{
|
||||||
kestrelEngine.Start(count: 1);
|
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()))
|
using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext()))
|
||||||
{
|
{
|
||||||
kestrelEngine.Start(count: 1);
|
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()))
|
using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext()))
|
||||||
{
|
{
|
||||||
kestrelEngine.Start(count: 1);
|
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()))
|
using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext()))
|
||||||
{
|
{
|
||||||
kestrelEngine.Start(count: 1);
|
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()))
|
using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext()))
|
||||||
{
|
{
|
||||||
kestrelEngine.Start(count: 1);
|
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()))
|
using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext()))
|
||||||
{
|
{
|
||||||
kestrelEngine.Start(count: 1);
|
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()))
|
using (var kestrelEngine = new KestrelEngine(mockLibuv, new TestServiceContext()))
|
||||||
{
|
{
|
||||||
kestrelEngine.Start(count: 1);
|
kestrelEngine.Start(count: 1);
|
||||||
|
|
@ -529,7 +529,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
block2.End = block2.Data.Offset + block2.Data.Count;
|
block2.End = block2.Data.Offset + block2.Data.Count;
|
||||||
start.Block.Next = block2;
|
start.Block.Next = block2;
|
||||||
|
|
||||||
var end = new MemoryPoolIterator2(block2, block2.End);
|
var end = new MemoryPoolIterator(block2, block2.End);
|
||||||
|
|
||||||
socketOutput.ProducingComplete(end);
|
socketOutput.ProducingComplete(end);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
class TestInput : IConnectionControl, IFrameControl, IDisposable
|
class TestInput : IConnectionControl, IFrameControl, IDisposable
|
||||||
{
|
{
|
||||||
private MemoryPool2 _memoryPool;
|
private MemoryPool _memoryPool;
|
||||||
|
|
||||||
public TestInput()
|
public TestInput()
|
||||||
{
|
{
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
};
|
};
|
||||||
FrameContext = new Frame<object>(null, context);
|
FrameContext = new Frame<object>(null, context);
|
||||||
|
|
||||||
_memoryPool = new MemoryPool2();
|
_memoryPool = new MemoryPool();
|
||||||
FrameContext.SocketInput = new SocketInput(_memoryPool, ltp);
|
FrameContext.SocketInput = new SocketInput(_memoryPool, ltp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,16 +120,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
Assert.Equal(expect, result);
|
Assert.Equal(expect, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MemoryPoolIterator2 BuildSample(string data)
|
private MemoryPoolIterator BuildSample(string data)
|
||||||
{
|
{
|
||||||
var store = data.Select(c => (byte)c).ToArray();
|
var store = data.Select(c => (byte)c).ToArray();
|
||||||
var mem = MemoryPoolBlock2.Create(new ArraySegment<byte>(store), IntPtr.Zero, null, null);
|
var mem = MemoryPoolBlock.Create(new ArraySegment<byte>(store), IntPtr.Zero, null, null);
|
||||||
mem.End = store.Length;
|
mem.End = store.Length;
|
||||||
|
|
||||||
return mem.GetIterator();
|
return mem.GetIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private MemoryPoolIterator2 GetIterator(MemoryPoolIterator2 begin, int displacement)
|
private MemoryPoolIterator GetIterator(MemoryPoolIterator begin, int displacement)
|
||||||
{
|
{
|
||||||
var result = begin;
|
var result = begin;
|
||||||
for (int i = 0; i < displacement; ++i)
|
for (int i = 0; i < displacement; ++i)
|
||||||
|
|
|
||||||
|
|
@ -390,7 +390,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
((ICollection<KeyValuePair<string, StringValues>>)MaybeUnknown)?.CopyTo(array, arrayIndex);
|
((ICollection<KeyValuePair<string, StringValues>>)MaybeUnknown)?.CopyTo(array, arrayIndex);
|
||||||
}}
|
}}
|
||||||
{(loop.ClassName == "FrameResponseHeaders" ? $@"
|
{(loop.ClassName == "FrameResponseHeaders" ? $@"
|
||||||
protected void CopyToFast(ref MemoryPoolIterator2 output)
|
protected void CopyToFast(ref MemoryPoolIterator output)
|
||||||
{{
|
{{
|
||||||
{Each(loop.Headers, header => $@"
|
{Each(loop.Headers, header => $@"
|
||||||
if ({header.TestBit()})
|
if ({header.TestBit()})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue