IISIntegration 714 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. commit b8c3d26975fc53347ae7c9280927be5be9bea5eb
  2. Author: Pavel Krymets <[email protected]>
  3. Date: Mon Nov 13 15:06:22 2017 -0800
  4. Migrate to new pipe APIs (#454)
  5. diff --git a/Directory.Build.props b/Directory.Build.props
  6. index ed8924e1223..5a6091cbfea 100644
  7. --- a/Directory.Build.props
  8. +++ b/Directory.Build.props
  9. @@ -12,4 +12,10 @@
  10. <PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
  11. <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  12. </PropertyGroup>
  13. +
  14. + <ItemGroup>
  15. + <!-- This is an experimental version of the compiler. See https://github.com/dotnet/csharplang/issues/666 for more details. -->
  16. + <PackageReference Include="Microsoft.NETCore.Compilers" Version="$(MicrosoftNETCoreCompilersPackageVersion)" PrivateAssets="All" />
  17. + </ItemGroup>
  18. +
  19. </Project>
  20. diff --git a/build/dependencies.props b/build/dependencies.props
  21. index 94936eaa6ad..c5719a5f51e 100644
  22. --- a/build/dependencies.props
  23. +++ b/build/dependencies.props
  24. @@ -26,14 +26,15 @@
  25. <MicrosoftExtensionsOptionsPackageVersion>2.1.0-preview1-27496</MicrosoftExtensionsOptionsPackageVersion>
  26. <MicrosoftExtensionsSecurityHelperSourcesPackageVersion>2.1.0-preview1-27496</MicrosoftExtensionsSecurityHelperSourcesPackageVersion>
  27. <MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
  28. + <MicrosoftNETCoreCompilersPackageVersion>2.6.0-beta2-62211-02</MicrosoftNETCoreCompilersPackageVersion>
  29. <MicrosoftNETTestSdkPackageVersion>15.3.0</MicrosoftNETTestSdkPackageVersion>
  30. <SystemBuffersPackageVersion>4.4.0</SystemBuffersPackageVersion>
  31. - <SystemIOPipelinesPackageVersion>0.1.0-e170811-6</SystemIOPipelinesPackageVersion>
  32. - <SystemMemoryPackageVersion>4.4.0-preview3-25519-03</SystemMemoryPackageVersion>
  33. - <SystemNumericsVectorsPackageVersion>4.4.0</SystemNumericsVectorsPackageVersion>
  34. - <SystemRuntimeCompilerServicesUnsafePackageVersion>4.4.0</SystemRuntimeCompilerServicesUnsafePackageVersion>
  35. + <SystemIOPipelinesPackageVersion>0.1.0-alpha-002</SystemIOPipelinesPackageVersion>
  36. + <SystemMemoryPackageVersion>4.5.0-preview1-25902-08</SystemMemoryPackageVersion>
  37. + <SystemNumericsVectorsPackageVersion>4.5.0-preview1-25902-08</SystemNumericsVectorsPackageVersion>
  38. + <SystemRuntimeCompilerServicesUnsafePackageVersion>4.5.0-preview1-25902-08</SystemRuntimeCompilerServicesUnsafePackageVersion>
  39. <SystemSecurityPrincipalWindowsPackageVersion>4.4.0</SystemSecurityPrincipalWindowsPackageVersion>
  40. - <SystemTextEncodingsWebUtf8PackageVersion>0.1.0-e170811-6</SystemTextEncodingsWebUtf8PackageVersion>
  41. + <SystemTextEncodingsWebUtf8PackageVersion>0.1.0-alpha-002</SystemTextEncodingsWebUtf8PackageVersion>
  42. <XunitPackageVersion>2.3.0</XunitPackageVersion>
  43. <XunitRunnerVisualStudioPackageVersion>2.3.0</XunitRunnerVisualStudioPackageVersion>
  44. </PropertyGroup>
  45. diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs
  46. index db83adc7cb2..4b7f3c12d79 100644
  47. --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs
  48. +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs
  49. @@ -41,10 +41,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  50. protected Stack<KeyValuePair<Func<object, Task>, object>> _onCompleted;
  51. protected Exception _applicationException;
  52. - private readonly PipeFactory _pipeFactory;
  53. + private readonly BufferPool _bufferPool;
  54. private GCHandle _thisHandle;
  55. - private BufferHandle _inputHandle;
  56. + private MemoryHandle _inputHandle;
  57. private IISAwaitable _operation = new IISAwaitable();
  58. private IISAwaitable _readWebSocketsOperation;
  59. @@ -64,12 +64,12 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  60. private const string NegotiateString = "Negotiate";
  61. private const string BasicString = "Basic";
  62. - internal unsafe IISHttpContext(PipeFactory pipeFactory, IntPtr pHttpContext, IISOptions options)
  63. + internal unsafe IISHttpContext(BufferPool bufferPool, IntPtr pHttpContext, IISOptions options)
  64. : base((HttpApiTypes.HTTP_REQUEST*)NativeMethods.http_get_raw_request(pHttpContext))
  65. {
  66. _thisHandle = GCHandle.Alloc(this);
  67. - _pipeFactory = pipeFactory;
  68. + _bufferPool = bufferPool;
  69. _pHttpContext = pHttpContext;
  70. NativeMethods.http_set_managed_context(_pHttpContext, (IntPtr)_thisHandle);
  71. @@ -142,8 +142,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  72. RequestBody = new IISHttpRequestBody(this);
  73. ResponseBody = new IISHttpResponseBody(this);
  74. - Input = _pipeFactory.Create(new PipeOptions { ReaderScheduler = TaskRunScheduler.Default });
  75. - var pipe = _pipeFactory.Create(new PipeOptions { ReaderScheduler = TaskRunScheduler.Default });
  76. + Input = new Pipe(new PipeOptions(_bufferPool, readerScheduler: TaskRunScheduler.Default));
  77. + var pipe = new Pipe(new PipeOptions(_bufferPool, readerScheduler: TaskRunScheduler.Default));
  78. Output = new OutputProducer(pipe);
  79. }
  80. @@ -609,7 +609,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  81. // REVIEW: We don't really need this list since the memory is already pinned with the default pool,
  82. // but shouldn't assume the pool implementation right now. Unfortunately, this causes a heap allocation...
  83. - var handles = new BufferHandle[nChunks];
  84. + var handles = new MemoryHandle[nChunks];
  85. foreach (var b in buffer)
  86. {
  87. @@ -620,7 +620,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  88. chunk.DataChunkType = HttpApiTypes.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
  89. chunk.fromMemory.BufferLength = (uint)b.Length;
  90. - chunk.fromMemory.pBuffer = (IntPtr)handle.PinnedPointer;
  91. + chunk.fromMemory.pBuffer = (IntPtr)handle.Pointer;
  92. currentChunk++;
  93. }
  94. @@ -661,7 +661,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  95. {
  96. var hr = NativeMethods.http_read_request_bytes(
  97. _pHttpContext,
  98. - (byte*)_inputHandle.PinnedPointer,
  99. + (byte*)_inputHandle.Pointer,
  100. length,
  101. out var dwReceivedBytes,
  102. out bool fCompletionExpected);
  103. @@ -679,7 +679,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  104. bool fCompletionExpected;
  105. hr = NativeMethods.http_websockets_read_bytes(
  106. _pHttpContext,
  107. - (byte*)_inputHandle.PinnedPointer,
  108. + (byte*)_inputHandle.Pointer,
  109. length,
  110. IISAwaitable.ReadCallback,
  111. (IntPtr)_thisHandle,
  112. diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs
  113. index 1701122ec68..5d326b27b1e 100644
  114. --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs
  115. +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs
  116. @@ -2,6 +2,7 @@
  117. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  118. using System;
  119. +using System.Buffers;
  120. using System.Threading.Tasks;
  121. using System.Threading;
  122. using System.IO.Pipelines;
  123. @@ -14,8 +15,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  124. {
  125. private readonly IHttpApplication<TContext> _application;
  126. - public IISHttpContextOfT(PipeFactory pipeFactory, IHttpApplication<TContext> application, IntPtr pHttpContext, IISOptions options)
  127. - : base(pipeFactory, pHttpContext, options)
  128. + public IISHttpContextOfT(BufferPool bufferPool, IHttpApplication<TContext> application, IntPtr pHttpContext, IISOptions options)
  129. + : base(bufferPool, pHttpContext, options)
  130. {
  131. _application = application;
  132. }
  133. diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs
  134. index 4417e54c5b0..a02e1fac1cf 100644
  135. --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs
  136. +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs
  137. @@ -2,6 +2,7 @@
  138. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  139. using System;
  140. +using System.Buffers;
  141. using System.IO.Pipelines;
  142. using System.Runtime.InteropServices;
  143. using System.Threading;
  144. @@ -22,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  145. private static NativeMethods.PFN_ASYNC_COMPLETION _onAsyncCompletion = OnAsyncCompletion;
  146. private IISContextFactory _iisContextFactory;
  147. - private PipeFactory _pipeFactory = new PipeFactory();
  148. + private readonly BufferPool _bufferPool = new MemoryPool();
  149. private GCHandle _httpServerHandle;
  150. private readonly IApplicationLifetime _applicationLifetime;
  151. private readonly IAuthenticationSchemeProvider _authentication;
  152. @@ -45,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  153. {
  154. _httpServerHandle = GCHandle.Alloc(this);
  155. - _iisContextFactory = new IISContextFactory<TContext>(_pipeFactory, application, _options);
  156. + _iisContextFactory = new IISContextFactory<TContext>(_bufferPool, application, _options);
  157. // Start the server by registering the callback
  158. NativeMethods.register_callbacks(_requestHandler, _shutdownHandler, _onAsyncCompletion, (IntPtr)_httpServerHandle, (IntPtr)_httpServerHandle);
  159. @@ -69,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  160. _httpServerHandle.Free();
  161. }
  162. - _pipeFactory.Dispose();
  163. + _bufferPool.Dispose();
  164. }
  165. private static NativeMethods.REQUEST_NOTIFICATION_STATUS HandleRequest(IntPtr pHttpContext, IntPtr pvRequestContext)
  166. @@ -125,19 +126,19 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  167. private class IISContextFactory<T> : IISContextFactory
  168. {
  169. private readonly IHttpApplication<T> _application;
  170. - private readonly PipeFactory _pipeFactory;
  171. + private readonly BufferPool _bufferPool;
  172. private readonly IISOptions _options;
  173. - public IISContextFactory(PipeFactory pipeFactory, IHttpApplication<T> application, IISOptions options)
  174. + public IISContextFactory(BufferPool bufferPool, IHttpApplication<T> application, IISOptions options)
  175. {
  176. _application = application;
  177. - _pipeFactory = pipeFactory;
  178. + _bufferPool = bufferPool;
  179. _options = options;
  180. }
  181. public IISHttpContext CreateHttpContext(IntPtr pHttpContext)
  182. {
  183. - return new IISHttpContextOfT<T>(_pipeFactory, _application, pHttpContext, _options);
  184. + return new IISHttpContextOfT<T>(_bufferPool, _application, pHttpContext, _options);
  185. }
  186. }
  187. }
  188. diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/OutputProducer.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/OutputProducer.cs
  189. index 57391e80ded..d469dd4d882 100644
  190. --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/OutputProducer.cs
  191. +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/OutputProducer.cs
  192. @@ -107,10 +107,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  193. // The flush task can't fail today
  194. return Task.CompletedTask;
  195. }
  196. - return FlushAsyncAwaited(awaitable, writableBuffer.BytesWritten, cancellationToken);
  197. + return FlushAsyncAwaited(awaitable, cancellationToken);
  198. }
  199. - private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, long count, CancellationToken cancellationToken)
  200. + private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, CancellationToken cancellationToken)
  201. {
  202. // https://github.com/dotnet/corefxlab/issues/1334
  203. // Since the flush awaitable doesn't currently support multiple awaiters