Skip to content

Commit 9ae6a5b

Browse files
committed
iis
1 parent bd9cd25 commit 9ae6a5b

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

src/Servers/IIS/IIS/src/Core/IISHttpServer.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
using System.Buffers;
55
using System.Diagnostics;
6-
using System.Diagnostics.Metrics;
76
using System.Runtime.InteropServices;
87
using Microsoft.AspNetCore.Authentication;
98
using Microsoft.AspNetCore.Builder;
9+
using Microsoft.AspNetCore.Connections;
1010
using Microsoft.AspNetCore.Hosting.Server;
1111
using Microsoft.AspNetCore.Hosting.Server.Features;
1212
using Microsoft.AspNetCore.Http.Features;
@@ -19,17 +19,10 @@ namespace Microsoft.AspNetCore.Server.IIS.Core;
1919

2020
internal sealed class IISHttpServer : IServer
2121
{
22-
internal sealed class DummyMeterFactory : IMeterFactory
23-
{
24-
public Meter Create(MeterOptions options) => new Meter(options);
25-
26-
public void Dispose() { }
27-
}
28-
2922
private const string WebSocketVersionString = "WEBSOCKET_VERSION";
3023

3124
private IISContextFactory? _iisContextFactory;
32-
private readonly MemoryPool<byte> _memoryPool = new PinnedBlockMemoryPool(new DummyMeterFactory());
25+
private readonly MemoryPool<byte> _memoryPool;
3326
private GCHandle _httpServerHandle;
3427
private readonly IHostApplicationLifetime _applicationLifetime;
3528
private readonly ILogger<IISHttpServer> _logger;
@@ -68,10 +61,12 @@ public IISHttpServer(
6861
IHostApplicationLifetime applicationLifetime,
6962
IAuthenticationSchemeProvider authentication,
7063
IConfiguration configuration,
64+
IMemoryPoolFactory<byte> memoryPoolFactory,
7165
IOptions<IISServerOptions> options,
7266
ILogger<IISHttpServer> logger
7367
)
7468
{
69+
_memoryPool = memoryPoolFactory.Create();
7570
_nativeApplication = nativeApplication;
7671
_applicationLifetime = applicationLifetime;
7772
_logger = logger;

src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Buffers;
45
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Connections;
57
using Microsoft.AspNetCore.Hosting.Server;
68
using Microsoft.AspNetCore.Server.IIS;
79
using Microsoft.AspNetCore.Server.IIS.Core;
810
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.DependencyInjection.Extensions;
912

1013
namespace Microsoft.AspNetCore.Hosting;
1114

@@ -53,6 +56,8 @@ public static IWebHostBuilder UseIIS(this IWebHostBuilder hostBuilder)
5356
options.IisMaxRequestSizeLimit = iisConfigData.maxRequestBodySize;
5457
}
5558
);
59+
60+
services.TryAddSingleton<IMemoryPoolFactory<byte>, DefaultMemoryPoolFactory>();
5661
});
5762
}
5863

src/Servers/Kestrel/Core/src/Internal/PinnedBlockMemoryPoolFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ public PinnedBlockMemoryPoolFactory(IMeterFactory meterFactory, TimeProvider? ti
2424
public MemoryPool<byte> Create()
2525
{
2626
var pool = new PinnedBlockMemoryPool(_meterFactory);
27+
28+
_pools.TryAdd(pool, pool);
29+
2730
pool.DisposeCallback = (self) =>
2831
{
2932
_pools.TryRemove(self, out _);
3033
};
3134

32-
_pools.TryAdd(pool, pool);
33-
3435
return pool;
3536
}
3637

src/Shared/Buffers.MemoryPool/DefaultMemoryPoolFactory.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace System.Buffers;
1010

11+
#nullable enable
12+
1113
internal sealed class DefaultMemoryPoolFactory : IMemoryPoolFactory<byte>, IDisposable
1214
{
1315
private readonly IMeterFactory _meterFactory;
@@ -40,13 +42,14 @@ public DefaultMemoryPoolFactory(IMeterFactory? meterFactory = null)
4042
public MemoryPool<byte> Create()
4143
{
4244
var pool = new PinnedBlockMemoryPool(_meterFactory);
45+
46+
_pools.TryAdd(pool, pool);
47+
4348
pool.DisposeCallback = (self) =>
4449
{
4550
_pools.TryRemove(self, out _);
4651
};
4752

48-
_pools.TryAdd(pool, pool);
49-
5053
return pool;
5154
}
5255

0 commit comments

Comments
 (0)