Skip to content

Commit

Permalink
Removed provider and replaced with statics on Listener and Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ManickaP committed Jun 15, 2022
1 parent 2f88af1 commit 2650274
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static async ValueTask<SslStream> EstablishSslConnectionAsync(SslClientAu
public static async ValueTask<QuicConnection> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static bool IsQuicSupported
{
try
{
return QuicProvider.IsSupported;
return QuicConnection.IsSupported;
}
catch (System.PlatformNotSupportedException)
{
Expand Down
10 changes: 4 additions & 6 deletions src/libraries/System.Net.Quic/ref/System.Net.Quic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<System.Net.Quic.QuicStream> 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<System.Net.Quic.QuicConnection> 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; }
Expand All @@ -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<System.Net.Quic.QuicConnection> AcceptConnectionAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public void Dispose() { }
public static System.Threading.Tasks.ValueTask<System.Net.Quic.QuicListener> ListenAsync(System.Net.Quic.QuicListenerOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class QuicListenerOptions : System.Net.Quic.QuicOptions
{
Expand All @@ -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<System.Net.Quic.QuicConnection> CreateConnectionAsync(System.Net.Quic.QuicClientConnectionOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.ValueTask<System.Net.Quic.QuicListener> 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() { }
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/System.Net.Quic/src/ExcludeApiList.PNSE.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
P:System.Net.Quic.QuicProvider.IsSupported
P:System.Net.Quic.QuicConnection.IsSupported
P:System.Net.Quic.QuicListener.IsSupported
4 changes: 2 additions & 2 deletions src/libraries/System.Net.Quic/src/System.Net.Quic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<Compile Include="System\Net\Quic\QuicConnection.cs" />
<Compile Include="System\Net\Quic\QuicConnectionAbortedException.cs" />
<Compile Include="System\Net\Quic\QuicException.cs" />
<Compile Include="System\Net\Quic\QuicProvider.cs" />
<Compile Include="System\Net\Quic\QuicListener.cs" />
<Compile Include="System\Net\Quic\QuicListenerOptions.cs" />
<Compile Include="System\Net\Quic\QuicOperationAbortedException.cs" />
Expand All @@ -42,7 +41,8 @@
</ItemGroup>
<!-- Unsupported platforms -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == ''">
<Compile Include="System\Net\Quic\QuicProvider.Unsupported.cs" />
<Compile Include="System\Net\Quic\QuicListener.Unsupported.cs" />
<Compile Include="System\Net\Quic\QuicConnection.Unsupported.cs" />
</ItemGroup>
<!-- Windows specific files -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,6 +13,18 @@ namespace System.Net.Quic
{
public sealed class QuicConnection : IDisposable
{
public static bool IsSupported => MsQuicApi.IsQuicSupported;

public static ValueTask<QuicConnection> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace System.Net.Quic
{
public static partial class QuicProvider
public sealed partial class QuicListener
{
public static bool IsSupported => false;
}
Expand Down
13 changes: 13 additions & 0 deletions src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,6 +12,18 @@ namespace System.Net.Quic
{
public sealed class QuicListener : IDisposable
{
public static bool IsSupported => MsQuicApi.IsQuicSupported;

public static ValueTask<QuicListener> 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)
Expand Down
35 changes: 0 additions & 35 deletions src/libraries/System.Net.Quic/src/System/Net/Quic/QuicProvider.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public SslClientAuthenticationOptions GetSslClientAuthenticationOptions()

protected override async Task<StreamPair> CreateConnectedStreamsAsync()
{
var listener = await QuicProvider.CreateListenerAsync(new QuicListenerOptions()
var listener = await QuicListener.ListenAsync(new QuicListenerOptions()
{
ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0),
ServerAuthenticationOptions = GetSslServerAuthenticationOptions()
Expand All @@ -71,7 +71,7 @@ await WhenAllOrAnyFailed(
{
try
{
connection2 = await QuicProvider.CreateConnectionAsync(new QuicClientConnectionOptions()
connection2 = await QuicConnection.ConnectAsync(new QuicClientConnectionOptions()
{
RemoteEndPoint = listener.ListenEndPoint,
ClientAuthenticationOptions = GetSslClientAuthenticationOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -78,7 +78,7 @@ internal ValueTask<QuicConnection> CreateQuicConnection(IPEndPoint endpoint)

internal ValueTask<QuicConnection> CreateQuicConnection(QuicClientConnectionOptions clientOptions)
{
return QuicProvider.CreateConnectionAsync(clientOptions);
return QuicConnection.ConnectAsync(clientOptions);
}

internal QuicListenerOptions CreateQuicListenerOptions()
Expand Down Expand Up @@ -109,7 +109,7 @@ internal ValueTask<QuicListener> CreateQuicListener(IPEndPoint endpoint)
return CreateQuicListener(options);
}

internal ValueTask<QuicListener> CreateQuicListener(QuicListenerOptions options) => QuicProvider.CreateListenerAsync(options);
internal ValueTask<QuicListener> 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)
Expand Down

0 comments on commit 2650274

Please sign in to comment.