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
102 changes: 51 additions & 51 deletions src/libraries/System.Net.Quic/ref/System.Net.Quic.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
using System.Threading.Tasks;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Channels;
using System.Diagnostics.CodeAnalysis;

#pragma warning disable IDE0060

namespace System.Net.Quic.Implementations.Managed
{
public sealed partial class ManagedQuicConnection : IAsyncDisposable
public sealed partial class ManagedQuicConnection : QuicConnection, IAsyncDisposable
{
public static bool IsSupported => true;
public static async ValueTask<ManagedQuicConnection> ConnectAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken = default)
public static new bool IsSupported => true;
public static new async ValueTask<ManagedQuicConnection> ConnectAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken = default)
{
var connection = new ManagedQuicConnection(options, TlsFactory.Default);
await connection.ConnectAsync(cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -238,6 +237,7 @@ internal void Ping()

// client constructor
internal ManagedQuicConnection(QuicClientConnectionOptions options, TlsFactory tlsFactory)
: base(true)
{
IsServer = false;
_remoteEndpoint = options.RemoteEndPoint!;
Expand Down Expand Up @@ -266,6 +266,7 @@ internal ManagedQuicConnection(QuicClientConnectionOptions options, TlsFactory t
// server constructor
internal ManagedQuicConnection(QuicServerConnectionOptions options, QuicConnectionContext socketContext,
EndPoint remoteEndpoint, ReadOnlySpan<byte> odcid, TlsFactory tlsFactory)
: base(true)
{
IsServer = true;
_socketContext = socketContext;
Expand Down Expand Up @@ -639,7 +640,7 @@ internal ValueTask DisposeAsync(long errorCode)
return _closeTcs.GetTask();
}

public ValueTask DisposeAsync()
public override ValueTask DisposeAsync()
{
return DisposeAsync((long)TransportErrorCode.NoError);
}
Expand Down Expand Up @@ -711,10 +712,11 @@ private enum ProcessPacketResult
#region Public API


public IPEndPoint LocalEndPoint => _socketContext.LocalEndPoint;
public override IPEndPoint LocalEndPoint => _socketContext.LocalEndPoint;

// TODO-RZ: create a defensive copy of the endpoint
public EndPoint RemoteEndPoint => _remoteEndpoint;
// TODO: get the IP endpoint from the connected socket, not from input options as it might be DNS endpoint that needs to be resolved
public override IPEndPoint RemoteEndPoint => (IPEndPoint)_remoteEndpoint;

#pragma warning disable IDE0060 // Remove unused parameter
internal ValueTask ConnectAsync(CancellationToken cancellationToken = default)
Expand All @@ -731,15 +733,15 @@ internal ValueTask ConnectAsync(CancellationToken cancellationToken = default)
return _connectTcs.GetTask();
}

public async ValueTask<ManagedQuicStream> OpenOutboundStreamAsync(QuicStreamType type, CancellationToken cancellationToken = default)
public override async ValueTask<QuicStream> OpenOutboundStreamAsync(QuicStreamType type, CancellationToken cancellationToken = default)
{
ThrowIfDisposed();
ThrowIfError();

return await OpenStream(type == QuicStreamType.Unidirectional, cancellationToken).ConfigureAwait(false);
}

public async ValueTask<ManagedQuicStream> AcceptInboundStreamAsync(CancellationToken cancellationToken = default)
public override async ValueTask<QuicStream> AcceptInboundStreamAsync(CancellationToken cancellationToken = default)
{
ThrowIfDisposed();
ThrowIfError();
Expand All @@ -754,7 +756,7 @@ public async ValueTask<ManagedQuicStream> AcceptInboundStreamAsync(CancellationT
}
}

public SslApplicationProtocol NegotiatedApplicationProtocol
public override SslApplicationProtocol NegotiatedApplicationProtocol
{
get
{
Expand All @@ -763,9 +765,9 @@ public SslApplicationProtocol NegotiatedApplicationProtocol
}
}

public X509Certificate? RemoteCertificate => throw new NotImplementedException();
public override X509Certificate? RemoteCertificate => throw new NotImplementedException();

public ValueTask CloseAsync(long errorCode, CancellationToken cancellationToken = default)
public override ValueTask CloseAsync(long errorCode, CancellationToken cancellationToken = default)
{
return DisposeAsync(errorCode);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.IO;
using System.Net.Quic.Implementations.Managed.Internal;
using System.Net.Quic.Implementations.Managed.Internal.Sockets;
using System.Net.Quic.Implementations.Managed.Internal.Tls;
using System.Threading;
Expand All @@ -11,10 +9,10 @@

namespace System.Net.Quic.Implementations.Managed
{
public sealed class ManagedQuicListener : IAsyncDisposable
public sealed class ManagedQuicListener : QuicListener, IAsyncDisposable
{
public static bool IsSupported => true;
public static ValueTask<ManagedQuicListener> ListenAsync(QuicListenerOptions options, CancellationToken cancellationToken = default)
public static new bool IsSupported => true;
public static new ValueTask<ManagedQuicListener> ListenAsync(QuicListenerOptions options, CancellationToken cancellationToken = default)
{
return ValueTask.FromResult(new ManagedQuicListener(options));
}
Expand All @@ -25,6 +23,7 @@ public static ValueTask<ManagedQuicListener> ListenAsync(QuicListenerOptions opt
private readonly QuicServerSocketContext _socketContext;

private ManagedQuicListener(QuicListenerOptions options)
: base(true)
{
var listenEndPoint = options.ListenEndPoint ?? new IPEndPoint(IPAddress.Any, 0);

Expand All @@ -42,14 +41,14 @@ private ManagedQuicListener(QuicListenerOptions options)

public IPEndPoint ListenEndPoint => _socketContext.LocalEndPoint;

public ValueTask<ManagedQuicConnection> AcceptConnectionAsync(CancellationToken cancellationToken = default)
public override async ValueTask<QuicConnection> AcceptConnectionAsync(CancellationToken cancellationToken = default)
{
ObjectDisposedException.ThrowIf(_disposed, this);

return _acceptQueue.ReadAsync(cancellationToken);
return await _acceptQueue.ReadAsync(cancellationToken).ConfigureAwait(false);
}

public ValueTask DisposeAsync()
public override ValueTask DisposeAsync()
{
if (_disposed) return ValueTask.CompletedTask;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -14,7 +12,7 @@

namespace System.Net.Quic.Implementations.Managed
{
public sealed class ManagedQuicStream : Stream
public sealed class ManagedQuicStream : QuicStream
{
/// <summary>
/// Node to the linked list of all flushable streams. Should be accessed only by the <see cref="StreamCollection"/> class.
Expand Down Expand Up @@ -58,6 +56,7 @@ public sealed class ManagedQuicStream : Stream
internal SendStream? SendStream { get; }

internal ManagedQuicStream(long streamId, ReceiveStream? receiveStream, SendStream? sendStream, ManagedQuicConnection connection)
: base(true)
{
// trivial check whether buffer nullable combination makes sense with respect to streamId
Debug.Assert(receiveStream != null || sendStream != null);
Expand All @@ -78,17 +77,17 @@ internal ManagedQuicStream(long streamId, ReceiveStream? receiveStream, SendStre
public override bool CanSeek => false;
public override bool CanTimeout => false;

public long Id { get; }
public override long Id { get; }

public override long Length => throw new NotSupportedException();
public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }

public Task ReadClosed => throw new NotImplementedException();
public override Task ReadsClosed => throw new NotImplementedException();
public override int ReadTimeout { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }
public Task WriteClosed => throw new NotImplementedException();
public override Task WritesClosed => throw new NotImplementedException();
public override int WriteTimeout { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }

public void Abort(QuicAbortDirection abortDirection, long errorCode)
public override void Abort(QuicAbortDirection abortDirection, long errorCode)
{
ThrowIfDisposed();

Expand All @@ -103,7 +102,7 @@ public void Abort(QuicAbortDirection abortDirection, long errorCode)
}
}

public void CompleteWrites()
public override void CompleteWrites()
{
ThrowIfDisposed();
ThrowIfConnectionError();
Expand Down Expand Up @@ -209,14 +208,14 @@ public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationTo
return WriteAsync(buffer, false, cancellationToken);
}

public async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, bool endStream, CancellationToken cancellationToken = default)
public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, bool completeWrites, CancellationToken cancellationToken = default)
{
ThrowIfDisposed();
ThrowIfConnectionError();
ThrowIfNotWritable();

// TODO-RZ: optimize away some of the copying
await WriteAsyncInternal(buffer, endStream, cancellationToken).ConfigureAwait(false);
await WriteAsyncInternal(buffer, completeWrites, cancellationToken).ConfigureAwait(false);
await FlushAsync(cancellationToken).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace System.Net.Quic;

public sealed partial class QuicConnection
public partial class QuicConnection
{
public static bool IsSupported => false;
}
26 changes: 16 additions & 10 deletions src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace System.Net.Quic;
/// Each connection can then open outbound stream: <see cref="QuicConnection.OpenOutboundStreamAsync(QuicStreamType, CancellationToken)" />,
/// or accept an inbound stream: <see cref="QuicConnection.AcceptInboundStreamAsync(CancellationToken)" />.
/// </remarks>
public sealed partial class QuicConnection : IAsyncDisposable
public partial class QuicConnection : IAsyncDisposable
{
#if DEBUG
/// <summary>
Expand Down Expand Up @@ -155,23 +155,23 @@ static async ValueTask<QuicConnection> StartConnectAsync(QuicClientConnectionOpt
/// <summary>
/// The remote endpoint used for this connection.
/// </summary>
public IPEndPoint RemoteEndPoint => _remoteEndPoint;
public virtual IPEndPoint RemoteEndPoint => _remoteEndPoint;
/// <summary>
/// The local endpoint used for this connection.
/// </summary>
public IPEndPoint LocalEndPoint => _localEndPoint;
public virtual IPEndPoint LocalEndPoint => _localEndPoint;

/// <summary>
/// Gets the name of the server the client is trying to connect to. That name is used for server certificate validation. It can be a DNS name or an IP address.
/// </summary>
/// <returns>The name of the server the client is trying to connect to.</returns>
public string TargetHostName => _sslConnectionOptions.TargetHost ?? string.Empty;
public virtual string TargetHostName => _sslConnectionOptions.TargetHost ?? string.Empty;

/// <summary>
/// The certificate provided by the peer.
/// For an outbound/client connection will always have the peer's (server) certificate; for an inbound/server one, only if the connection requested and the peer (client) provided one.
/// </summary>
public X509Certificate? RemoteCertificate
public virtual X509Certificate? RemoteCertificate
{
get
{
Expand All @@ -183,11 +183,17 @@ public X509Certificate? RemoteCertificate
/// <summary>
/// Final, negotiated application protocol.
/// </summary>
public SslApplicationProtocol NegotiatedApplicationProtocol => _negotiatedApplicationProtocol;
public virtual SslApplicationProtocol NegotiatedApplicationProtocol => _negotiatedApplicationProtocol;

/// <inheritdoc />
public override string ToString() => _handle.ToString();

protected QuicConnection(bool managed)
{
Debug.Assert(managed);
_handle = null!;
}

/// <summary>
/// Initializes a new instance of an outbound <see cref="QuicConnection" />.
/// </summary>
Expand Down Expand Up @@ -366,7 +372,7 @@ internal ValueTask FinishHandshakeAsync(QuicServerConnectionOptions options, str
/// <param name="type">The type of the stream, i.e. unidirectional or bidirectional.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the asynchronous operation.</param>
/// <returns>An asynchronous task that completes with the opened <see cref="QuicStream" />.</returns>
public async ValueTask<QuicStream> OpenOutboundStreamAsync(QuicStreamType type, CancellationToken cancellationToken = default)
public virtual async ValueTask<QuicStream> OpenOutboundStreamAsync(QuicStreamType type, CancellationToken cancellationToken = default)
{
ObjectDisposedException.ThrowIf(_disposed == 1, this);

Expand Down Expand Up @@ -397,7 +403,7 @@ public async ValueTask<QuicStream> OpenOutboundStreamAsync(QuicStreamType type,
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the asynchronous operation.</param>
/// <returns>An asynchronous task that completes with the accepted <see cref="QuicStream" />.</returns>
public async ValueTask<QuicStream> AcceptInboundStreamAsync(CancellationToken cancellationToken = default)
public virtual async ValueTask<QuicStream> AcceptInboundStreamAsync(CancellationToken cancellationToken = default)
{
ObjectDisposedException.ThrowIf(_disposed == 1, this);

Expand Down Expand Up @@ -436,7 +442,7 @@ public async ValueTask<QuicStream> AcceptInboundStreamAsync(CancellationToken ca
/// <param name="errorCode">Application provided code with the reason for closure.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the asynchronous operation.</param>
/// <returns>An asynchronous task that completes when the connection is closed.</returns>
public ValueTask CloseAsync(long errorCode, CancellationToken cancellationToken = default)
public virtual ValueTask CloseAsync(long errorCode, CancellationToken cancellationToken = default)
{
ObjectDisposedException.ThrowIf(_disposed == 1, this);

Expand Down Expand Up @@ -586,7 +592,7 @@ private static unsafe int NativeCallback(QUIC_HANDLE* connection, void* context,
/// And releases all resources associated with the connection.
/// </summary>
/// <returns>A task that represents the asynchronous dispose operation.</returns>
public async ValueTask DisposeAsync()
public virtual async ValueTask DisposeAsync()
{
if (Interlocked.Exchange(ref _disposed, 1) != 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace System.Net.Quic;

public sealed partial class QuicListener
public partial class QuicListener
{
public static bool IsSupported => false;
}
Loading