Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/System.Private.CoreLib/shared/System/IO/StreamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ private int ReadBuffer(Span<char> userBuffer, out bool readToUserBuffer)

private async Task<string?> ReadLineAsyncInternal()
{
if (_charPos == _charLen && (await ReadBufferAsync().ConfigureAwait(false)) == 0)
if (_charPos == _charLen && (await ReadBufferAsync(CancellationToken.None).ConfigureAwait(false)) == 0)
{
return null;
}
Expand Down Expand Up @@ -876,7 +876,7 @@ private int ReadBuffer(Span<char> userBuffer, out bool readToUserBuffer)

_charPos = tmpCharPos = i + 1;

if (ch == '\r' && (tmpCharPos < tmpCharLen || (await ReadBufferAsync().ConfigureAwait(false)) > 0))
if (ch == '\r' && (tmpCharPos < tmpCharLen || (await ReadBufferAsync(CancellationToken.None).ConfigureAwait(false)) > 0))
{
tmpCharPos = _charPos;
if (_charBuffer[tmpCharPos] == '\n')
Expand All @@ -894,7 +894,7 @@ private int ReadBuffer(Span<char> userBuffer, out bool readToUserBuffer)
i = tmpCharLen - tmpCharPos;
sb ??= new StringBuilder(i + 80);
sb.Append(tmpCharBuffer, tmpCharPos, i);
} while (await ReadBufferAsync().ConfigureAwait(false) > 0);
} while (await ReadBufferAsync(CancellationToken.None).ConfigureAwait(false) > 0);

return sb.ToString();
}
Expand Down Expand Up @@ -928,7 +928,7 @@ private async Task<string> ReadToEndAsyncInternal()
int tmpCharPos = _charPos;
sb.Append(_charBuffer, tmpCharPos, _charLen - tmpCharPos);
_charPos = _charLen; // We consumed these characters
await ReadBufferAsync().ConfigureAwait(false);
await ReadBufferAsync(CancellationToken.None).ConfigureAwait(false);
} while (_charLen > 0);

return sb.ToString();
Expand Down Expand Up @@ -961,7 +961,7 @@ public override Task<int> ReadAsync(char[] buffer, int index, int count)
ThrowIfDisposed();
CheckAsyncTaskInProgress();

Task<int> task = ReadAsyncInternal(new Memory<char>(buffer, index, count), default).AsTask();
Task<int> task = ReadAsyncInternal(new Memory<char>(buffer, index, count), CancellationToken.None).AsTask();
_asyncReadTask = task;

return task;
Expand All @@ -988,7 +988,7 @@ public override ValueTask<int> ReadAsync(Memory<char> buffer, CancellationToken

internal override async ValueTask<int> ReadAsyncInternal(Memory<char> buffer, CancellationToken cancellationToken)
{
if (_charPos == _charLen && (await ReadBufferAsync().ConfigureAwait(false)) == 0)
if (_charPos == _charLen && (await ReadBufferAsync(cancellationToken).ConfigureAwait(false)) == 0)
{
return 0;
}
Expand Down Expand Up @@ -1218,7 +1218,7 @@ public override ValueTask<int> ReadBlockAsync(Memory<char> buffer, CancellationT
return new ValueTask<int>(t);
}

private async ValueTask<int> ReadBufferAsync()
private async ValueTask<int> ReadBufferAsync(CancellationToken cancellationToken)
{
_charLen = 0;
_charPos = 0;
Expand All @@ -1235,7 +1235,7 @@ private async ValueTask<int> ReadBufferAsync()
{
Debug.Assert(_bytePos <= _encoding.Preamble.Length, "possible bug in _compressPreamble. Are two threads using this StreamReader at the same time?");
int tmpBytePos = _bytePos;
int len = await tmpStream.ReadAsync(new Memory<byte>(tmpByteBuffer, tmpBytePos, tmpByteBuffer.Length - tmpBytePos)).ConfigureAwait(false);
int len = await tmpStream.ReadAsync(new Memory<byte>(tmpByteBuffer, tmpBytePos, tmpByteBuffer.Length - tmpBytePos), cancellationToken).ConfigureAwait(false);
Debug.Assert(len >= 0, "Stream.Read returned a negative number! This is a bug in your stream class.");

if (len == 0)
Expand All @@ -1257,7 +1257,7 @@ private async ValueTask<int> ReadBufferAsync()
else
{
Debug.Assert(_bytePos == 0, "_bytePos can be non zero only when we are trying to _checkPreamble. Are two threads using this StreamReader at the same time?");
_byteLen = await tmpStream.ReadAsync(new Memory<byte>(tmpByteBuffer)).ConfigureAwait(false);
_byteLen = await tmpStream.ReadAsync(new Memory<byte>(tmpByteBuffer), cancellationToken).ConfigureAwait(false);
Debug.Assert(_byteLen >= 0, "Stream.Read returned a negative number! Bug in stream class.");

if (_byteLen == 0) // We're at EOF
Expand Down