48 Action<object> callback =
Cancel;
62 if (num != 0
L && num != 34359738368
L && num != 17179869184
L)
85 ulong num = ((errorCode == 0 || errorCode == 109 || errorCode == 232) ? (0x100000000uL | numBytes) : (0x200000000uL | errorCode));
96 long num = (long)packedResult & -4294967296
L;
97 if (num == 8589934592
L)
99 int num2 = (int)(packedResult & 0xFFFFFFFFu);
121 if (lastPInvokeError != 1168)
130 if (preallocatedOverlapped ==
null || !
MemoryMarshal.TryGetArray(memory, out var segment) || !preallocatedOverlapped.
IsUserObject(segment.Array))
134 return new CompletionSource(strategy, preallocatedOverlapped, numBufferedBytesRead, segment.Array);
143 : base(strategy, null, numBufferedBytes, null)
151 base.ReleaseNativeResource();
351 int synchronousResult;
362 int synchronousResult;
367 if (
task ==
null ||
task.Result != synchronousResult)
420 return new ValueTask(
BeginWriteInternal(segment.Array, segment.Offset, segment.Count,
null,
null, serializeAsynchronously:
true, apm:
false));
427 Flush(flushToDisk:
false);
430 internal override void Flush(
bool flushToDisk)
447 if (filePosition != num)
616 handle.EnsureThreadPoolBindingInitialized();
627 protected override void Dispose(
bool disposing)
702 if (!calledFromFinalizer)
704 task.GetAwaiter().GetResult();
805 if (errorCode != 109)
821 if (origin < SeekOrigin.Begin || origin >
SeekOrigin.End)
867 int num3 = (int)(num2 - num);
927 else if (
source.Length != 0)
968 synchronousResult = num;
971 synchronousResult = 0;
987 synchronousResult = num2;
992 synchronousResult = 0;
1000 synchronousResult = num3;
1005 synchronousResult = 0;
1041 if (errorCode == 38)
1055 return completionSource.
Task;
1082 if (
source.Length != num)
1092 if (flag ||
task.IsFaulted ||
task.IsCanceled)
1132 if (errorCode == 38)
1146 return completionSource.
Task;
1156 int numBytesWritten = 0;
1168 return numBytesWritten;
static unsafe int WriteFile(IntPtr handle, byte *bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero)
static unsafe bool CancelIoEx(SafeHandle handle, NativeOverlapped *lpOverlapped)
ThreadPoolBoundHandle? ThreadPoolBinding
static SafeFileHandle Open(string fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, long preallocationSize)
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
void SetCurrentStackTrace()
static void SuppressFinalize(object obj)
static string GetFullPath(string path)
static unsafe long GetFileLength(SafeFileHandle handle)
static unsafe async Task AsyncModeCopyToAsync(SafeFileHandle handle, bool canSeek, long filePosition, Stream destination, int bufferSize, CancellationToken cancellationToken)
static int GetLastWin32ErrorAndDisposeHandleIfInvalid(SafeFileHandle handle)
static unsafe int ReadFileNative(SafeFileHandle handle, Span< byte > bytes, NativeOverlapped *overlapped, out int errorCode)
static void SetFileLength(SafeFileHandle handle, long length)
static void Lock(SafeFileHandle handle, bool canWrite, long position, long length)
static void Unlock(SafeFileHandle handle, long position, long length)
static void FlushToDisk(SafeFileHandle handle)
static long Seek(SafeFileHandle handle, long offset, SeekOrigin origin, bool closeInvalidHandle=false)
static bool IsIoRelatedException(Exception e)
static CompletionSource Create(Net5CompatFileStreamStrategy strategy, PreAllocatedOverlapped preallocatedOverlapped, int numBufferedBytesRead, ReadOnlyMemory< byte > memory)
readonly int _numBufferedBytes
unsafe void RegisterForCancellation(CancellationToken cancellationToken)
readonly Net5CompatFileStreamStrategy _strategy
unsafe CompletionSource(Net5CompatFileStreamStrategy strategy, PreAllocatedOverlapped preallocatedOverlapped, int numBufferedBytes, byte[] bytes)
CancellationTokenRegistration _cancellationRegistration
unsafe NativeOverlapped * Overlapped
static Action< object > s_cancelCallback
void SetCompletedSynchronously(int numBytes)
static unsafe readonly IOCompletionCallback s_ioCallback
static unsafe void Cancel(object state)
void CompleteCallback(ulong packedResult)
unsafe NativeOverlapped * _overlapped
virtual unsafe void ReleaseNativeResource()
static unsafe void IOCallback(uint errorCode, uint numBytes, NativeOverlapped *pOverlapped)
override void ReleaseNativeResource()
MemoryFileStreamCompletionSource(Net5CompatFileStreamStrategy strategy, int numBufferedBytes, ReadOnlyMemory< byte > memory)
override void Unlock(long position, long length)
void InitFromHandle(SafeFileHandle handle, FileAccess access, bool useAsyncIO)
override long Seek(long offset, SeekOrigin origin)
override void Flush(bool flushToDisk)
override void WriteByte(byte value)
void FlushWriteBufferForWriteByte()
readonly bool _useAsyncIO
override void Dispose(bool disposing)
override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
void Init(FileMode mode, string originalPath, FileOptions options)
override int Read(Span< byte > buffer)
override ValueTask WriteAsync(ReadOnlyMemory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
Task _activeBufferOperation
Net5CompatFileStreamStrategy(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, long preallocationSize)
~Net5CompatFileStreamStrategy()
readonly int _bufferLength
override void SetLength(long value)
override void Write(byte[] buffer, int offset, int count)
override void EndWrite(IAsyncResult asyncResult)
override void Write(ReadOnlySpan< byte > buffer)
bool HasActiveBufferOperation
PreAllocatedOverlapped _preallocatedOverlapped
void FlushInternalBuffer()
async Task AsyncModeCopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
int FillReadBufferForReadByte()
override int Read(byte[] buffer, int offset, int count)
Task FlushWriteAsync(CancellationToken cancellationToken)
void VerifyOSHandlePosition()
CompletionSource CompareExchangeCurrentOverlappedOwner(CompletionSource newSource, CompletionSource existingSource)
override Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Net5CompatFileStreamStrategy(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync)
override async ValueTask DisposeAsync()
readonly SafeFileHandle _fileHandle
Task< int > _lastSynchronouslyCompletedTask
override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
CompletionSource _currentOverlappedOwner
unsafe int WriteFileNative(SafeFileHandle handle, ReadOnlySpan< byte > buffer, NativeOverlapped *overlapped, out int errorCode)
override void Lock(long position, long length)
override ValueTask< int > ReadAsync(Memory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
unsafe Task WriteAsyncInternalCore(ReadOnlyMemory< byte > source, CancellationToken cancellationToken)
Task< int > ReadAsyncTask(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
unsafe Task< int > ReadNativeAsync(Memory< byte > destination, int numBufferedBytesRead, CancellationToken cancellationToken)
unsafe void WriteCore(ReadOnlySpan< byte > source)
override void DisposeInternal(bool disposing)
void WriteSpan(ReadOnlySpan< byte > source)
override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
void InitFromHandleImpl(SafeFileHandle handle, bool useAsyncIO)
override Task FlushAsync(CancellationToken cancellationToken)
unsafe int ReadNative(Span< byte > buffer)
override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
readonly FileAccess _access
unsafe int ReadFileNative(SafeFileHandle handle, Span< byte > bytes, NativeOverlapped *overlapped, out int errorCode)
void FlushWriteBuffer(bool calledFromFinalizer=false)
ValueTask WriteAsyncInternal(ReadOnlyMemory< byte > source, CancellationToken cancellationToken)
override int EndRead(IAsyncResult asyncResult)
long SeekCore(SafeFileHandle fileHandle, long offset, SeekOrigin origin, bool closeInvalidHandle=false)
void SetLengthCore(long value)
int ReadSpan(Span< byte > destination)
Task< int > ReadAsyncInternal(Memory< byte > destination, CancellationToken cancellationToken, out int synchronousResult)
Task< int > BeginReadInternal(byte[] buffer, int offset, int count, AsyncCallback callback, object state, bool serializeAsynchronously, bool apm)
Task BeginWriteInternal(byte[] buffer, int offset, int count, AsyncCallback callback, object state, bool serializeAsynchronously, bool apm)
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static byte Min(byte val1, byte val2)
static int GetLastPInvokeError()
static string IO_FileTooLongOrHandleNotSync
static string IO_SeekAppendOverwrite
static string IO_UnknownFileName
static string IO_SetLengthAppendTruncate
static string IO_FileStreamHandlePosition
static string Argument_InvalidSeekOrigin
static int CompareExchange(ref int location1, int value, int comparand)
static int Exchange(ref int location1, int value)
bool IsUserObject(byte[] buffer)
static PreAllocatedOverlapped UnsafeCreate(IOCompletionCallback callback, object? state, object? pinData)
bool TrySetException(Exception exception)
static IAsyncResult Begin(Task task, AsyncCallback callback, object state)
static void End(IAsyncResult asyncResult)
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
static Task FromException(Exception exception)
static Task FromCanceled(CancellationToken cancellationToken)
static Task CompletedTask
new TaskAwaiter< TResult > GetAwaiter()
static Task WhenAll(IEnumerable< Task > tasks)
unsafe void FreeNativeOverlapped(NativeOverlapped *overlapped)
unsafe NativeOverlapped * AllocateNativeOverlapped(IOCompletionCallback callback, object? state, object? pinData)
static unsafe? object GetNativeOverlappedState(NativeOverlapped *overlapped)
static void ThrowNotSupportedException_UnwritableStream()
static void ThrowArgumentException_HandleNotSync(string paramName)
static void ThrowNotSupportedException_UnseekableStream()
static void ThrowObjectDisposedException_FileClosed()
static void ThrowEndOfFileException()
static void ThrowNotSupportedException_UnreadableStream()
@ RunContinuationsAsynchronously
unsafe delegate void IOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped *pOVERLAP)
static readonly IntPtr Zero
unsafe MemoryHandle Pin()
void CopyTo(Span< T > destination)
void CopyTo(Span< T > destination)
bool IsCancellationRequested
static CancellationToken None