Skip to content

Commit

Permalink
Add transport selector interface to Kestrel sockets and QUIC transpor…
Browse files Browse the repository at this point in the history
…ts (#44832)
  • Loading branch information
JamesNK authored Dec 9, 2022
1 parent 7f89d9c commit f543e35
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic;
/// <summary>
/// A factory for QUIC based connections.
/// </summary>
internal sealed class QuicTransportFactory : IMultiplexedConnectionListenerFactory
internal sealed class QuicTransportFactory : IMultiplexedConnectionListenerFactory, IConnectionListenerFactorySelector
{
private readonly ILogger _log;
private readonly QuicTransportOptions _options;
Expand Down Expand Up @@ -56,4 +56,9 @@ public async ValueTask<IMultiplexedConnectionListener> BindAsync(EndPoint endpoi

return transport;
}

public bool CanBind(EndPoint endpoint)
{
return endpoint is IPEndPoint;
}
}
2 changes: 1 addition & 1 deletion src/Servers/Kestrel/Transport.Quic/test/WebHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public async Task StartAsync_Http3WithNonIPListener_ThrowError()
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => host.StartAsync()).DefaultTimeout();

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

private static HttpClient CreateClient()
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.CanBind(System.Net.EndPoint! endpoint) -> bool
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Net;
using System.Net.Sockets;
using Microsoft.AspNetCore.Connections;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand All @@ -11,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets;
/// <summary>
/// A factory for socket based connections.
/// </summary>
public sealed class SocketTransportFactory : IConnectionListenerFactory
public sealed class SocketTransportFactory : IConnectionListenerFactory, IConnectionListenerFactorySelector
{
private readonly SocketTransportOptions _options;
private readonly ILoggerFactory _logger;
Expand Down Expand Up @@ -40,4 +41,16 @@ public ValueTask<IConnectionListener> BindAsync(EndPoint endpoint, CancellationT
transport.Bind();
return new ValueTask<IConnectionListener>(transport);
}

/// <inheritdoc />
public bool CanBind(EndPoint endpoint)
{
return endpoint switch
{
IPEndPoint _ => true,
UnixDomainSocketEndPoint _ => true,
FileHandleEndPoint _ => true,
_ => false
};
}
}

0 comments on commit f543e35

Please sign in to comment.