Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make memory pool plugable
  • Loading branch information
jkotalik committed Nov 15, 2018
commit 7bf5f2ce6cbcdfd8f83dffe7053e1887ac488068
5 changes: 3 additions & 2 deletions src/Microsoft.AspNetCore.Http/StreamPipeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public class StreamPipeWriter : PipeWriter, IDisposable
private List<CompletedBuffer> _completedSegments;
private Memory<byte> _currentSegment;
private IMemoryOwner<byte> _currentSegmentOwner;
private MemoryPool<byte> _pool;
private int _position;

private CancellationTokenSource _internalTokenSource;
private bool _isCompleted;
private ExceptionDispatchInfo _exceptionInfo;

private object lockObject = new object();

private CancellationTokenSource InternalTokenSource
Expand Down Expand Up @@ -60,6 +60,7 @@ public StreamPipeWriter(Stream writingStream, int minimumSegmentSize, MemoryPool
{
_minimumSegmentSize = minimumSegmentSize;
_writingStream = writingStream;
_pool = pool ?? MemoryPool<byte>.Shared;
}

/// <inheritdoc />
Expand Down Expand Up @@ -252,7 +253,7 @@ private void AddSegment(int sizeHint = 0)
}

// Get a new buffer using the minimum segment size, unless the size hint is larger than a single segment.
_currentSegmentOwner = MemoryPool<byte>.Shared.Rent(Math.Max(_minimumSegmentSize, sizeHint));
_currentSegmentOwner = _pool.Rent(Math.Max(_minimumSegmentSize, sizeHint));
_currentSegment = _currentSegmentOwner.Memory;
_position = 0;
}
Expand Down