Enable netfx testing. (#588)
* Enable netfx testing. * Skip impacted tests and re-enable netfx testing. * Remove redundant comment. * Remove unnecessary project configuration. * Simplify test server copying.
This commit is contained in:
parent
c0440760ac
commit
aa75f6f37e
2 changed files with 1940 additions and 53 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using ModelContextProtocol;
|
||||
using System.Buffers;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace System.IO;
|
||||
|
||||
|
|
@ -33,4 +34,31 @@ internal static class StreamExtensions
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ValueTask<int> ReadAsync(this Stream stream, Memory<byte> buffer, CancellationToken cancellationToken)
|
||||
{
|
||||
Throw.IfNull(stream);
|
||||
if (MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> segment))
|
||||
{
|
||||
return new ValueTask<int>(stream.ReadAsync(segment.Array, segment.Offset, segment.Count, cancellationToken));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ReadAsyncCore(stream, buffer, cancellationToken);
|
||||
static async ValueTask<int> ReadAsyncCore(Stream stream, Memory<byte> buffer, CancellationToken cancellationToken)
|
||||
{
|
||||
byte[] array = ArrayPool<byte>.Shared.Rent(buffer.Length);
|
||||
try
|
||||
{
|
||||
int bytesRead = await stream.ReadAsync(array, 0, buffer.Length, cancellationToken).ConfigureAwait(false);
|
||||
array.AsSpan(0, bytesRead).CopyTo(buffer.Span);
|
||||
return bytesRead;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(array);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
namespace System.IO;
|
||||
|
||||
internal static class TextReaderExtensions
|
||||
{
|
||||
public static Task<string> ReadLineAsync(this TextReader reader, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return reader.ReadLineAsync();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue