Sync shared code from runtime (#23843)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2020-07-10 09:40:47 -07:00 committed by GitHub
parent 5d170de769
commit c45e0d707d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 83 deletions

View File

@ -29,8 +29,8 @@ namespace System.Net
// Usage: // Usage:
// - Operations that may allocate (e.g. boxing a value type, using string interpolation, etc.) or that may have computations // - Operations that may allocate (e.g. boxing a value type, using string interpolation, etc.) or that may have computations
// at call sites should guard access like: // at call sites should guard access like:
// if (NetEventSource.IsEnabled) NetEventSource.Enter(this, refArg1, valueTypeArg2); // entering an instance method with a value type arg // if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this, refArg1, valueTypeArg2); // entering an instance method with a value type arg
// if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"Found certificate: {cert}"); // info logging with a formattable string // if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(null, $"Found certificate: {cert}"); // info logging with a formattable string
// - Operations that have zero allocations / measurable computations at call sites can use a simpler pattern, calling methods like: // - Operations that have zero allocations / measurable computations at call sites can use a simpler pattern, calling methods like:
// NetEventSource.Enter(this); // entering an instance method // NetEventSource.Enter(this); // entering an instance method
// NetEventSource.Info(this, "literal string"); // arbitrary message with a literal string // NetEventSource.Info(this, "literal string"); // arbitrary message with a literal string
@ -103,7 +103,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString); DebugValidateArg(formattableString);
if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters);
} }
/// <summary>Logs entrance to a method.</summary> /// <summary>Logs entrance to a method.</summary>
@ -115,7 +115,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0); DebugValidateArg(arg0);
if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)})"); if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)})");
} }
/// <summary>Logs entrance to a method.</summary> /// <summary>Logs entrance to a method.</summary>
@ -129,7 +129,7 @@ namespace System.Net
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0); DebugValidateArg(arg0);
DebugValidateArg(arg1); DebugValidateArg(arg1);
if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)})"); if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)})");
} }
/// <summary>Logs entrance to a method.</summary> /// <summary>Logs entrance to a method.</summary>
@ -145,7 +145,7 @@ namespace System.Net
DebugValidateArg(arg0); DebugValidateArg(arg0);
DebugValidateArg(arg1); DebugValidateArg(arg1);
DebugValidateArg(arg2); DebugValidateArg(arg2);
if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)}, {Format(arg2)})"); if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)}, {Format(arg2)})");
} }
[Event(EnterEventId, Level = EventLevel.Informational, Keywords = Keywords.EnterExit)] [Event(EnterEventId, Level = EventLevel.Informational, Keywords = Keywords.EnterExit)]
@ -163,7 +163,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString); DebugValidateArg(formattableString);
if (IsEnabled) Log.Exit(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); if (Log.IsEnabled()) Log.Exit(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters);
} }
/// <summary>Logs exit from a method.</summary> /// <summary>Logs exit from a method.</summary>
@ -175,7 +175,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0); DebugValidateArg(arg0);
if (IsEnabled) Log.Exit(IdOf(thisOrContextObject), memberName, Format(arg0).ToString()); if (Log.IsEnabled()) Log.Exit(IdOf(thisOrContextObject), memberName, Format(arg0).ToString());
} }
/// <summary>Logs exit from a method.</summary> /// <summary>Logs exit from a method.</summary>
@ -189,7 +189,7 @@ namespace System.Net
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0); DebugValidateArg(arg0);
DebugValidateArg(arg1); DebugValidateArg(arg1);
if (IsEnabled) Log.Exit(IdOf(thisOrContextObject), memberName, $"{Format(arg0)}, {Format(arg1)}"); if (Log.IsEnabled()) Log.Exit(IdOf(thisOrContextObject), memberName, $"{Format(arg0)}, {Format(arg1)}");
} }
[Event(ExitEventId, Level = EventLevel.Informational, Keywords = Keywords.EnterExit)] [Event(ExitEventId, Level = EventLevel.Informational, Keywords = Keywords.EnterExit)]
@ -207,7 +207,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString); DebugValidateArg(formattableString);
if (IsEnabled) Log.Info(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); if (Log.IsEnabled()) Log.Info(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters);
} }
/// <summary>Logs an information message.</summary> /// <summary>Logs an information message.</summary>
@ -219,7 +219,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(message); DebugValidateArg(message);
if (IsEnabled) Log.Info(IdOf(thisOrContextObject), memberName, Format(message).ToString()); if (Log.IsEnabled()) Log.Info(IdOf(thisOrContextObject), memberName, Format(message).ToString());
} }
[Event(InfoEventId, Level = EventLevel.Informational, Keywords = Keywords.Default)] [Event(InfoEventId, Level = EventLevel.Informational, Keywords = Keywords.Default)]
@ -237,7 +237,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString); DebugValidateArg(formattableString);
if (IsEnabled) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString)); if (Log.IsEnabled()) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString));
} }
/// <summary>Logs an error message.</summary> /// <summary>Logs an error message.</summary>
@ -249,7 +249,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(message); DebugValidateArg(message);
if (IsEnabled) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(message).ToString()); if (Log.IsEnabled()) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(message).ToString());
} }
[Event(ErrorEventId, Level = EventLevel.Error, Keywords = Keywords.Default)] [Event(ErrorEventId, Level = EventLevel.Error, Keywords = Keywords.Default)]
@ -268,7 +268,7 @@ namespace System.Net
// Don't call DebugValidateArg on args, as we expect Fail to be used in assert/failure situations // Don't call DebugValidateArg on args, as we expect Fail to be used in assert/failure situations
// that should never happen in production, and thus we don't care about extra costs. // that should never happen in production, and thus we don't care about extra costs.
if (IsEnabled) Log.CriticalFailure(IdOf(thisOrContextObject), memberName, Format(formattableString)); if (Log.IsEnabled()) Log.CriticalFailure(IdOf(thisOrContextObject), memberName, Format(formattableString));
Debug.Fail(Format(formattableString), $"{IdOf(thisOrContextObject)}.{memberName}"); Debug.Fail(Format(formattableString), $"{IdOf(thisOrContextObject)}.{memberName}");
} }
@ -282,7 +282,7 @@ namespace System.Net
// Don't call DebugValidateArg on args, as we expect Fail to be used in assert/failure situations // Don't call DebugValidateArg on args, as we expect Fail to be used in assert/failure situations
// that should never happen in production, and thus we don't care about extra costs. // that should never happen in production, and thus we don't care about extra costs.
if (IsEnabled) Log.CriticalFailure(IdOf(thisOrContextObject), memberName, Format(message).ToString()); if (Log.IsEnabled()) Log.CriticalFailure(IdOf(thisOrContextObject), memberName, Format(message).ToString());
Debug.Fail(Format(message).ToString(), $"{IdOf(thisOrContextObject)}.{memberName}"); Debug.Fail(Format(message).ToString(), $"{IdOf(thisOrContextObject)}.{memberName}");
} }
@ -311,7 +311,7 @@ namespace System.Net
[NonEvent] [NonEvent]
public static void DumpBuffer(object? thisOrContextObject, byte[] buffer, int offset, int count, [CallerMemberName] string? memberName = null) public static void DumpBuffer(object? thisOrContextObject, byte[] buffer, int offset, int count, [CallerMemberName] string? memberName = null)
{ {
if (IsEnabled) if (Log.IsEnabled())
{ {
if (offset < 0 || offset > buffer.Length - count) if (offset < 0 || offset > buffer.Length - count)
{ {
@ -343,7 +343,7 @@ namespace System.Net
Debug.Assert(bufferPtr != IntPtr.Zero); Debug.Assert(bufferPtr != IntPtr.Zero);
Debug.Assert(count >= 0); Debug.Assert(count >= 0);
if (IsEnabled) if (Log.IsEnabled())
{ {
var buffer = new byte[Math.Min(count, MaxDumpSize)]; var buffer = new byte[Math.Min(count, MaxDumpSize)];
fixed (byte* targetPtr = buffer) fixed (byte* targetPtr = buffer)
@ -369,7 +369,7 @@ namespace System.Net
{ {
DebugValidateArg(first); DebugValidateArg(first);
DebugValidateArg(second); DebugValidateArg(second);
if (IsEnabled) Log.Associate(IdOf(first), memberName, IdOf(first), IdOf(second)); if (Log.IsEnabled()) Log.Associate(IdOf(first), memberName, IdOf(first), IdOf(second));
} }
/// <summary>Logs a relationship between two objects.</summary> /// <summary>Logs a relationship between two objects.</summary>
@ -383,7 +383,7 @@ namespace System.Net
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(first); DebugValidateArg(first);
DebugValidateArg(second); DebugValidateArg(second);
if (IsEnabled) Log.Associate(IdOf(thisOrContextObject), memberName, IdOf(first), IdOf(second)); if (Log.IsEnabled()) Log.Associate(IdOf(thisOrContextObject), memberName, IdOf(first), IdOf(second));
} }
[Event(AssociateEventId, Level = EventLevel.Informational, Keywords = Keywords.Default, Message = "[{2}]<-->[{3}]")] [Event(AssociateEventId, Level = EventLevel.Informational, Keywords = Keywords.Default, Message = "[{2}]<-->[{3}]")]
@ -396,7 +396,7 @@ namespace System.Net
[Conditional("DEBUG_NETEVENTSOURCE_MISUSE")] [Conditional("DEBUG_NETEVENTSOURCE_MISUSE")]
private static void DebugValidateArg(object? arg) private static void DebugValidateArg(object? arg)
{ {
if (!IsEnabled) if (!Log.IsEnabled())
{ {
Debug.Assert(!(arg is ValueType), $"Should not be passing value type {arg?.GetType()} to logging without IsEnabled check"); Debug.Assert(!(arg is ValueType), $"Should not be passing value type {arg?.GetType()} to logging without IsEnabled check");
Debug.Assert(!(arg is FormattableString), $"Should not be formatting FormattableString \"{arg}\" if tracing isn't enabled"); Debug.Assert(!(arg is FormattableString), $"Should not be formatting FormattableString \"{arg}\" if tracing isn't enabled");
@ -406,12 +406,9 @@ namespace System.Net
[Conditional("DEBUG_NETEVENTSOURCE_MISUSE")] [Conditional("DEBUG_NETEVENTSOURCE_MISUSE")]
private static void DebugValidateArg(FormattableString? arg) private static void DebugValidateArg(FormattableString? arg)
{ {
Debug.Assert(IsEnabled || arg == null, $"Should not be formatting FormattableString \"{arg}\" if tracing isn't enabled"); Debug.Assert(Log.IsEnabled() || arg == null, $"Should not be formatting FormattableString \"{arg}\" if tracing isn't enabled");
} }
public static new bool IsEnabled =>
Log.IsEnabled();
[NonEvent] [NonEvent]
public static string IdOf(object? value) => value != null ? value.GetType().Name + "#" + GetHashCode(value) : NullInstance; public static string IdOf(object? value) => value != null ? value.GetType().Name + "#" + GetHashCode(value) : NullInstance;

View File

@ -51,20 +51,20 @@ namespace System.Net.Quic.Implementations.MsQuic
// constructor for inbound connections // constructor for inbound connections
public MsQuicConnection(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, IntPtr nativeObjPtr) public MsQuicConnection(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, IntPtr nativeObjPtr)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
_localEndPoint = localEndPoint; _localEndPoint = localEndPoint;
_remoteEndPoint = remoteEndPoint; _remoteEndPoint = remoteEndPoint;
_ptr = nativeObjPtr; _ptr = nativeObjPtr;
SetCallbackHandler(); SetCallbackHandler();
SetIdleTimeout(TimeSpan.FromSeconds(120)); SetIdleTimeout(TimeSpan.FromSeconds(120));
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
} }
// constructor for outbound connections // constructor for outbound connections
public MsQuicConnection(QuicClientConnectionOptions options) public MsQuicConnection(QuicClientConnectionOptions options)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
// TODO need to figure out if/how we want to expose sessions // TODO need to figure out if/how we want to expose sessions
// Creating a session per connection isn't ideal. // Creating a session per connection isn't ideal.
@ -75,7 +75,7 @@ namespace System.Net.Quic.Implementations.MsQuic
SetCallbackHandler(); SetCallbackHandler();
SetIdleTimeout(options.IdleTimeout); SetIdleTimeout(options.IdleTimeout);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
} }
internal override IPEndPoint LocalEndPoint internal override IPEndPoint LocalEndPoint
@ -168,7 +168,7 @@ namespace System.Net.Quic.Implementations.MsQuic
private uint HandleEventConnected(ConnectionEvent connectionEvent) private uint HandleEventConnected(ConnectionEvent connectionEvent)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
SOCKADDR_INET inetAddress = MsQuicParameterHelpers.GetINetParam(MsQuicApi.Api, _ptr, (uint)QUIC_PARAM_LEVEL.CONNECTION, (uint)QUIC_PARAM_CONN.LOCAL_ADDRESS); SOCKADDR_INET inetAddress = MsQuicParameterHelpers.GetINetParam(MsQuicApi.Api, _ptr, (uint)QUIC_PARAM_LEVEL.CONNECTION, (uint)QUIC_PARAM_CONN.LOCAL_ADDRESS);
_localEndPoint = MsQuicAddressHelpers.INetToIPEndPoint(inetAddress); _localEndPoint = MsQuicAddressHelpers.INetToIPEndPoint(inetAddress);
@ -179,13 +179,13 @@ namespace System.Net.Quic.Implementations.MsQuic
// handle event shutdown initiated by transport // handle event shutdown initiated by transport
_connectTcs.Complete(MsQuicStatusCodes.Success); _connectTcs.Complete(MsQuicStatusCodes.Success);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleEventShutdownInitiatedByTransport(ConnectionEvent connectionEvent) private uint HandleEventShutdownInitiatedByTransport(ConnectionEvent connectionEvent)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
if (!_connected) if (!_connected)
{ {
@ -194,7 +194,7 @@ namespace System.Net.Quic.Implementations.MsQuic
_acceptQueue.Writer.Complete(); _acceptQueue.Writer.Complete();
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
@ -208,22 +208,22 @@ namespace System.Net.Quic.Implementations.MsQuic
private uint HandleEventShutdownComplete(ConnectionEvent connectionEvent) private uint HandleEventShutdownComplete(ConnectionEvent connectionEvent)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
_shutdownTcs.Complete(MsQuicStatusCodes.Success); _shutdownTcs.Complete(MsQuicStatusCodes.Success);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleEventNewStream(ConnectionEvent connectionEvent) private uint HandleEventNewStream(ConnectionEvent connectionEvent)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
MsQuicStream msQuicStream = new MsQuicStream(this, connectionEvent.StreamFlags, connectionEvent.Data.NewStream.Stream, inbound: true); MsQuicStream msQuicStream = new MsQuicStream(this, connectionEvent.StreamFlags, connectionEvent.Data.NewStream.Stream, inbound: true);
_acceptQueue.Writer.TryWrite(msQuicStream); _acceptQueue.Writer.TryWrite(msQuicStream);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
@ -235,7 +235,7 @@ namespace System.Net.Quic.Implementations.MsQuic
internal override async ValueTask<QuicStreamProvider> AcceptStreamAsync(CancellationToken cancellationToken = default) internal override async ValueTask<QuicStreamProvider> AcceptStreamAsync(CancellationToken cancellationToken = default)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
@ -254,7 +254,7 @@ namespace System.Net.Quic.Implementations.MsQuic
}; };
} }
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return stream; return stream;
} }
@ -305,7 +305,7 @@ namespace System.Net.Quic.Implementations.MsQuic
private MsQuicStream StreamOpen( private MsQuicStream StreamOpen(
QUIC_STREAM_OPEN_FLAG flags) QUIC_STREAM_OPEN_FLAG flags)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
IntPtr streamPtr = IntPtr.Zero; IntPtr streamPtr = IntPtr.Zero;
QuicExceptionHelpers.ThrowIfFailed( QuicExceptionHelpers.ThrowIfFailed(
@ -319,7 +319,7 @@ namespace System.Net.Quic.Implementations.MsQuic
MsQuicStream stream = new MsQuicStream(this, flags, streamPtr, inbound: false); MsQuicStream stream = new MsQuicStream(this, flags, streamPtr, inbound: false);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return stream; return stream;
} }
@ -337,7 +337,7 @@ namespace System.Net.Quic.Implementations.MsQuic
QUIC_CONNECTION_SHUTDOWN_FLAG Flags, QUIC_CONNECTION_SHUTDOWN_FLAG Flags,
long ErrorCode) long ErrorCode)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
uint status = MsQuicApi.Api.ConnectionShutdownDelegate( uint status = MsQuicApi.Api.ConnectionShutdownDelegate(
_ptr, _ptr,
@ -345,7 +345,7 @@ namespace System.Net.Quic.Implementations.MsQuic
ErrorCode); ErrorCode);
QuicExceptionHelpers.ThrowIfFailed(status, "Failed to shutdown connection."); QuicExceptionHelpers.ThrowIfFailed(status, "Failed to shutdown connection.");
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return _shutdownTcs.GetTypelessValueTask(); return _shutdownTcs.GetTypelessValueTask();
} }
@ -377,7 +377,7 @@ namespace System.Net.Quic.Implementations.MsQuic
return; return;
} }
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
if (_ptr != IntPtr.Zero) if (_ptr != IntPtr.Zero)
{ {
@ -395,7 +395,7 @@ namespace System.Net.Quic.Implementations.MsQuic
_disposed = true; _disposed = true;
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
} }
internal override ValueTask CloseAsync(long errorCode, CancellationToken cancellationToken = default) internal override ValueTask CloseAsync(long errorCode, CancellationToken cancellationToken = default)

