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 @@ -14,13 +14,16 @@
using System.Net.Quic.Implementations.Managed.Internal.Streams;
using System.Net.Quic.Implementations.Managed.Internal.Tracing;
using System.Net.Quic.Implementations.Managed.Internal.Tls;
using System.Net.Quic.Implementations.Managed.Internal.Tls.OpenSsl;
using System.Net.Security;
using System.Threading;
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
Expand Down Expand Up @@ -69,6 +72,8 @@ public sealed partial class ManagedQuicConnection : IAsyncDisposable
/// </summary>
private bool IsClosing => _closingPeriodEndTimestamp != null;

private bool Connected => HandshakeConfirmed;

/// <summary>
/// Timestamp when the connection close will be initiated due to lack of packets from peer.
/// </summary>
Expand Down Expand Up @@ -607,7 +612,7 @@ internal ValueTask DisposeAsync(long errorCode)
if (!Connected)
{
// abandon connection attempt
_connectTcs.TryCompleteException(new QuicException(QuicError.ConnectionAborted, errorCode));
_connectTcs.TryCompleteException(new QuicException(QuicError.ConnectionAborted, errorCode, "Abandon connection attempt"));
_closeTcs.TryComplete();
return default;
}
Expand Down Expand Up @@ -775,7 +780,7 @@ internal void ThrowIfError()
if (!_outboundError.IsQuicError)
{
// connection close initiated by application
throw new QuicOperationAbortedException();
throw new QuicException(QuicError.ConnectionAborted, (long)_outboundError.ErrorCode, "Connection close initiated by application");
}
else if (_outboundError.ErrorCode != TransportErrorCode.NoError)
{
Expand Down Expand Up @@ -893,12 +898,12 @@ private QuicException MakeOperationAbortedException()
{
return _inboundError != null
? MakeConnectionAbortedException(_inboundError) // initiated by peer
: new QuicOperationAbortedException(); // initiated by us
: new QuicException(QuicError.OperationAborted, null, "Initiated by us");
}

private static QuicException MakeConnectionAbortedException(QuicTransportError error)
{
return new QuicException(QuicError.ConnectionAborted, (long)error.ErrorCode, error.ReasonPhrase);
return new QuicException(QuicError.ConnectionAborted, (long)error.ErrorCode, error.ReasonPhrase ?? "");
}

internal void OnSocketContextException(Exception e)
Expand All @@ -924,3 +929,5 @@ internal void DoCleanup()
}
}
}

#pragma warning restore IDE0060
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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.Net.Quic.Implementations.Managed.Internal.Tls.OpenSsl;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
Expand Down Expand Up @@ -51,11 +52,13 @@ public ValueTask<ManagedQuicConnection> AcceptConnectionAsync(CancellationToken

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

_disposed = true;

_socketContext.StopOrOrphan();

return ValueTask.CompletedTask;
}
}
}