Merge branch 'benaadams/dont-use-default-buffer-size' into dev
This commit is contained in:
commit
1c320d7a74
|
|
@ -29,8 +29,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter
|
|||
_filteredStream = filteredStream;
|
||||
_socketInputStream = new SocketInputStream(SocketInput);
|
||||
|
||||
_filteredStream.CopyToAsync(_socketInputStream).ContinueWith((task, state) =>
|
||||
var block = memory.Lease();
|
||||
// Use pooled block for copy
|
||||
_filteredStream.CopyToAsync(_socketInputStream, block).ContinueWith((task, state) =>
|
||||
{
|
||||
var returnedBlock = task.Result;
|
||||
returnedBlock.Pool?.Return(returnedBlock);
|
||||
|
||||
((FilteredStreamAdapter)state).OnStreamClose(task);
|
||||
}, this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.Server.Kestrel.Filter
|
||||
{
|
||||
public static class StreamExtensions
|
||||
{
|
||||
public static async Task<MemoryPoolBlock2> CopyToAsync(this Stream source, Stream destination, MemoryPoolBlock2 block)
|
||||
{
|
||||
int bytesRead;
|
||||
while ((bytesRead = await source.ReadAsync(block.Array, block.Data.Offset, block.Data.Count)) != 0)
|
||||
{
|
||||
await destination.WriteAsync(block.Array, block.Data.Offset, bytesRead);
|
||||
}
|
||||
|
||||
return block;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue