| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- commit b8c3d26975fc53347ae7c9280927be5be9bea5eb
- Author: Pavel Krymets <[email protected]>
- Date: Mon Nov 13 15:06:22 2017 -0800
- Migrate to new pipe APIs (#454)
- diff --git a/Directory.Build.props b/Directory.Build.props
- index ed8924e1223..5a6091cbfea 100644
- --- a/Directory.Build.props
- +++ b/Directory.Build.props
- @@ -12,4 +12,10 @@
- <PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
- <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
- </PropertyGroup>
- +
- + <ItemGroup>
- + <!-- This is an experimental version of the compiler. See https://github.com/dotnet/csharplang/issues/666 for more details. -->
- + <PackageReference Include="Microsoft.NETCore.Compilers" Version="$(MicrosoftNETCoreCompilersPackageVersion)" PrivateAssets="All" />
- + </ItemGroup>
- +
- </Project>
- diff --git a/build/dependencies.props b/build/dependencies.props
- index 94936eaa6ad..c5719a5f51e 100644
- --- a/build/dependencies.props
- +++ b/build/dependencies.props
- @@ -26,14 +26,15 @@
- <MicrosoftExtensionsOptionsPackageVersion>2.1.0-preview1-27496</MicrosoftExtensionsOptionsPackageVersion>
- <MicrosoftExtensionsSecurityHelperSourcesPackageVersion>2.1.0-preview1-27496</MicrosoftExtensionsSecurityHelperSourcesPackageVersion>
- <MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
- + <MicrosoftNETCoreCompilersPackageVersion>2.6.0-beta2-62211-02</MicrosoftNETCoreCompilersPackageVersion>
- <MicrosoftNETTestSdkPackageVersion>15.3.0</MicrosoftNETTestSdkPackageVersion>
- <SystemBuffersPackageVersion>4.4.0</SystemBuffersPackageVersion>
- - <SystemIOPipelinesPackageVersion>0.1.0-e170811-6</SystemIOPipelinesPackageVersion>
- - <SystemMemoryPackageVersion>4.4.0-preview3-25519-03</SystemMemoryPackageVersion>
- - <SystemNumericsVectorsPackageVersion>4.4.0</SystemNumericsVectorsPackageVersion>
- - <SystemRuntimeCompilerServicesUnsafePackageVersion>4.4.0</SystemRuntimeCompilerServicesUnsafePackageVersion>
- + <SystemIOPipelinesPackageVersion>0.1.0-alpha-002</SystemIOPipelinesPackageVersion>
- + <SystemMemoryPackageVersion>4.5.0-preview1-25902-08</SystemMemoryPackageVersion>
- + <SystemNumericsVectorsPackageVersion>4.5.0-preview1-25902-08</SystemNumericsVectorsPackageVersion>
- + <SystemRuntimeCompilerServicesUnsafePackageVersion>4.5.0-preview1-25902-08</SystemRuntimeCompilerServicesUnsafePackageVersion>
- <SystemSecurityPrincipalWindowsPackageVersion>4.4.0</SystemSecurityPrincipalWindowsPackageVersion>
- - <SystemTextEncodingsWebUtf8PackageVersion>0.1.0-e170811-6</SystemTextEncodingsWebUtf8PackageVersion>
- + <SystemTextEncodingsWebUtf8PackageVersion>0.1.0-alpha-002</SystemTextEncodingsWebUtf8PackageVersion>
- <XunitPackageVersion>2.3.0</XunitPackageVersion>
- <XunitRunnerVisualStudioPackageVersion>2.3.0</XunitRunnerVisualStudioPackageVersion>
- </PropertyGroup>
- diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs
- index db83adc7cb2..4b7f3c12d79 100644
- --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs
- +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs
- @@ -41,10 +41,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
- protected Stack<KeyValuePair<Func<object, Task>, object>> _onCompleted;
-
- protected Exception _applicationException;
- - private readonly PipeFactory _pipeFactory;
- + private readonly BufferPool _bufferPool;
-
- private GCHandle _thisHandle;
- - private BufferHandle _inputHandle;
- + private MemoryHandle _inputHandle;
- private IISAwaitable _operation = new IISAwaitable();
-
- private IISAwaitable _readWebSocketsOperation;
- @@ -64,12 +64,12 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
- private const string NegotiateString = "Negotiate";
- private const string BasicString = "Basic";
-
- - internal unsafe IISHttpContext(PipeFactory pipeFactory, IntPtr pHttpContext, IISOptions options)
- + internal unsafe IISHttpContext(BufferPool bufferPool, IntPtr pHttpContext, IISOptions options)
- : base((HttpApiTypes.HTTP_REQUEST*)NativeMethods.http_get_raw_request(pHttpContext))
- {
- _thisHandle = GCHandle.Alloc(this);
-
- - _pipeFactory = pipeFactory;
- + _bufferPool = bufferPool;
- _pHttpContext = pHttpContext;
-
- NativeMethods.http_set_managed_context(_pHttpContext, (IntPtr)_thisHandle);
- @@ -142,8 +142,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
- RequestBody = new IISHttpRequestBody(this);
- ResponseBody = new IISHttpResponseBody(this);
-
- - Input = _pipeFactory.Create(new PipeOptions { ReaderScheduler = TaskRunScheduler.Default });
- - var pipe = _pipeFactory.Create(new PipeOptions { ReaderScheduler = TaskRunScheduler.Default });
- + Input = new Pipe(new PipeOptions(_bufferPool, readerScheduler: TaskRunScheduler.Default));
- + var pipe = new Pipe(new PipeOptions(_bufferPool, readerScheduler: TaskRunScheduler.Default));
- Output = new OutputProducer(pipe);
- }
-
- @@ -609,7 +609,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
-
- // REVIEW: We don't really need this list since the memory is already pinned with the default pool,
- // but shouldn't assume the pool implementation right now. Unfortunately, this causes a heap allocation...
- - var handles = new BufferHandle[nChunks];
- + var handles = new MemoryHandle[nChunks];
-
- foreach (var b in buffer)
- {
- @@ -620,7 +620,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
-
- chunk.DataChunkType = HttpApiTypes.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
- chunk.fromMemory.BufferLength = (uint)b.Length;
- - chunk.fromMemory.pBuffer = (IntPtr)handle.PinnedPointer;
- + chunk.fromMemory.pBuffer = (IntPtr)handle.Pointer;
-
- currentChunk++;
- }
- @@ -661,7 +661,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
- {
- var hr = NativeMethods.http_read_request_bytes(
- _pHttpContext,
- - (byte*)_inputHandle.PinnedPointer,
- + (byte*)_inputHandle.Pointer,
- length,
- out var dwReceivedBytes,
- out bool fCompletionExpected);
- @@ -679,7 +679,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
- bool fCompletionExpected;
- hr = NativeMethods.http_websockets_read_bytes(
- _pHttpContext,
- - (byte*)_inputHandle.PinnedPointer,
- + (byte*)_inputHandle.Pointer,
- length,
- IISAwaitable.ReadCallback,
- (IntPtr)_thisHandle,
- diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs
- index 1701122ec68..5d326b27b1e 100644
- --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs
- +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs
- @@ -2,6 +2,7 @@
- // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
- using System;
- +using System.Buffers;
- using System.Threading.Tasks;
- using System.Threading;
- using System.IO.Pipelines;
- @@ -14,8 +15,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
- {
- private readonly IHttpApplication<TContext> _application;
-
- - public IISHttpContextOfT(PipeFactory pipeFactory, IHttpApplication<TContext> application, IntPtr pHttpContext, IISOptions options)
- - : base(pipeFactory, pHttpContext, options)
- + public IISHttpContextOfT(BufferPool bufferPool, IHttpApplication<TContext> application, IntPtr pHttpContext, IISOptions options)
- + : base(bufferPool, pHttpContext, options)
- {
- _application = application;
- }
- diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs
- index 4417e54c5b0..a02e1fac1cf 100644
- --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs
- +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs
- @@ -2,6 +2,7 @@
- // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
- using System;
- +using System.Buffers;
- using System.IO.Pipelines;
- using System.Runtime.InteropServices;
- using System.Threading;
- @@ -22,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
- private static NativeMethods.PFN_ASYNC_COMPLETION _onAsyncCompletion = OnAsyncCompletion;
-
- private IISContextFactory _iisContextFactory;
- - private PipeFactory _pipeFactory = new PipeFactory();
- + private readonly BufferPool _bufferPool = new MemoryPool();
- private GCHandle _httpServerHandle;
- private readonly IApplicationLifetime _applicationLifetime;
- private readonly IAuthenticationSchemeProvider _authentication;
- @@ -45,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
- {
- _httpServerHandle = GCHandle.Alloc(this);
-
- - _iisContextFactory = new IISContextFactory<TContext>(_pipeFactory, application, _options);
- + _iisContextFactory = new IISContextFactory<TContext>(_bufferPool, application, _options);
-
- // Start the server by registering the callback
- NativeMethods.register_callbacks(_requestHandler, _shutdownHandler, _onAsyncCompletion, (IntPtr)_httpServerHandle, (IntPtr)_httpServerHandle);
- @@ -69,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
- _httpServerHandle.Free();
- }
-
- - _pipeFactory.Dispose();
- + _bufferPool.Dispose();
- }
-
- private static NativeMethods.REQUEST_NOTIFICATION_STATUS HandleRequest(IntPtr pHttpContext, IntPtr pvRequestContext)
- @@ -125,19 +126,19 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
- private class IISContextFactory<T> : IISContextFactory
- {
- private readonly IHttpApplication<T> _application;
- - private readonly PipeFactory _pipeFactory;
- + private readonly BufferPool _bufferPool;
- private readonly IISOptions _options;
-
- - public IISContextFactory(PipeFactory pipeFactory, IHttpApplication<T> application, IISOptions options)
- + public IISContextFactory(BufferPool bufferPool, IHttpApplication<T> application, IISOptions options)
- {
- _application = application;
- - _pipeFactory = pipeFactory;
- + _bufferPool = bufferPool;
- _options = options;
- }
-
- public IISHttpContext CreateHttpContext(IntPtr pHttpContext)
- {
- - return new IISHttpContextOfT<T>(_pipeFactory, _application, pHttpContext, _options);
- + return new IISHttpContextOfT<T>(_bufferPool, _application, pHttpContext, _options);
- }
- }
- }
- diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/OutputProducer.cs
- index 57391e80ded..d469dd4d882 100644
- --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/OutputProducer.cs
- +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/OutputProducer.cs
- @@ -107,10 +107,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
- // The flush task can't fail today
- return Task.CompletedTask;
- }
- - return FlushAsyncAwaited(awaitable, writableBuffer.BytesWritten, cancellationToken);
- + return FlushAsyncAwaited(awaitable, cancellationToken);
- }
-
- - private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, long count, CancellationToken cancellationToken)
- + private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, CancellationToken cancellationToken)
- {
- // https://github.com/dotnet/corefxlab/issues/1334
- // Since the flush awaitable doesn't currently support multiple awaiters
|