コード例 #1
0
ファイル: __ConsoleStream.cs プロジェクト: afrog33k/csnative
 protected override void Dispose(bool disposing)
 {
     // We're probably better off not closing the OS handle here.  First,
     // we allow a program to get multiple instances of __ConsoleStreams
     // around the same OS handle, so closing one handle would invalidate
     // them all.  Additionally, we want a second AppDomain to be able to 
     // write to stdout if a second AppDomain quits.
     if (_handle != null)
     {
         _handle = null;
     }
     _canRead = false;
     _canWrite = false;
     base.Dispose(disposing);
 }
コード例 #2
0
ファイル: __ConsoleStream.cs プロジェクト: afrog33k/csnative
 internal __ConsoleStream(SafeFileHandle handle, FileAccess access)
 {
     _handle = handle;
     _canRead = ((access & FileAccess.Read) == FileAccess.Read);
     _canWrite = ((access & FileAccess.Write) == FileAccess.Write);
 }
コード例 #3
0
ファイル: __ConsoleStream.cs プロジェクト: afrog33k/csnative
        private static int WriteFileNative(SafeFileHandle hFile, byte[] bytes, int offset, int count)
        {
            // You can't use the fixed statement on an array of length 0.
            if (bytes.Length == 0)
                return ERROR_SUCCESS;

            bool writeSuccess;

            int numBytesWritten = hFile.WriteFile(bytes, offset, count);
            writeSuccess = (0 != numBytesWritten);

            if (writeSuccess)
                return ERROR_SUCCESS;

            int errorCode = -1;

            return errorCode;
        }
コード例 #4
0
ファイル: File.cs プロジェクト: afrog33k/csnative
        /// <summary>
        /// </summary>
        /// <param name="path">
        /// </param>
        /// <param name="access">
        /// </param>
        /// <param name="handle">
        /// </param>
        /// <returns>
        /// </returns>
        private static FileStream OpenFile(string path, FileAccess access, out SafeFileHandle handle)
        {
            FileStream fs = new FileStream(path, FileMode.Open, access, FileShare.ReadWrite, 1);
            handle = fs.SafeFileHandle;

            if (handle.IsInvalid)
            {
                __Error.WinIOError(0, path);
            }

            return fs;
        }
コード例 #5
0
ファイル: __ConsoleStream.cs プロジェクト: afrog33k/csnative
        private static int ReadFileNative(SafeFileHandle hFile, byte[] bytes, int offset, int count, out int bytesRead)
        {
            if (bytes.Length - offset < count)
                throw new IndexOutOfRangeException("IORaceCondition");

            // You can't use the fixed statement on an array of length 0.
            if (bytes.Length == 0)
            {
                bytesRead = 0;
                return ERROR_SUCCESS;
            }

            bool readSuccess;

            bytesRead = hFile.ReadFile(bytes, offset, count);
            readSuccess = (0 != bytesRead);

            if (readSuccess)
                return ERROR_SUCCESS;

            int errorCode = -1;
            return errorCode;
        }
コード例 #6
0
 private static ValueTask <long> ReadScatterAtOffsetAsync(SafeFileHandle handle, IReadOnlyList <Memory <byte> > buffers,
                                                          long fileOffset, CancellationToken cancellationToken)
 => ScheduleSyncReadScatterAtOffsetAsync(handle, buffers, fileOffset, cancellationToken);
コード例 #7
0
 private static ValueTask <int> ReadAtOffsetAsync(SafeFileHandle handle, Memory <byte> buffer, long fileOffset, CancellationToken cancellationToken)
 => ScheduleSyncReadAtOffsetAsync(handle, buffer, fileOffset, cancellationToken);
コード例 #8
0
 private static bool IsHandleInvalid(SafeFileHandle handle)
 {
     return(handle == null || handle.IsInvalid || handle.IsClosed);
 }
コード例 #9
0
 internal static bool GetDefaultIsAsync(SafeFileHandle handle, bool defaultIsAsync) => handle.IsAsync ?? defaultIsAsync;
コード例 #10
0
 // in the future we are most probably going to introduce more strategies (io_uring etc)
 internal static FileStreamStrategy ChooseStrategy(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync)
 => new LegacyFileStreamStrategy(handle, access, bufferSize, isAsync);