Sync shared code from runtime (#23853)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2020-07-11 00:45:53 +00:00 committed by GitHub
parent dbfdc5c87b
commit 241e45d2b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 130 deletions

View File

@ -29,14 +29,9 @@ 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.Log.IsEnabled()) NetEventSource.Enter(this, refArg1, valueTypeArg2); // entering an instance method with a value type arg
// if (NetEventSource.Log.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.Info(this, "literal string"); // arbitrary message with a literal string // NetEventSource.Info(this, "literal string"); // arbitrary message with a literal string
// NetEventSource.Enter(this, refArg1, regArg2); // entering an instance method with two reference type arguments
// NetEventSource.Enter(null); // entering a static method
// NetEventSource.Enter(null, refArg1); // entering a static method with one reference type argument
// Debug.Asserts inside the logging methods will help to flag some misuse if the DEBUG_NETEVENTSOURCE_MISUSE compilation constant is defined. // Debug.Asserts inside the logging methods will help to flag some misuse if the DEBUG_NETEVENTSOURCE_MISUSE compilation constant is defined.
// However, because it can be difficult by observation to understand all of the costs involved, guarding can be done everywhere. // However, because it can be difficult by observation to understand all of the costs involved, guarding can be done everywhere.
// - NetEventSource.Fail calls typically do not need to be prefixed with an IsEnabled check, even if they allocate, as FailMessage // - NetEventSource.Fail calls typically do not need to be prefixed with an IsEnabled check, even if they allocate, as FailMessage
@ -103,7 +98,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString); DebugValidateArg(formattableString);
if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); if (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 +110,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0); DebugValidateArg(arg0);
if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)})"); if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)})");
} }
/// <summary>Logs entrance to a method.</summary> /// <summary>Logs entrance to a method.</summary>
@ -129,7 +124,7 @@ namespace System.Net
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0); DebugValidateArg(arg0);
DebugValidateArg(arg1); DebugValidateArg(arg1);
if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)})"); if (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 +140,7 @@ namespace System.Net
DebugValidateArg(arg0); DebugValidateArg(arg0);
DebugValidateArg(arg1); DebugValidateArg(arg1);
DebugValidateArg(arg2); DebugValidateArg(arg2);
if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)}, {Format(arg2)})"); if (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 +158,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString); DebugValidateArg(formattableString);
if (Log.IsEnabled()) Log.Exit(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); if (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 +170,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0); DebugValidateArg(arg0);
if (Log.IsEnabled()) Log.Exit(IdOf(thisOrContextObject), memberName, Format(arg0).ToString()); if (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 +184,7 @@ namespace System.Net
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0); DebugValidateArg(arg0);
DebugValidateArg(arg1); DebugValidateArg(arg1);
if (Log.IsEnabled()) Log.Exit(IdOf(thisOrContextObject), memberName, $"{Format(arg0)}, {Format(arg1)}"); if (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 +202,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString); DebugValidateArg(formattableString);
if (Log.IsEnabled()) Log.Info(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); if (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 +214,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(message); DebugValidateArg(message);
if (Log.IsEnabled()) Log.Info(IdOf(thisOrContextObject), memberName, Format(message).ToString()); if (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 +232,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString); DebugValidateArg(formattableString);
if (Log.IsEnabled()) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString)); if (IsEnabled) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString));
} }
/// <summary>Logs an error message.</summary> /// <summary>Logs an error message.</summary>
@ -249,7 +244,7 @@ namespace System.Net
{ {
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(message); DebugValidateArg(message);
if (Log.IsEnabled()) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(message).ToString()); if (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 +263,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 (Log.IsEnabled()) Log.CriticalFailure(IdOf(thisOrContextObject), memberName, Format(formattableString)); if (IsEnabled) Log.CriticalFailure(IdOf(thisOrContextObject), memberName, Format(formattableString));
Debug.Fail(Format(formattableString), $"{IdOf(thisOrContextObject)}.{memberName}"); Debug.Fail(Format(formattableString), $"{IdOf(thisOrContextObject)}.{memberName}");
} }
@ -282,7 +277,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 (Log.IsEnabled()) Log.CriticalFailure(IdOf(thisOrContextObject), memberName, Format(message).ToString()); if (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 +306,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 (Log.IsEnabled()) if (IsEnabled)
{ {
if (offset < 0 || offset > buffer.Length - count) if (offset < 0 || offset > buffer.Length - count)
{ {
@ -343,7 +338,7 @@ namespace System.Net
Debug.Assert(bufferPtr != IntPtr.Zero); Debug.Assert(bufferPtr != IntPtr.Zero);
Debug.Assert(count >= 0); Debug.Assert(count >= 0);
if (Log.IsEnabled()) if (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 +364,7 @@ namespace System.Net
{ {
DebugValidateArg(first); DebugValidateArg(first);
DebugValidateArg(second); DebugValidateArg(second);
if (Log.IsEnabled()) Log.Associate(IdOf(first), memberName, IdOf(first), IdOf(second)); if (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 +378,7 @@ namespace System.Net
DebugValidateArg(thisOrContextObject); DebugValidateArg(thisOrContextObject);
DebugValidateArg(first); DebugValidateArg(first);
DebugValidateArg(second); DebugValidateArg(second);
if (Log.IsEnabled()) Log.Associate(IdOf(thisOrContextObject), memberName, IdOf(first), IdOf(second)); if (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 +391,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 (!Log.IsEnabled()) if (!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,9 +401,12 @@ 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(Log.IsEnabled() || arg == null, $"Should not be formatting FormattableString \"{arg}\" if tracing isn't enabled"); Debug.Assert(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,21 +51,17 @@ 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.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.Log.IsEnabled()) NetEventSource.Exit(this);
} }
// constructor for outbound connections // constructor for outbound connections
public MsQuicConnection(QuicClientConnectionOptions options) public MsQuicConnection(QuicClientConnectionOptions options)
{ {
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.
_session = new MsQuicSession(); _session = new MsQuicSession();
@ -74,8 +70,6 @@ namespace System.Net.Quic.Implementations.MsQuic
SetCallbackHandler(); SetCallbackHandler();
SetIdleTimeout(options.IdleTimeout); SetIdleTimeout(options.IdleTimeout);
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
} }
internal override IPEndPoint LocalEndPoint internal override IPEndPoint LocalEndPoint
@ -168,8 +162,6 @@ namespace System.Net.Quic.Implementations.MsQuic
private uint HandleEventConnected(ConnectionEvent connectionEvent) private uint HandleEventConnected(ConnectionEvent connectionEvent)
{ {
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,14 +171,11 @@ 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.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleEventShutdownInitiatedByTransport(ConnectionEvent connectionEvent) private uint HandleEventShutdownInitiatedByTransport(ConnectionEvent connectionEvent)
{ {
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
if (!_connected) if (!_connected)
{ {
_connectTcs.CompleteException(new IOException("Connection has been shutdown.")); _connectTcs.CompleteException(new IOException("Connection has been shutdown."));
@ -194,7 +183,6 @@ namespace System.Net.Quic.Implementations.MsQuic
_acceptQueue.Writer.Complete(); _acceptQueue.Writer.Complete();
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
@ -208,23 +196,14 @@ namespace System.Net.Quic.Implementations.MsQuic
private uint HandleEventShutdownComplete(ConnectionEvent connectionEvent) private uint HandleEventShutdownComplete(ConnectionEvent connectionEvent)
{ {
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
_shutdownTcs.Complete(MsQuicStatusCodes.Success); _shutdownTcs.Complete(MsQuicStatusCodes.Success);
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.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.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
@ -235,8 +214,6 @@ 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.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
MsQuicStream stream; MsQuicStream stream;
@ -254,7 +231,6 @@ namespace System.Net.Quic.Implementations.MsQuic
}; };
} }
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return stream; return stream;
} }
@ -305,8 +281,6 @@ namespace System.Net.Quic.Implementations.MsQuic
private MsQuicStream StreamOpen( private MsQuicStream StreamOpen(
QUIC_STREAM_OPEN_FLAG flags) QUIC_STREAM_OPEN_FLAG flags)
{ {
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
IntPtr streamPtr = IntPtr.Zero; IntPtr streamPtr = IntPtr.Zero;
QuicExceptionHelpers.ThrowIfFailed( QuicExceptionHelpers.ThrowIfFailed(
MsQuicApi.Api.StreamOpenDelegate( MsQuicApi.Api.StreamOpenDelegate(
@ -317,10 +291,7 @@ namespace System.Net.Quic.Implementations.MsQuic
out streamPtr), out streamPtr),
"Failed to open stream to peer."); "Failed to open stream to peer.");
MsQuicStream stream = new MsQuicStream(this, flags, streamPtr, inbound: false); return new MsQuicStream(this, flags, streamPtr, inbound: false);
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return stream;
} }
private void SetCallbackHandler() private void SetCallbackHandler()
@ -337,15 +308,12 @@ namespace System.Net.Quic.Implementations.MsQuic
QUIC_CONNECTION_SHUTDOWN_FLAG Flags, QUIC_CONNECTION_SHUTDOWN_FLAG Flags,
long ErrorCode) long ErrorCode)
{ {
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
uint status = MsQuicApi.Api.ConnectionShutdownDelegate( uint status = MsQuicApi.Api.ConnectionShutdownDelegate(
_ptr, _ptr,
(uint)Flags, (uint)Flags,
ErrorCode); ErrorCode);
QuicExceptionHelpers.ThrowIfFailed(status, "Failed to shutdown connection."); QuicExceptionHelpers.ThrowIfFailed(status, "Failed to shutdown connection.");
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return _shutdownTcs.GetTypelessValueTask(); return _shutdownTcs.GetTypelessValueTask();
} }
@ -377,8 +345,6 @@ namespace System.Net.Quic.Implementations.MsQuic
return; return;
} }
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
if (_ptr != IntPtr.Zero) if (_ptr != IntPtr.Zero)
{ {
MsQuicApi.Api.ConnectionCloseDelegate?.Invoke(_ptr); MsQuicApi.Api.ConnectionCloseDelegate?.Invoke(_ptr);
@ -394,8 +360,6 @@ namespace System.Net.Quic.Implementations.MsQuic
} }
_disposed = true; _disposed = true;
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,8 +62,6 @@ 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.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
MsQuicConnection connection; MsQuicConnection connection;
@ -81,7 +79,6 @@ namespace System.Net.Quic.Implementations.MsQuic
_options.CertificateFilePath, _options.CertificateFilePath,
_options.PrivateKeyFilePath).ConfigureAwait(false); _options.PrivateKeyFilePath).ConfigureAwait(false);
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return connection; return connection;
} }

View File

@ -124,8 +124,6 @@ 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.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false); using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false);
@ -133,8 +131,6 @@ namespace System.Net.Quic.Implementations.MsQuic
await SendReadOnlySequenceAsync(buffers, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false); await SendReadOnlySequenceAsync(buffers, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false);
HandleWriteCompletedState(); HandleWriteCompletedState();
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,8 +140,6 @@ 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.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false); using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false);
@ -153,14 +147,10 @@ namespace System.Net.Quic.Implementations.MsQuic
await SendReadOnlyMemoryListAsync(buffers, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false); await SendReadOnlyMemoryListAsync(buffers, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false);
HandleWriteCompletedState(); HandleWriteCompletedState();
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.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false); using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false);
@ -168,8 +158,6 @@ namespace System.Net.Quic.Implementations.MsQuic
await SendReadOnlyMemoryAsync(buffer, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false); await SendReadOnlyMemoryAsync(buffer, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false);
HandleWriteCompletedState(); HandleWriteCompletedState();
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
} }
private async ValueTask<CancellationTokenRegistration> HandleWriteStartState(CancellationToken cancellationToken) private async ValueTask<CancellationTokenRegistration> HandleWriteStartState(CancellationToken cancellationToken)
@ -228,8 +216,6 @@ 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.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
if (!_canRead) if (!_canRead)
@ -241,7 +227,6 @@ namespace System.Net.Quic.Implementations.MsQuic
{ {
if (_readState == ReadState.ReadsCompleted) if (_readState == ReadState.ReadsCompleted)
{ {
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return 0; return 0;
} }
else if (_readState == ReadState.Aborted) else if (_readState == ReadState.Aborted)
@ -310,8 +295,6 @@ namespace System.Net.Quic.Implementations.MsQuic
} }
} }
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return actual; return actual;
} }
@ -319,8 +302,6 @@ 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.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
lock (_sync) lock (_sync)
@ -330,13 +311,10 @@ 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.Log.IsEnabled()) NetEventSource.Exit(this);
} }
internal override void AbortWrite(long errorCode) internal override void AbortWrite(long errorCode)
{ {
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
bool shouldComplete = false; bool shouldComplete = false;
@ -356,14 +334,10 @@ 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.Log.IsEnabled()) NetEventSource.Exit(this);
} }
internal override ValueTask ShutdownWriteCompleted(CancellationToken cancellationToken = default) internal override ValueTask ShutdownWriteCompleted(CancellationToken cancellationToken = default)
{ {
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
ThrowIfDisposed(); ThrowIfDisposed();
// TODO do anything to stop writes? // TODO do anything to stop writes?
@ -385,8 +359,6 @@ namespace System.Net.Quic.Implementations.MsQuic
} }
}); });
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return _shutdownWriteResettableCompletionSource.GetTypelessValueTask(); return _shutdownWriteResettableCompletionSource.GetTypelessValueTask();
} }
@ -434,8 +406,6 @@ namespace System.Net.Quic.Implementations.MsQuic
return default; return default;
} }
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
CleanupSendState(); CleanupSendState();
if (_ptr != IntPtr.Zero) if (_ptr != IntPtr.Zero)
@ -448,7 +418,6 @@ namespace System.Net.Quic.Implementations.MsQuic
_handle.Free(); _handle.Free();
_disposed = true; _disposed = true;
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return default; return default;
} }
@ -471,8 +440,6 @@ namespace System.Net.Quic.Implementations.MsQuic
return; return;
} }
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
CleanupSendState(); CleanupSendState();
if (_ptr != IntPtr.Zero) if (_ptr != IntPtr.Zero)
@ -484,8 +451,6 @@ namespace System.Net.Quic.Implementations.MsQuic
_handle.Free(); _handle.Free();
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
_disposed = true; _disposed = true;
} }
@ -577,8 +542,6 @@ namespace System.Net.Quic.Implementations.MsQuic
private unsafe uint HandleEventRecv(ref MsQuicNativeMethods.StreamEvent evt) private unsafe uint HandleEventRecv(ref MsQuicNativeMethods.StreamEvent evt)
{ {
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,15 +563,11 @@ namespace System.Net.Quic.Implementations.MsQuic
_receiveResettableCompletionSource.Complete((uint)receieveEvent.TotalBufferLength); _receiveResettableCompletionSource.Complete((uint)receieveEvent.TotalBufferLength);
} }
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.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldComplete = false; bool shouldComplete = false;
lock (_sync) lock (_sync)
{ {
@ -625,15 +584,11 @@ namespace System.Net.Quic.Implementations.MsQuic
_sendResettableCompletionSource.CompleteException(new QuicStreamAbortedException(_sendErrorCode)); _sendResettableCompletionSource.CompleteException(new QuicStreamAbortedException(_sendErrorCode));
} }
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleStartComplete() private uint HandleStartComplete()
{ {
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldComplete = false; bool shouldComplete = false;
lock (_sync) lock (_sync)
{ {
@ -649,14 +604,11 @@ namespace System.Net.Quic.Implementations.MsQuic
_sendResettableCompletionSource.Complete(MsQuicStatusCodes.Success); _sendResettableCompletionSource.Complete(MsQuicStatusCodes.Success);
} }
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.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldComplete = false; bool shouldComplete = false;
lock (_sync) lock (_sync)
{ {
@ -672,15 +624,11 @@ namespace System.Net.Quic.Implementations.MsQuic
_shutdownWriteResettableCompletionSource.Complete(MsQuicStatusCodes.Success); _shutdownWriteResettableCompletionSource.Complete(MsQuicStatusCodes.Success);
} }
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleEventShutdownComplete() private uint HandleEventShutdownComplete()
{ {
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldReadComplete = false; bool shouldReadComplete = false;
bool shouldShutdownWriteComplete = false; bool shouldShutdownWriteComplete = false;
@ -713,15 +661,11 @@ namespace System.Net.Quic.Implementations.MsQuic
_shutdownWriteResettableCompletionSource.Complete(MsQuicStatusCodes.Success); _shutdownWriteResettableCompletionSource.Complete(MsQuicStatusCodes.Success);
} }
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.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldComplete = false; bool shouldComplete = false;
lock (_sync) lock (_sync)
{ {
@ -738,15 +682,11 @@ namespace System.Net.Quic.Implementations.MsQuic
_receiveResettableCompletionSource.CompleteException(new QuicStreamAbortedException(_readErrorCode)); _receiveResettableCompletionSource.CompleteException(new QuicStreamAbortedException(_readErrorCode));
} }
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }
private uint HandleEventPeerSendShutdown() private uint HandleEventPeerSendShutdown()
{ {
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(this);
bool shouldComplete = false; bool shouldComplete = false;
lock (_sync) lock (_sync)
@ -767,15 +707,11 @@ namespace System.Net.Quic.Implementations.MsQuic
_receiveResettableCompletionSource.Complete(0); _receiveResettableCompletionSource.Complete(0);
} }
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.Log.IsEnabled()) NetEventSource.Enter(this);
CleanupSendState(); CleanupSendState();
// TODO throw if a write was canceled. // TODO throw if a write was canceled.
@ -796,8 +732,6 @@ namespace System.Net.Quic.Implementations.MsQuic
_sendResettableCompletionSource.Complete(MsQuicStatusCodes.Success); _sendResettableCompletionSource.Complete(MsQuicStatusCodes.Success);
} }
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(this);
return MsQuicStatusCodes.Success; return MsQuicStatusCodes.Success;
} }