Skip to content

Commit 16e80a7

Browse files
committed
Patch 5.18.2 for DotNext.IO
1 parent 4d875d1 commit 16e80a7

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Release Notes
1515
* 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
1616
* * Improved synchronous support for `RandomAccessCache` class
1717

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Release Date: 01-20-2025
5959
* 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
6060
* Improved synchronous support for `RandomAccessCache` class
6161

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

src/DotNext.IO/DotNext.IO.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Authors>.NET Foundation and Contributors</Authors>
1212
<Company />
1313
<Product>.NEXT Family of Libraries</Product>
14-
<VersionPrefix>5.18.1</VersionPrefix>
14+
<VersionPrefix>5.18.2</VersionPrefix>
1515
<VersionSuffix></VersionSuffix>
1616
<AssemblyName>DotNext.IO</AssemblyName>
1717
<PackageLicenseExpression>MIT</PackageLicenseExpression>

src/DotNext.IO/IO/PoolingBufferedStream.cs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -213,23 +213,16 @@ public void Write()
213213
/// <returns>The task representing asynchronous execution of the operation.</returns>
214214
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
215215
/// <exception cref="ObjectDisposedException">The stream is disposed.</exception>
216-
public ValueTask WriteAsync(CancellationToken token = default)
216+
public async ValueTask WriteAsync(CancellationToken token = default)
217217
{
218-
ValueTask task;
219-
if (stream is null)
220-
{
221-
task = new(DisposedTask);
222-
}
223-
else if (stream.CanWrite)
224-
{
225-
task = WriteCoreAsync(out _, token);
226-
}
227-
else
228-
{
229-
task = ValueTask.FromException(new NotSupportedException());
230-
}
218+
AssertState();
219+
ThrowIfDisposed();
220+
if (!stream.CanWrite)
221+
throw new NotSupportedException();
231222

232-
return task;
223+
await WriteCoreAsync(out var isWritten, token).ConfigureAwait(false);
224+
if (isWritten)
225+
Reset();
233226
}
234227

235228
private bool WriteCore()
@@ -681,13 +674,13 @@ public override IAsyncResult BeginRead(byte[] data, int offset, int count, Async
681674
public override Task FlushAsync(CancellationToken token)
682675
{
683676
Task task;
684-
if (writePosition > 0)
677+
if (stream is null)
685678
{
686-
task = WriteAndFlushAsync(token);
679+
task = DisposedTask;
687680
}
688-
else if (stream is null)
681+
else if (writePosition > 0)
689682
{
690-
task = DisposedTask;
683+
task = WriteAndFlushAsync(token);
691684
}
692685
else
693686
{
@@ -704,11 +697,10 @@ public override Task FlushAsync(CancellationToken token)
704697

705698
private async Task WriteAndFlushAsync(CancellationToken token)
706699
{
700+
Debug.Assert(stream is not null);
707701
Debug.Assert(writePosition > 0);
708702
Debug.Assert(buffer.Length > 0);
709703

710-
ThrowIfDisposed();
711-
712704
await stream.WriteAsync(WrittenMemory, token).ConfigureAwait(false);
713705
await stream.FlushAsync(token).ConfigureAwait(false);
714706

0 commit comments

Comments
 (0)