diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicHelpers.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicHelpers.cs index 210cc20776875..04beebc6a2fc1 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicHelpers.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicHelpers.cs @@ -56,29 +56,37 @@ internal static unsafe QuicAddr ToQuicAddr(this IPEndPoint iPEndPoint) } internal static unsafe T GetMsQuicParameter(MsQuicSafeHandle handle, uint parameter) - where T: unmanaged + where T : unmanaged { T value; uint length = (uint)sizeof(T); - ThrowHelper.ThrowIfMsQuicError(MsQuicApi.Api.ApiTable->GetParam( + int status = MsQuicApi.Api.ApiTable->GetParam( handle.QuicHandle, parameter, &length, - (byte*)&value), - $"GetParam({handle}, {parameter}) failed"); + (byte*)&value); + + if (StatusFailed(status)) + { + throw ThrowHelper.GetExceptionForMsQuicStatus(status, $"GetParam({handle}, {parameter}) failed"); + } return value; } internal static unsafe void SetMsQuicParameter(MsQuicSafeHandle handle, uint parameter, T value) - where T: unmanaged + where T : unmanaged { - ThrowHelper.ThrowIfMsQuicError(MsQuicApi.Api.ApiTable->SetParam( + int status = MsQuicApi.Api.ApiTable->SetParam( handle.QuicHandle, parameter, (uint)sizeof(T), - (byte*)&value), - $"SetParam({handle}, {parameter}) failed"); + (byte*)&value); + + if (StatusFailed(status)) + { + throw ThrowHelper.GetExceptionForMsQuicStatus(status, $"SetParam({handle}, {parameter}) failed"); + } } } diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicSafeHandle.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicSafeHandle.cs index f566b64d4e728..6e247ef993737 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicSafeHandle.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicSafeHandle.cs @@ -20,7 +20,8 @@ internal unsafe class MsQuicSafeHandle : SafeHandle }; private readonly delegate* unmanaged[Cdecl] _releaseAction; - private readonly string _traceId; + private string? _traceId; + private SafeHandleType _type; public override bool IsInvalid => handle == IntPtr.Zero; @@ -30,7 +31,7 @@ public MsQuicSafeHandle(QUIC_HANDLE* handle, delegate* unmanaged[Cdecl] _traceId; + public override string ToString() => _traceId ??= $"[{s_typeName[(int)_type]}][0x{DangerousGetHandle():X11}]"; } internal enum SafeHandleType