Пример #1
0
        public unsafe void Execute(FileWriteResult target)
        {
            target.Pin(buffer.Data);

            Overlapped overlapped = new Overlapped
            {
                AsyncResult = target,
                OffsetLow   = (int)(target.Position & 0xffffffff),
                OffsetHigh  = (int)((target.Position >> 32) & 0xffffffff)
            };

            NativeOverlapped *native = overlapped.UnsafePack(null, null);
            IntPtr            array  = Marshal.UnsafeAddrOfPinnedArrayElement(buffer.Data, buffer.Offset);

            int  read;
            int  result = FileInterop.WriteFile(handle, array, buffer.Count, out read, native);
            uint error  = FileInterop.GetLastError();

            if (result == 0 && error != 997)
            {
                target.Fail(error);
            }

            if (result == 1)
            {
                target.Complete(native, read);
            }
        }
Пример #2
0
        public File OpenOrCreate(string path)
        {
            IntPtr handle = FileInterop.CreateFile(path, 0x80000000 | 0x40000000, 0x01 | 0x02, IntPtr.Zero, 0x04, 0x40000000 | 0x00000080, IntPtr.Zero);
            uint   error  = FileInterop.GetLastError();

            worker.Add(handle);

            return(new FileInstance(handle, worker));
        }
Пример #3
0
        public File Open(string path)
        {
            IntPtr handle = FileInterop.CreateFile(path, 0x80000000 | 0x40000000, 0x01 | 0x02, IntPtr.Zero, 0x03, 0x40000000 | 0x00000080, IntPtr.Zero);

            if (handle == new IntPtr(-1))
            {
                return(null);
            }

            worker.Add(handle);

            return(new FileInstance(handle, worker));
        }
Пример #4
0
        public unsafe void Complete(NativeOverlapped *overlapped, int affected)
        {
            uint ignore;
            uint result = FileInterop.GetOverlappedResult(Handle, overlapped, out ignore, false);

            Affected    = affected;
            IsCompleted = true;

            if (result != 0 || affected > 0)
            {
                Release();
                Complete();
            }
            else
            {
                Fail();
            }
        }
Пример #5
0
 public void Fail()
 {
     Fail(FileInterop.GetLastError());
 }
Пример #6
0
 public void Dispose()
 {
     FileInterop.CloseHandle(handle);
 }
Пример #7
0
 public bool Flush()
 {
     return(FileInterop.FlushFileBuffers(handle));
 }
Пример #8
0
 public bool SetLength(long length)
 {
     return
         (FileInterop.SetFilePointerEx(handle, length, IntPtr.Zero, 0x00) &&
          FileInterop.SetEndOfFile(handle));
 }