Skip to content

Commit

Permalink
Avoid unnecessary string allocations in Get/SetMsQuicParameter (dotne…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Jul 18, 2023
1 parent d1ef9b6 commit 4f933e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ internal static unsafe T GetMsQuicParameter<T>(MsQuicSafeHandle handle, uint par
&length,
(byte*)&value);

ThrowHelper.ThrowIfMsQuicError(status, $"GetParam({handle}, {parameter}) failed");
if (StatusFailed(status))
{
ThrowHelper.ThrowMsQuicException(status, $"GetParam({handle}, {parameter}) failed");
}

return value;
}

Expand All @@ -80,6 +84,9 @@ internal static unsafe void SetMsQuicParameter<T>(MsQuicSafeHandle handle, uint
(uint)sizeof(T),
(byte*)&value);

ThrowHelper.ThrowIfMsQuicError(status, $"SetParam({handle}, {parameter}) failed");
if (StatusFailed(status))
{
ThrowHelper.ThrowMsQuicException(status, $"SetParam({handle}, {parameter}) failed");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ internal static void ThrowIfMsQuicError(int status, string? message = null)
{
if (StatusFailed(status))
{
throw GetExceptionForMsQuicStatus(status, message: message);
ThrowMsQuicException(status, message);
}
}

internal static void ThrowMsQuicException(int status, string? message = null)
{
throw GetExceptionForMsQuicStatus(status, message: message);
}

internal static string GetErrorMessageForStatus(int status, string? message)
{
return (message ?? "Status code") + ": " + GetErrorMessageForStatus(status);
Expand Down

0 comments on commit 4f933e1

Please sign in to comment.