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

◆ ReadAsync() [2/3]

override Task< int > System.IO.BufferedStream.ReadAsync ( byte[] buffer,
int offset,
int count,
CancellationToken cancellationToken )
inlinevirtual

Reimplemented from System.IO.Stream.

Definition at line 433 of file BufferedStream.cs.

434 {
435 Stream.ValidateBufferArguments(buffer, offset, count);
436 if (cancellationToken.IsCancellationRequested)
437 {
439 }
442 int num = 0;
444 Task task = semaphoreSlim.WaitAsync(cancellationToken);
445 if (task.IsCompletedSuccessfully)
446 {
447 bool flag = true;
448 try
449 {
450 num = ReadFromBuffer(buffer, offset, count, out var error);
451 flag = num == count || error != null;
452 if (flag)
453 {
454 return (error == null) ? LastSyncCompletedReadTask(num) : Task.FromException<int>(error);
455 }
456 }
457 finally
458 {
459 if (flag)
460 {
461 semaphoreSlim.Release();
462 }
463 }
464 }
465 return ReadFromUnderlyingStreamAsync(new Memory<byte>(buffer, offset + num, count - num), cancellationToken, num, task).AsTask();
466 }
Task< int > LastSyncCompletedReadTask(int val)
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 Task FromCanceled(CancellationToken cancellationToken)
Definition Task.cs:3363

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

Referenced by System.IO.BufferedStream.BeginRead().