View File

@ -62,7 +62,7 @@ namespace System.Net.Quic.Implementations.MsQuic
internal override async ValueTask<QuicConnectionProvider> AcceptConnectionAsync(CancellationToken cancellationToken = default) internal override async ValueTask<QuicConnectionProvider> AcceptConnectionAsync(CancellationToken cancellationToken = default)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
@ -81,7 +81,7 @@ namespace System.Net.Quic.Implementations.MsQuic
_options.CertificateFilePath, _options.CertificateFilePath,
_options.PrivateKeyFilePath).ConfigureAwait(false); _options.PrivateKeyFilePath).ConfigureAwait(false);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return connection; return connection;
} }

View File

@ -124,7 +124,7 @@ namespace System.Net.Quic.Implementations.MsQuic
internal override async ValueTask WriteAsync(ReadOnlySequence<byte> buffers, bool endStream, CancellationToken cancellationToken = default) internal override async ValueTask WriteAsync(ReadOnlySequence<byte> buffers, bool endStream, CancellationToken cancellationToken = default)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
@ -134,7 +134,7 @@ namespace System.Net.Quic.Implementations.MsQuic
HandleWriteCompletedState(); HandleWriteCompletedState();
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
} }
internal override ValueTask WriteAsync(ReadOnlyMemory<ReadOnlyMemory<byte>> buffers, CancellationToken cancellationToken = default) internal override ValueTask WriteAsync(ReadOnlyMemory<ReadOnlyMemory<byte>> buffers, CancellationToken cancellationToken = default)
@ -144,7 +144,7 @@ namespace System.Net.Quic.Implementations.MsQuic
internal override async ValueTask WriteAsync(ReadOnlyMemory<ReadOnlyMemory<byte>> buffers, bool endStream, CancellationToken cancellationToken = default) internal override async ValueTask WriteAsync(ReadOnlyMemory<ReadOnlyMemory<byte>> buffers, bool endStream, CancellationToken cancellationToken = default)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
@ -154,12 +154,12 @@ namespace System.Net.Quic.Implementations.MsQuic
HandleWriteCompletedState(); HandleWriteCompletedState();
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
} }
internal override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, bool endStream, CancellationToken cancellationToken = default) internal override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, bool endStream, CancellationToken cancellationToken = default)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
@ -169,7 +169,7 @@ namespace System.Net.Quic.Implementations.MsQuic
HandleWriteCompletedState(); HandleWriteCompletedState();
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
} }
private async ValueTask<CancellationTokenRegistration> HandleWriteStartState(CancellationToken cancellationToken) private async ValueTask<CancellationTokenRegistration> HandleWriteStartState(CancellationToken cancellationToken)
@ -228,7 +228,7 @@ namespace System.Net.Quic.Implementations.MsQuic
internal override async ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default) internal override async ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
@ -241,7 +241,7 @@ namespace System.Net.Quic.Implementations.MsQuic
{ {
if (_readState == ReadState.ReadsCompleted) if (_readState == ReadState.ReadsCompleted)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return 0; return 0;
} }
else if (_readState == ReadState.Aborted) else if (_readState == ReadState.Aborted)
@ -310,7 +310,7 @@ namespace System.Net.Quic.Implementations.MsQuic
} }
} }
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return actual; return actual;
} }
@ -319,7 +319,7 @@ namespace System.Net.Quic.Implementations.MsQuic
// If so, we need to complete the read here as well. // If so, we need to complete the read here as well.
internal override void AbortRead(long errorCode) internal override void AbortRead(long errorCode)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
@ -330,12 +330,12 @@ namespace System.Net.Quic.Implementations.MsQuic
MsQuicApi.Api.StreamShutdownDelegate(_ptr, (uint)QUIC_STREAM_SHUTDOWN_FLAG.ABORT_RECV, errorCode); MsQuicApi.Api.StreamShutdownDelegate(_ptr, (uint)QUIC_STREAM_SHUTDOWN_FLAG.ABORT_RECV, errorCode);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
} }
internal override void AbortWrite(long errorCode) internal override void AbortWrite(long errorCode)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
@ -357,12 +357,12 @@ namespace System.Net.Quic.Implementations.MsQuic
MsQuicApi.Api.StreamShutdownDelegate(_ptr, (uint)QUIC_STREAM_SHUTDOWN_FLAG.ABORT_SEND, errorCode); MsQuicApi.Api.StreamShutdownDelegate(_ptr, (uint)QUIC_STREAM_SHUTDOWN_FLAG.ABORT_SEND, errorCode);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
} }
internal override ValueTask ShutdownWriteCompleted(CancellationToken cancellationToken = default) internal override ValueTask ShutdownWriteCompleted(CancellationToken cancellationToken = default)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
@ -385,7 +385,7 @@ namespace System.Net.Quic.Implementations.MsQuic
} }
}); });
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return _shutdownWriteResettableCompletionSource.GetTypelessValueTask(); return _shutdownWriteResettableCompletionSource.GetTypelessValueTask();
} }
@ -434,7 +434,7 @@ namespace System.Net.Quic.Implementations.MsQuic
return default; return default;
} }
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
CleanupSendState(); CleanupSendState();
@ -448,7 +448,7 @@ namespace System.Net.Quic.Implementations.MsQuic
_handle.Free(); _handle.Free();
_disposed = true; _disposed = true;
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return default; return default;
} }
@ -471,7 +471,7 @@ namespace System.Net.Quic.Implementations.MsQuic
return; return;
} }
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
CleanupSendState(); CleanupSendState();
@ -484,7 +484,7 @@ namespace System.Net.Quic.Implementations.MsQuic
_handle.Free(); _handle.Free();
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
_disposed = true; _disposed = true;
} }
@ -577,7 +577,7 @@ namespace System.Net.Quic.Implementations.MsQuic
private unsafe uint HandleEventRecv(ref MsQuicNativeMethods.StreamEvent evt) private unsafe uint HandleEventRecv(ref MsQuicNativeMethods.StreamEvent evt)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
StreamEventDataRecv receieveEvent = evt.Data.Recv; StreamEventDataRecv receieveEvent = evt.Data.Recv;
for (int i = 0; i < receieveEvent.BufferCount; i++) for (int i = 0; i < receieveEvent.BufferCount; i++)
@ -600,14 +600,14 @@ namespace System.Net.Quic.Implementations.MsQuic
_receiveResettableCompletionSource.Complete((uint)receieveEvent.TotalBufferLength); _receiveResettableCompletionSource.Complete((uint)receieveEvent.TotalBufferLength);
} }
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Pending; return MsQuicStatusCodes.Pending;
} }
private uint HandleEventPeerRecvAborted(ref StreamEvent evt) private uint HandleEventPeerRecvAborted(ref StreamEvent evt)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldComplete = false; bool shouldComplete = false;
lock (_sync) lock (_sync)
@ -625,14 +625,14 @@ namespace System.Net.Quic.Implementations.MsQuic
_sendResettableCompletionSource.CompleteException(new QuicStreamAbortedException(_sendErrorCode)); _sendResettableCompletionSource.CompleteException(new QuicStreamAbortedException(_sendErrorCode));
} }
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleStartComplete() private uint HandleStartComplete()
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldComplete = false; bool shouldComplete = false;
lock (_sync) lock (_sync)
@ -649,14 +649,14 @@ namespace System.Net.Quic.Implementations.MsQuic
_sendResettableCompletionSource.Complete(MsQuicStatusCodes.Success); _sendResettableCompletionSource.Complete(MsQuicStatusCodes.Success);
} }
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleEventSendShutdownComplete(ref MsQuicNativeMethods.StreamEvent evt) private uint HandleEventSendShutdownComplete(ref MsQuicNativeMethods.StreamEvent evt)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldComplete = false; bool shouldComplete = false;
lock (_sync) lock (_sync)
{ {
@ -672,14 +672,14 @@ namespace System.Net.Quic.Implementations.MsQuic
_shutdownWriteResettableCompletionSource.Complete(MsQuicStatusCodes.Success); _shutdownWriteResettableCompletionSource.Complete(MsQuicStatusCodes.Success);
} }
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleEventShutdownComplete() private uint HandleEventShutdownComplete()
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldReadComplete = false; bool shouldReadComplete = false;
bool shouldShutdownWriteComplete = false; bool shouldShutdownWriteComplete = false;
@ -687,7 +687,7 @@ namespace System.Net.Quic.Implementations.MsQuic
lock (_sync) lock (_sync)
{ {
// This event won't occur within the middle of a receive. // This event won't occur within the middle of a receive.
if (NetEventSource.IsEnabled) NetEventSource.Info("Completing resettable event source."); if (NetEventSource.Log.IsEnabled()) NetEventSource.Info("Completing resettable event source.");
if (_readState == ReadState.None) if (_readState == ReadState.None)
{ {
@ -713,14 +713,14 @@ namespace System.Net.Quic.Implementations.MsQuic
_shutdownWriteResettableCompletionSource.Complete(MsQuicStatusCodes.Success); _shutdownWriteResettableCompletionSource.Complete(MsQuicStatusCodes.Success);
} }
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleEventPeerSendAborted(ref StreamEvent evt) private uint HandleEventPeerSendAborted(ref StreamEvent evt)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldComplete = false; bool shouldComplete = false;
lock (_sync) lock (_sync)
@ -738,21 +738,21 @@ namespace System.Net.Quic.Implementations.MsQuic
_receiveResettableCompletionSource.CompleteException(new QuicStreamAbortedException(_readErrorCode)); _receiveResettableCompletionSource.CompleteException(new QuicStreamAbortedException(_readErrorCode));
} }
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleEventPeerSendShutdown() private uint HandleEventPeerSendShutdown()
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldComplete = false; bool shouldComplete = false;
lock (_sync) lock (_sync)
{ {
// This event won't occur within the middle of a receive. // This event won't occur within the middle of a receive.
if (NetEventSource.IsEnabled) NetEventSource.Info("Completing resettable event source."); if (NetEventSource.Log.IsEnabled()) NetEventSource.Info("Completing resettable event source.");
if (_readState == ReadState.None) if (_readState == ReadState.None)
{ {
@ -767,14 +767,14 @@ namespace System.Net.Quic.Implementations.MsQuic
_receiveResettableCompletionSource.Complete(0); _receiveResettableCompletionSource.Complete(0);
} }
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleEventSendComplete(ref StreamEvent evt) private uint HandleEventSendComplete(ref StreamEvent evt)
{ {
if (NetEventSource.IsEnabled) NetEventSource.Enter(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
CleanupSendState(); CleanupSendState();
@ -796,7 +796,7 @@ namespace System.Net.Quic.Implementations.MsQuic
_sendResettableCompletionSource.Complete(MsQuicStatusCodes.Success); _sendResettableCompletionSource.Complete(MsQuicStatusCodes.Success);
} }
if (NetEventSource.IsEnabled) NetEventSource.Exit(this); if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }