Skip to content

Commit f543e35

Browse files
authored
Add transport selector interface to Kestrel sockets and QUIC transports (#44832)
1 parent 7f89d9c commit f543e35

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

src/Servers/Kestrel/Transport.Quic/src/QuicTransportFactory.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic;
1313
/// <summary>
1414
/// A factory for QUIC based connections.
1515
/// </summary>
16-
internal sealed class QuicTransportFactory : IMultiplexedConnectionListenerFactory
16+
internal sealed class QuicTransportFactory : IMultiplexedConnectionListenerFactory, IConnectionListenerFactorySelector
1717
{
1818
private readonly ILogger _log;
1919
private readonly QuicTransportOptions _options;
@@ -56,4 +56,9 @@ public async ValueTask<IMultiplexedConnectionListener> BindAsync(EndPoint endpoi
5656

5757
return transport;
5858
}
59+
60+
public bool CanBind(EndPoint endpoint)
61+
{
62+
return endpoint is IPEndPoint;
63+
}
5964
}

src/Servers/Kestrel/Transport.Quic/test/WebHostTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public async Task StartAsync_Http3WithNonIPListener_ThrowError()
390390
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => host.StartAsync()).DefaultTimeout();
391391

392392
// Assert
393-
Assert.Equal("QUIC doesn't support listening on the configured endpoint type. Expected IPEndPoint but got UnixDomainSocketEndPoint.", ex.Message);
393+
Assert.Equal("No registered IMultiplexedConnectionListenerFactory supports endpoint UnixDomainSocketEndPoint: /test-path", ex.Message);
394394
}
395395

396396
private static HttpClient CreateClient()
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.CanBind(System.Net.EndPoint! endpoint) -> bool

src/Servers/Kestrel/Transport.Sockets/src/SocketTransportFactory.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Net;
5+
using System.Net.Sockets;
56
using Microsoft.AspNetCore.Connections;
67
using Microsoft.Extensions.Logging;
78
using Microsoft.Extensions.Options;
@@ -11,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets;
1112
/// <summary>
1213
/// A factory for socket based connections.
1314
/// </summary>
14-
public sealed class SocketTransportFactory : IConnectionListenerFactory
15+
public sealed class SocketTransportFactory : IConnectionListenerFactory, IConnectionListenerFactorySelector
1516
{
1617
private readonly SocketTransportOptions _options;
1718
private readonly ILoggerFactory _logger;
@@ -40,4 +41,16 @@ public ValueTask<IConnectionListener> BindAsync(EndPoint endpoint, CancellationT
4041
transport.Bind();
4142
return new ValueTask<IConnectionListener>(transport);
4243
}
44+
45+
/// <inheritdoc />
46+
public bool CanBind(EndPoint endpoint)
47+
{
48+
return endpoint switch
49+
{
50+
IPEndPoint _ => true,
51+
UnixDomainSocketEndPoint _ => true,
52+
FileHandleEndPoint _ => true,
53+
_ => false
54+
};
55+
}
4356
}

0 commit comments

Comments
 (0)