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 @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be an explicit interface implementation if we don't want it public.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anyone do this? Probably not. If someone is using a custom endpoint type to pass in custom values to the factory method, a workaround to this change is to inherit from one of the supported endpoint types, e.g. IPEndPoint, and add new members..

Would another workaround be to make CanBind virtual so they can derive from the transport and override it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementing a new interface on a public type is an API change with or without an explicit interface implementation. It doesn't matter what our PublicAPI.Unshipped.txt files have to say about it.

Personally, I think we should make CanBind fully public. It's not like it adds a lot of clutter to the AIP surface of SocketTransportFactory.

Copy link
Member Author

@JamesNK JamesNK Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, CanBind can stay public.

I don't like making CanBind virtual. Nothing else on this type is designed to be extended with inheritance. For example, the create socket factory method is configured via options as a func. If we want to allow people to customize CanBind, then it should also be a func on the options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #45035 so we can discuss it in API review. I like it though.

{
return endpoint switch
{
IPEndPoint _ => true,
UnixDomainSocketEndPoint _ => true,
FileHandleEndPoint _ => true,
_ => false
};
}
}