Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,21 @@ public void SocketTransportIsTheDefault()
[Fact]
public void LibuvTransportCanBeManuallySelectedIndependentOfOrder()
{
#pragma warning disable CS0618
var hostBuilder = new WebHostBuilder()
.UseKestrel()
.UseLibuv()
.Configure(app => { });
#pragma warning restore CS0618

Assert.IsType<LibuvTransportFactory>(hostBuilder.Build().Services.GetService<IConnectionListenerFactory>());

#pragma warning disable CS0618
var hostBuilderReversed = new WebHostBuilder()
.UseLibuv()
.UseKestrel()
.Configure(app => { });
#pragma warning restore CS0618

Assert.IsType<LibuvTransportFactory>(hostBuilderReversed.Build().Services.GetService<IConnectionListenerFactory>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public LibuvConnectionListener(LibuvFunctions uv, LibuvTransportContext context,

public IHostApplicationLifetime AppLifetime => TransportContext.AppLifetime;
public ILibuvTrace Log => TransportContext.Log;

#pragma warning disable CS0618
public LibuvTransportOptions TransportOptions => TransportContext.Options;
#pragma warning restore CS0618

public EndPoint EndPoint { get; set; }

Expand Down Expand Up @@ -131,7 +134,9 @@ internal async Task BindAsync()
{
// TODO: Move thread management to LibuvTransportFactory
// TODO: Split endpoint management from thread management
#pragma warning disable CS0618
for (var index = 0; index < TransportOptions.ThreadCount; index++)
#pragma warning restore CS0618
{
Threads.Add(new LibuvThread(Libuv, TransportContext));
}
Expand All @@ -143,7 +148,9 @@ internal async Task BindAsync()

try
{
#pragma warning disable CS0618
if (TransportOptions.ThreadCount == 1)
#pragma warning restore CS0618
{
var listener = new Listener(TransportContext);
_listeners.Add(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
{
internal class LibuvTransportContext
{
#pragma warning disable CS0618
public LibuvTransportOptions Options { get; set; }
#pragma warning restore CS0618

public IHostApplicationLifetime AppLifetime { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ internal class LibuvTransportFactory : IConnectionListenerFactory
private readonly LibuvTransportContext _baseTransportContext;

public LibuvTransportFactory(
#pragma warning disable CS0618
IOptions<LibuvTransportOptions> options,
#pragma warning restore CS0618
IHostApplicationLifetime applicationLifetime,
ILoggerFactory loggerFactory)
{
Expand All @@ -37,7 +39,9 @@ public LibuvTransportFactory(
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv");
var trace = new LibuvTrace(logger);

#pragma warning disable CS0618
var threadCount = options.Value.ThreadCount;
#pragma warning restore CS0618

if (threadCount <= 0)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Servers/Kestrel/Transport.Libuv/src/Internal/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public Task StartAsync(
return Thread.PostAsync(listener =>
{
listener.ListenSocket = listener.CreateListenSocket();
#pragma warning disable CS0618
listener.ListenSocket.Listen(TransportContext.Options.Backlog, ConnectionCallback, listener);
#pragma warning restore CS0618
}, this);
}

Expand Down Expand Up @@ -66,7 +68,9 @@ private UvTcpHandle ListenTcp(bool useFileHandle)
try
{
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
#pragma warning disable CS0618
socket.NoDelay(TransportContext.Options.NoDelay);
#pragma warning restore CS0618

if (!useFileHandle)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ protected internal void HandleConnection(UvStreamHandle socket)
}

var options = TransportContext.Options;
#pragma warning disable CS0618
var connection = new LibuvConnection(socket, TransportContext.Log, Thread, remoteEndPoint, localEndPoint, InputOptions, OutputOptions, options.MaxReadBufferSize, options.MaxWriteBufferSize);
#pragma warning restore CS0618
connection.Start();

bool accepted = _acceptQueue.Writer.TryWrite(connection);
Expand All @@ -128,7 +130,9 @@ private UvTcpHandle AcceptTcp()
try
{
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
#pragma warning disable CS0618
socket.NoDelay(TransportContext.Options.NoDelay);
#pragma warning restore CS0618
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ private void PostCallback()
ListenPipe = new UvPipeHandle(Log);
ListenPipe.Init(Thread.Loop, Thread.QueueCloseHandle, false);
ListenPipe.Bind(_pipeName);
#pragma warning disable CS0618
ListenPipe.Listen(TransportContext.Options.Backlog,
(pipe, status, error, state) => ((ListenerPrimary)state).OnListenPipe(pipe, status, error), this);
#pragma warning restore CS0618
}

private void OnListenPipe(UvStreamHandle pipe, int status, UvException error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv
/// <summary>
/// Provides programmatic configuration of Libuv transport features.
/// </summary>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public class LibuvTransportOptions
{
/// <summary>
Expand All @@ -17,6 +18,7 @@ public class LibuvTransportOptions
/// <remarks>
/// Defaults to half of <see cref="Environment.ProcessorCount" /> rounded down and clamped between 1 and 16.
/// </remarks>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public int ThreadCount { get; set; } = ProcessorThreadCount;

/// <summary>
Expand All @@ -25,6 +27,7 @@ public class LibuvTransportOptions
/// <remarks>
/// Defaults to true.
/// </remarks>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public bool NoDelay { get; set; } = true;

/// <summary>
Expand All @@ -33,10 +36,13 @@ public class LibuvTransportOptions
/// <remarks>
/// Defaults to 128.
/// </remarks>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public int Backlog { get; set; } = 128;

[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public long? MaxReadBufferSize { get; set; } = 1024 * 1024;

[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public long? MaxWriteBufferSize { get; set; } = 64 * 1024;

internal Func<MemoryPool<byte>> MemoryPoolFactory { get; set; } = System.Buffers.SlabMemoryPoolFactory.Create;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Microsoft.AspNetCore.Hosting
{
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public static class WebHostBuilderLibuvExtensions
{
/// <summary>
Expand All @@ -20,6 +21,7 @@ public static class WebHostBuilderLibuvExtensions
/// <returns>
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder.
/// </returns>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public static IWebHostBuilder UseLibuv(this IWebHostBuilder hostBuilder)
{
return hostBuilder.ConfigureServices(services =>
Expand All @@ -40,6 +42,7 @@ public static IWebHostBuilder UseLibuv(this IWebHostBuilder hostBuilder)
/// <returns>
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder.
/// </returns>
[Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)]
public static IWebHostBuilder UseLibuv(this IWebHostBuilder hostBuilder, Action<LibuvTransportOptions> configureOptions)
{
return hostBuilder.UseLibuv().ConfigureServices(services =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public class LibuvTransportFactoryTests
[InlineData(-1337)]
public void StartWithNonPositiveThreadCountThrows(int threadCount)
{
#pragma warning disable CS0618
var options = new LibuvTransportOptions { ThreadCount = threadCount };
#pragma warning restore CS0618

var exception = Assert.Throws<ArgumentOutOfRangeException>(() =>
new LibuvTransportFactory(Options.Create(options), new LifetimeNotImplemented(), Mock.Of<ILoggerFactory>()));
Expand All @@ -30,7 +32,9 @@ public void StartWithNonPositiveThreadCountThrows(int threadCount)
public void LoggerCategoryNameIsLibuvTransportNamespace()
{
var mockLoggerFactory = new Mock<ILoggerFactory>();
#pragma warning disable CS0618
new LibuvTransportFactory(Options.Create<LibuvTransportOptions>(new LibuvTransportOptions()), new LifetimeNotImplemented(), mockLoggerFactory.Object);
#pragma warning restore CS0618
mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public void SetThreadCountUsingProcessorCount()
// Ideally we'd mock Environment.ProcessorCount to test edge cases.
var expected = Clamp(Environment.ProcessorCount >> 1, 1, 16);

#pragma warning disable CS0618
var information = new LibuvTransportOptions();

Assert.Equal(expected, information.ThreadCount);
#pragma warning restore CS0618
}

private static int Clamp(int value, int min, int max)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ public async Task OneToTenThreads(int threadCount)

var transportContext = new TestLibuvTransportContext
{
#pragma warning disable CS0618
Options = new LibuvTransportOptions { ThreadCount = threadCount }
#pragma warning restore CS0618
};

await using var transport = new LibuvConnectionListener(transportContext, listenOptions.EndPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public TestLibuvTransportContext()

AppLifetime = new LifetimeNotImplemented();
Log = new LibuvTrace(logger);
#pragma warning disable CS0618
Options = new LibuvTransportOptions { ThreadCount = 1 };
#pragma warning restore CS0618
}
}
}
2 changes: 2 additions & 0 deletions src/Servers/Kestrel/samples/SampleApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ public static Task Main(string[] args)
if (string.Equals(Process.GetCurrentProcess().Id.ToString(), Environment.GetEnvironmentVariable("LISTEN_PID")))
{
// Use libuv if activated by systemd, since that's currently the only transport that supports being passed a socket handle.
#pragma warning disable CS0618
hostBuilder.UseLibuv(options =>
{
// Uncomment the following line to change the default number of libuv threads for all endpoints.
// options.ThreadCount = 4;
});
#pragma warning restore CS0618
}

return hostBuilder.Build().RunAsync();
Expand Down
2 changes: 2 additions & 0 deletions src/Servers/Kestrel/samples/SystemdTestApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ public static Task Main(string[] args)
if (string.Equals(Process.GetCurrentProcess().Id.ToString(), Environment.GetEnvironmentVariable("LISTEN_PID")))
{
// Use libuv if activated by systemd, since that's currently the only transport that supports being passed a socket handle.
#pragma warning disable CS0618
hostBuilder.UseLibuv(options =>
{
// Uncomment the following line to change the default number of libuv threads for all endpoints.
// options.ThreadCount = 4;
});
#pragma warning restore CS0618
}

return hostBuilder.Build().RunAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public static class TransportSelector
public static IWebHostBuilder GetWebHostBuilder(Func<MemoryPool<byte>> memoryPoolFactory = null,
long? maxReadBufferSize = null)
{
#pragma warning disable CS0618
return new WebHostBuilder().UseLibuv(options =>
{
options.MemoryPoolFactory = memoryPoolFactory ?? options.MemoryPoolFactory;
options.MaxReadBufferSize = maxReadBufferSize;
});
#pragma warning restore CS0618
}
}
}