Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ReadAsync() [3/3]

override ValueTask< int > System.IO.BufferedStream.ReadAsync ( Memory< byte > buffer,
CancellationToken cancellationToken = default(CancellationToken) )
inlinevirtual

Reimplemented from System.IO.Stream.

Definition at line 468 of file BufferedStream.cs.

469 {
470 if (cancellationToken.IsCancellationRequested)
471 {
473 }
476 int num = 0;
478 Task task = semaphoreSlim.WaitAsync(cancellationToken);
479 if (task.IsCompletedSuccessfully)
480 {
481 bool flag = true;
482 try
483 {
484 num = ReadFromBuffer(buffer.Span);
485 flag = num == buffer.Length;
486 if (flag)
487 {
488 return new ValueTask<int>(num);
489 }
490 }
491 finally
492 {
493 if (flag)
494 {
495 semaphoreSlim.Release();
496 }
497 }
498 }
500 }
int ReadFromBuffer(byte[] buffer, int offset, int count)
async ValueTask< int > ReadFromUnderlyingStreamAsync(Memory< byte > buffer, CancellationToken cancellationToken, int bytesAlreadySatisfied, Task semaphoreLockTask)
SemaphoreSlim EnsureAsyncActiveSemaphoreInitialized()
Definition Stream.cs:535
static ValueTask FromCanceled(CancellationToken cancellationToken)
Definition ValueTask.cs:180

References System.buffer, System.cancellationToken, System.IO.Stream.EnsureAsyncActiveSemaphoreInitialized(), System.IO.BufferedStream.EnsureCanRead(), System.IO.BufferedStream.EnsureNotClosed(), System.Threading.Tasks.ValueTask< TResult >.FromCanceled(), System.IO.BufferedStream.ReadFromBuffer(), System.IO.BufferedStream.ReadFromUnderlyingStreamAsync(), System.Threading.SemaphoreSlim.Release(), System.task, and System.Threading.SemaphoreSlim.WaitAsync().