Skip to content

Commit

Permalink
Patch 5.18.2 for DotNext.IO
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jan 24, 2025
1 parent 4d875d1 commit 16e80a7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Release Notes
* Synchronous `TryAcquire` implemented by `AsyncExclusiveLock` and `AsyncReaderWriterLock` are now implemented in portable way. Previously, WASM target was not supported. Additionally, the method supports lock stealing
* * Improved synchronous support for `RandomAccessCache` class

<a href="https://www.nuget.org/packages/dotnext.io/5.18.1">DotNext.IO 5.18.1</a>
<a href="https://www.nuget.org/packages/dotnext.io/5.18.2">DotNext.IO 5.18.2</a>
* Fixed issue of `PoolingBufferedStream` class when the stream has buffered bytes in the write buffer and `Position` is set to backward
* Fixed [256](https://github.com/dotnet/dotNext/issues/256)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Release Date: 01-20-2025
* Synchronous `TryAcquire` implemented by `AsyncExclusiveLock` and `AsyncReaderWriterLock` are now implemented in portable way. Previously, WASM target was not supported. Additionally, the method supports lock stealing
* Improved synchronous support for `RandomAccessCache` class

<a href="https://www.nuget.org/packages/dotnext.io/5.18.1">DotNext.IO 5.18.1</a>
<a href="https://www.nuget.org/packages/dotnext.io/5.18.2">DotNext.IO 5.18.2</a>
* Fixed issue of `PoolingBufferedStream` class when the stream has buffered bytes in the write buffer and `Position` is set to backward
* Fixed [256](https://github.com/dotnet/dotNext/issues/256)

Expand Down
2 changes: 1 addition & 1 deletion src/DotNext.IO/DotNext.IO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Authors>.NET Foundation and Contributors</Authors>
<Company />
<Product>.NEXT Family of Libraries</Product>
<VersionPrefix>5.18.1</VersionPrefix>
<VersionPrefix>5.18.2</VersionPrefix>
<VersionSuffix></VersionSuffix>
<AssemblyName>DotNext.IO</AssemblyName>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
34 changes: 13 additions & 21 deletions src/DotNext.IO/IO/PoolingBufferedStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,16 @@ public void Write()
/// <returns>The task representing asynchronous execution of the operation.</returns>
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
/// <exception cref="ObjectDisposedException">The stream is disposed.</exception>
public ValueTask WriteAsync(CancellationToken token = default)
public async ValueTask WriteAsync(CancellationToken token = default)
{
ValueTask task;
if (stream is null)
{
task = new(DisposedTask);
}
else if (stream.CanWrite)
{
task = WriteCoreAsync(out _, token);
}
else
{
task = ValueTask.FromException(new NotSupportedException());
}
AssertState();
ThrowIfDisposed();
if (!stream.CanWrite)
throw new NotSupportedException();

return task;
await WriteCoreAsync(out var isWritten, token).ConfigureAwait(false);
if (isWritten)
Reset();
}

private bool WriteCore()
Expand Down Expand Up @@ -681,13 +674,13 @@ public override IAsyncResult BeginRead(byte[] data, int offset, int count, Async
public override Task FlushAsync(CancellationToken token)
{
Task task;
if (writePosition > 0)
if (stream is null)
{
task = WriteAndFlushAsync(token);
task = DisposedTask;
}
else if (stream is null)
else if (writePosition > 0)
{
task = DisposedTask;
task = WriteAndFlushAsync(token);
}
else
{
Expand All @@ -704,11 +697,10 @@ public override Task FlushAsync(CancellationToken token)

private async Task WriteAndFlushAsync(CancellationToken token)
{
Debug.Assert(stream is not null);
Debug.Assert(writePosition > 0);
Debug.Assert(buffer.Length > 0);

ThrowIfDisposed();

await stream.WriteAsync(WrittenMemory, token).ConfigureAwait(false);
await stream.FlushAsync(token).ConfigureAwait(false);

Expand Down

0 comments on commit 16e80a7

Please sign in to comment.