From 26502749e780a358bb5454eda6ace2a212e3afd8 Mon Sep 17 00:00:00 2001 From: ManickaP Date: Wed, 15 Jun 2022 09:38:23 +0200 Subject: [PATCH] Removed provider and replaced with statics on Listener and Connection --- .../System/Net/Http/Http3LoopbackServer.cs | 2 +- .../Http/SocketsHttpHandler/ConnectHelper.cs | 2 +- .../SocketsHttpHandler/HttpConnectionPool.cs | 2 +- ...lientHandlerTestBase.SocketsHttpHandler.cs | 2 +- .../System.Net.Quic/ref/System.Net.Quic.cs | 10 +++--- .../src/ExcludeApiList.PNSE.txt | 3 +- .../src/System.Net.Quic.csproj | 4 +-- .../MsQuic/MsQuicConnection.cs | 2 +- .../Net/Quic/QuicConnection.Unsupported.cs | 10 ++++++ .../src/System/Net/Quic/QuicConnection.cs | 13 +++++++ ...pported.cs => QuicListener.Unsupported.cs} | 2 +- .../src/System/Net/Quic/QuicListener.cs | 13 +++++++ .../src/System/Net/Quic/QuicProvider.cs | 35 ------------------- ...icStreamConnectedStreamConformanceTests.cs | 4 +-- .../tests/FunctionalTests/QuicTestBase.cs | 6 ++-- 15 files changed, 55 insertions(+), 55 deletions(-) create mode 100644 src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.Unsupported.cs rename src/libraries/System.Net.Quic/src/System/Net/Quic/{QuicProvider.Unsupported.cs => QuicListener.Unsupported.cs} (83%) delete mode 100644 src/libraries/System.Net.Quic/src/System/Net/Quic/QuicProvider.cs diff --git a/src/libraries/Common/tests/System/Net/Http/Http3LoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/Http3LoopbackServer.cs index 2d749fa7e4097..c3287d7933bb0 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http3LoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http3LoopbackServer.cs @@ -42,7 +42,7 @@ public Http3LoopbackServer(Http3Options options = null) MaxBidirectionalStreams = options.MaxBidirectionalStreams, }; - _listener = QuicProvider.CreateListenerAsync(listenerOptions).Result; + _listener = QuicListener.ListenAsync(listenerOptions).Result; } public override void Dispose() diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs index 7590fdaf60a4f..ec2e912e4a35c 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs @@ -107,7 +107,7 @@ public static async ValueTask EstablishSslConnectionAsync(SslClientAu public static async ValueTask ConnectQuicAsync(HttpRequestMessage request, DnsEndPoint endPoint, SslClientAuthenticationOptions clientAuthenticationOptions, CancellationToken cancellationToken) { clientAuthenticationOptions = SetUpRemoteCertificateValidationCallback(clientAuthenticationOptions, request); - QuicConnection connection = await QuicProvider.CreateConnectionAsync(new QuicClientConnectionOptions() + QuicConnection connection = await QuicConnection.ConnectAsync(new QuicClientConnectionOptions() { RemoteEndPoint = endPoint, ClientAuthenticationOptions = clientAuthenticationOptions diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs index dff8f8e14c2f6..027e01dafd86b 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs @@ -134,7 +134,7 @@ public HttpConnectionPool(HttpConnectionPoolManager poolManager, HttpConnectionK if (IsHttp3Supported()) { - _http3Enabled = _poolManager.Settings._maxHttpVersion >= HttpVersion.Version30 && QuicProvider.IsSupported; + _http3Enabled = _poolManager.Settings._maxHttpVersion >= HttpVersion.Version30 && QuicConnection.IsSupported; } switch (kind) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs index 66d9d0b188433..3d66d05613c81 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs @@ -19,7 +19,7 @@ public static bool IsQuicSupported { try { - return QuicProvider.IsSupported; + return QuicConnection.IsSupported; } catch (System.PlatformNotSupportedException) { diff --git a/src/libraries/System.Net.Quic/ref/System.Net.Quic.cs b/src/libraries/System.Net.Quic/ref/System.Net.Quic.cs index dd9addfac5c56..8e2c856827535 100644 --- a/src/libraries/System.Net.Quic/ref/System.Net.Quic.cs +++ b/src/libraries/System.Net.Quic/ref/System.Net.Quic.cs @@ -17,12 +17,14 @@ public sealed partial class QuicConnection : System.IDisposable { internal QuicConnection() { } public bool Connected { get { throw null; } } + public static bool IsSupported { get { throw null; } } public System.Net.IPEndPoint? LocalEndPoint { get { throw null; } } public System.Net.Security.SslApplicationProtocol NegotiatedApplicationProtocol { get { throw null; } } public System.Security.Cryptography.X509Certificates.X509Certificate? RemoteCertificate { get { throw null; } } public System.Net.EndPoint RemoteEndPoint { get { throw null; } } public System.Threading.Tasks.ValueTask AcceptStreamAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public System.Threading.Tasks.ValueTask CloseAsync(long errorCode, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.ValueTask ConnectAsync(System.Net.Quic.QuicClientConnectionOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public System.Threading.Tasks.ValueTask ConnectAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public void Dispose() { } public int GetRemoteAvailableBidirectionalStreamCount() { throw null; } @@ -44,9 +46,11 @@ public QuicException(string? message, System.Exception? innerException, int resu public sealed partial class QuicListener : System.IDisposable { internal QuicListener() { } + public static bool IsSupported { get { throw null; } } public System.Net.IPEndPoint ListenEndPoint { get { throw null; } } public System.Threading.Tasks.ValueTask AcceptConnectionAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public void Dispose() { } + public static System.Threading.Tasks.ValueTask ListenAsync(System.Net.Quic.QuicListenerOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } public partial class QuicListenerOptions : System.Net.Quic.QuicOptions { @@ -66,12 +70,6 @@ public QuicOptions() { } public int MaxBidirectionalStreams { get { throw null; } set { } } public int MaxUnidirectionalStreams { get { throw null; } set { } } } - public static partial class QuicProvider - { - public static bool IsSupported { get { throw null; } } - public static System.Threading.Tasks.ValueTask CreateConnectionAsync(System.Net.Quic.QuicClientConnectionOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.ValueTask CreateListenerAsync(System.Net.Quic.QuicListenerOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - } public sealed partial class QuicStream : System.IO.Stream { internal QuicStream() { } diff --git a/src/libraries/System.Net.Quic/src/ExcludeApiList.PNSE.txt b/src/libraries/System.Net.Quic/src/ExcludeApiList.PNSE.txt index 25cbd3f4511f6..d6b3f48e2a732 100644 --- a/src/libraries/System.Net.Quic/src/ExcludeApiList.PNSE.txt +++ b/src/libraries/System.Net.Quic/src/ExcludeApiList.PNSE.txt @@ -1 +1,2 @@ -P:System.Net.Quic.QuicProvider.IsSupported \ No newline at end of file +P:System.Net.Quic.QuicConnection.IsSupported +P:System.Net.Quic.QuicListener.IsSupported \ No newline at end of file diff --git a/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj b/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj index 234ad7272a8d9..a989b8dd455ff 100644 --- a/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj +++ b/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj @@ -18,7 +18,6 @@ - @@ -42,7 +41,8 @@ - + + diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicConnection.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicConnection.cs index cbcc4f83348e2..8dfc80218bfa4 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicConnection.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicConnection.cs @@ -497,7 +497,7 @@ internal int GetRemoteAvailableBidirectionalStreamCount() return MsQuicParameterHelpers.GetUShortParam(MsQuicApi.Api, _state.Handle, QUIC_PARAM_CONN_LOCAL_BIDI_STREAM_COUNT); } - internal unsafe override ValueTask ConnectAsync(CancellationToken cancellationToken = default) + internal unsafe ValueTask ConnectAsync(CancellationToken cancellationToken = default) { ThrowIfDisposed(); diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.Unsupported.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.Unsupported.cs new file mode 100644 index 0000000000000..93ad515214433 --- /dev/null +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.Unsupported.cs @@ -0,0 +1,10 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Net.Quic +{ + public sealed partial class QuicConnection + { + public static bool IsSupported => false; + } +} diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs index b5ee819f5527b..b919e6e9d38b6 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs @@ -3,6 +3,7 @@ using System.Net.Quic.Implementations; using System.Net.Quic.Implementations.MsQuic; +using System.Net.Quic.Implementations.MsQuic.Internal; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Threading; @@ -12,6 +13,18 @@ namespace System.Net.Quic { public sealed class QuicConnection : IDisposable { + public static bool IsSupported => MsQuicApi.IsQuicSupported; + + public static ValueTask ConnectAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken = default) + { + if (!IsSupported) + { + throw new PlatformNotSupportedException(SR.SystemNetQuic_PlatformNotSupported); + } + + return ValueTask.FromResult(new QuicConnection(new MsQuicConnection(options))); + } + private readonly MsQuicConnection _provider; internal QuicConnection(MsQuicConnection provider) diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicProvider.Unsupported.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.Unsupported.cs similarity index 83% rename from src/libraries/System.Net.Quic/src/System/Net/Quic/QuicProvider.Unsupported.cs rename to src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.Unsupported.cs index b860c936e5166..6d37aeff8a0b6 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicProvider.Unsupported.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.Unsupported.cs @@ -3,7 +3,7 @@ namespace System.Net.Quic { - public static partial class QuicProvider + public sealed partial class QuicListener { public static bool IsSupported => false; } diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.cs index 8c31a7c487536..9d29f34176d1f 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.cs @@ -3,6 +3,7 @@ using System.Net.Quic.Implementations; using System.Net.Quic.Implementations.MsQuic; +using System.Net.Quic.Implementations.MsQuic.Internal; using System.Net.Security; using System.Threading; using System.Threading.Tasks; @@ -11,6 +12,18 @@ namespace System.Net.Quic { public sealed class QuicListener : IDisposable { + public static bool IsSupported => MsQuicApi.IsQuicSupported; + + public static ValueTask ListenAsync(QuicListenerOptions options, CancellationToken cancellationToken = default) + { + if (!IsSupported) + { + throw new PlatformNotSupportedException(SR.SystemNetQuic_PlatformNotSupported); + } + + return ValueTask.FromResult(new QuicListener(new MsQuicListener(options))); + } + private readonly MsQuicListener _provider; internal QuicListener(MsQuicListener provider) diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicProvider.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicProvider.cs deleted file mode 100644 index c06e41cbec534..0000000000000 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicProvider.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Net.Quic.Implementations.MsQuic; -using System.Net.Quic.Implementations.MsQuic.Internal; -using System.Threading; -using System.Threading.Tasks; - -namespace System.Net.Quic -{ - public static partial class QuicProvider - { - public static bool IsSupported => MsQuicApi.IsQuicSupported; - - public static ValueTask CreateListenerAsync(QuicListenerOptions options, CancellationToken cancellationToken = default) - { - if (!IsSupported) - { - throw new PlatformNotSupportedException(SR.SystemNetQuic_PlatformNotSupported); - } - - return ValueTask.FromResult(new QuicListener(new MsQuicListener(options))); - } - - public static ValueTask CreateConnectionAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken = default) - { - if (!IsSupported) - { - throw new PlatformNotSupportedException(SR.SystemNetQuic_PlatformNotSupported); - } - - return ValueTask.FromResult(new QuicConnection(new MsQuicConnection(options))); - } - } -} diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicStreamConnectedStreamConformanceTests.cs b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicStreamConnectedStreamConformanceTests.cs index 1b8e1d5639b76..f0ac82216343a 100644 --- a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicStreamConnectedStreamConformanceTests.cs +++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicStreamConnectedStreamConformanceTests.cs @@ -51,7 +51,7 @@ public SslClientAuthenticationOptions GetSslClientAuthenticationOptions() protected override async Task CreateConnectedStreamsAsync() { - var listener = await QuicProvider.CreateListenerAsync(new QuicListenerOptions() + var listener = await QuicListener.ListenAsync(new QuicListenerOptions() { ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0), ServerAuthenticationOptions = GetSslServerAuthenticationOptions() @@ -71,7 +71,7 @@ await WhenAllOrAnyFailed( { try { - connection2 = await QuicProvider.CreateConnectionAsync(new QuicClientConnectionOptions() + connection2 = await QuicConnection.ConnectAsync(new QuicClientConnectionOptions() { RemoteEndPoint = listener.ListenEndPoint, ClientAuthenticationOptions = GetSslClientAuthenticationOptions() diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs index 48880043bfae6..8f970cf6e3f72 100644 --- a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs +++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs @@ -21,7 +21,7 @@ public abstract class QuicTestBase private static readonly byte[] s_ping = "PING"u8.ToArray(); private static readonly byte[] s_pong = "PONG"u8.ToArray(); - public static bool IsSupported => QuicProvider.IsSupported; + public static bool IsSupported => QuicListener.IsSupported && QuicConnection.IsSupported; public static SslApplicationProtocol ApplicationProtocol { get; } = new SslApplicationProtocol("quictest"); @@ -78,7 +78,7 @@ internal ValueTask CreateQuicConnection(IPEndPoint endpoint) internal ValueTask CreateQuicConnection(QuicClientConnectionOptions clientOptions) { - return QuicProvider.CreateConnectionAsync(clientOptions); + return QuicConnection.ConnectAsync(clientOptions); } internal QuicListenerOptions CreateQuicListenerOptions() @@ -109,7 +109,7 @@ internal ValueTask CreateQuicListener(IPEndPoint endpoint) return CreateQuicListener(options); } - internal ValueTask CreateQuicListener(QuicListenerOptions options) => QuicProvider.CreateListenerAsync(options); + internal ValueTask CreateQuicListener(QuicListenerOptions options) => QuicListener.ListenAsync(options); internal Task<(QuicConnection, QuicConnection)> CreateConnectedQuicConnection(QuicListener listener) => CreateConnectedQuicConnection(null, listener); internal async Task<(QuicConnection, QuicConnection)> CreateConnectedQuicConnection(QuicClientConnectionOptions? clientOptions, QuicListenerOptions listenerOptions)