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

◆ ReadNativeAsync()

unsafe Task< int > System.IO.Strategies.Net5CompatFileStreamStrategy.ReadNativeAsync ( Memory< byte > destination,
int numBufferedBytesRead,
CancellationToken cancellationToken )
inlineprivate

Definition at line 1009 of file Net5CompatFileStreamStrategy.cs.

1010 {
1011 CompletionSource completionSource = CompletionSource.Create(this, _preallocatedOverlapped, numBufferedBytesRead, destination);
1012 NativeOverlapped* overlapped = completionSource.Overlapped;
1013 if (CanSeek)
1014 {
1015 long length = Length;
1017 if (_filePosition + destination.Length > length)
1018 {
1019 destination = ((_filePosition > length) ? default(Memory<byte>) : destination.Slice(0, (int)(length - _filePosition)));
1020 }
1021 overlapped->OffsetLow = (int)_filePosition;
1022 overlapped->OffsetHigh = (int)(_filePosition >> 32);
1023 SeekCore(_fileHandle, destination.Length, SeekOrigin.Current);
1024 }
1025 int errorCode;
1026 int num = ReadFileNative(_fileHandle, destination.Span, overlapped, out errorCode);
1027 if (num == -1)
1028 {
1029 switch (errorCode)
1030 {
1031 case 109:
1032 overlapped->InternalLow = IntPtr.Zero;
1033 completionSource.SetCompletedSynchronously(0);
1034 break;
1035 default:
1037 {
1038 SeekCore(_fileHandle, 0L, SeekOrigin.Current);
1039 }
1040 completionSource.ReleaseNativeResource();
1041 if (errorCode == 38)
1042 {
1043 ThrowHelper.ThrowEndOfFileException();
1044 break;
1045 }
1046 throw Win32Marshal.GetExceptionForWin32Error(errorCode, _fileHandle.Path);
1047 case 997:
1048 if (cancellationToken.CanBeCanceled)
1049 {
1050 completionSource.RegisterForCancellation(cancellationToken);
1051 }
1052 break;
1053 }
1054 }
1055 return completionSource.Task;
1056 }
unsafe int ReadFileNative(SafeFileHandle handle, Span< byte > bytes, NativeOverlapped *overlapped, out int errorCode)
long SeekCore(SafeFileHandle fileHandle, long offset, SeekOrigin origin, bool closeInvalidHandle=false)

References System.IO.Strategies.Net5CompatFileStreamStrategy._fileHandle, System.IO.Strategies.Net5CompatFileStreamStrategy._filePosition, System.IO.Strategies.Net5CompatFileStreamStrategy._preallocatedOverlapped, System.cancellationToken, System.IO.Strategies.Net5CompatFileStreamStrategy.CanSeek, System.IO.Strategies.Net5CompatFileStreamStrategy.CompletionSource.Create(), System.destination, System.IO.Win32Marshal.GetExceptionForWin32Error(), System.Threading.NativeOverlapped.InternalLow, System.Runtime.InteropServices.SafeHandle.IsClosed, System.L, System.length, System.IO.Strategies.Net5CompatFileStreamStrategy.Length, System.Threading.NativeOverlapped.OffsetHigh, System.Threading.NativeOverlapped.OffsetLow, System.IO.Strategies.Net5CompatFileStreamStrategy.CompletionSource.Overlapped, Microsoft.Win32.SafeHandles.SafeFileHandle.Path, System.IO.Strategies.Net5CompatFileStreamStrategy.ReadFileNative(), System.IO.Strategies.Net5CompatFileStreamStrategy.CompletionSource.RegisterForCancellation(), System.IO.Strategies.Net5CompatFileStreamStrategy.CompletionSource.ReleaseNativeResource(), System.IO.Strategies.Net5CompatFileStreamStrategy.SeekCore(), System.IO.Strategies.Net5CompatFileStreamStrategy.CompletionSource.SetCompletedSynchronously(), System.Threading.Tasks.TaskCompletionSource< TResult >.Task, System.ThrowHelper.ThrowEndOfFileException(), System.IO.Strategies.Net5CompatFileStreamStrategy.VerifyOSHandlePosition(), and System.IntPtr.Zero.

Referenced by System.IO.Strategies.Net5CompatFileStreamStrategy.FillReadBufferForReadByte(), and System.IO.Strategies.Net5CompatFileStreamStrategy.ReadAsyncInternal().