Fix Test-Connection due to .NET 8 changes (#20369) (#20531)

This commit is contained in:
Aditya Patwardhan
2023-10-19 18:56:02 -07:00
committed by GitHub
parent ce4cc67209
commit 240bd1f2cc
@@ -56,7 +56,7 @@ namespace Microsoft.PowerShell.Commands
#region Private Fields
private static byte[]? s_DefaultSendBuffer;
private static readonly byte[] s_DefaultSendBuffer = Array.Empty<byte>();
private readonly CancellationTokenSource _dnsLookupCancel = new();
@@ -484,7 +484,10 @@ namespace Microsoft.PowerShell.Commands
reply.Status == IPStatus.Success
? reply.RoundtripTime
: timer.ElapsedMilliseconds,
buffer.Length,
// If we use the empty buffer, then .NET actually uses a 32 byte buffer so we want to show
// as the result object the actual buffer size used instead of 0.
buffer.Length == 0 ? DefaultSendBufferSize : buffer.Length,
pingNum: i);
WriteObject(new TraceStatus(
currentHop,
@@ -707,7 +710,7 @@ namespace Microsoft.PowerShell.Commands
resolvedTargetName,
reply,
reply.RoundtripTime,
buffer.Length,
buffer.Length == 0 ? DefaultSendBufferSize : buffer.Length,
pingNum: (uint)i));
}
@@ -862,7 +865,7 @@ namespace Microsoft.PowerShell.Commands
// Creates and fills a send buffer. This follows the ping.exe and CoreFX model.
private static byte[] GetSendBuffer(int bufferSize)
{
if (bufferSize == DefaultSendBufferSize && s_DefaultSendBuffer != null)
if (bufferSize == DefaultSendBufferSize)
{
return s_DefaultSendBuffer;
}
@@ -874,11 +877,6 @@ namespace Microsoft.PowerShell.Commands
sendBuffer[i] = (byte)((int)'a' + i % 23);
}
if (bufferSize == DefaultSendBufferSize && s_DefaultSendBuffer == null)
{
s_DefaultSendBuffer = sendBuffer;
}
return sendBuffer;
}