2021-09-14 13:13:58 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: Async.NT.hpp
|
|
|
|
Date: 2021-9-13
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2022-06-22 20:24:04 +00:00
|
|
|
namespace Aurora::IO::IPC
|
|
|
|
{
|
|
|
|
struct IPCPipeImpl;
|
|
|
|
}
|
|
|
|
|
2021-09-14 13:13:58 +00:00
|
|
|
namespace Aurora::IO::FS
|
|
|
|
{
|
2022-04-17 12:40:08 +00:00
|
|
|
struct FileHandle
|
|
|
|
{
|
|
|
|
~FileHandle();
|
2021-09-14 13:13:58 +00:00
|
|
|
|
2022-04-17 12:40:08 +00:00
|
|
|
bool Init(const AuString &path, EFileOpenMode openMode, bool directIO, EFileAdvisoryLockLevel lock);
|
2022-05-03 10:10:04 +00:00
|
|
|
void Init(HANDLE read, HANDLE write);
|
2022-04-17 12:40:08 +00:00
|
|
|
|
2022-05-03 10:10:04 +00:00
|
|
|
HANDLE handle {INVALID_HANDLE_VALUE}, writeHandle {INVALID_HANDLE_VALUE};
|
2022-04-17 12:40:08 +00:00
|
|
|
AuString path;
|
|
|
|
bool readOnly;
|
|
|
|
bool directIO;
|
2022-08-18 16:19:32 +00:00
|
|
|
bool bNoOwns { false };
|
|
|
|
bool bWriteLock { false };
|
|
|
|
bool bReadLock { false };
|
2022-04-17 12:40:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NtAsyncFileStream : IAsyncFileStream
|
|
|
|
{
|
|
|
|
AuSPtr<IAsyncTransaction> NewTransaction() override;
|
|
|
|
|
|
|
|
bool BlockingTruncate(AuUInt64 length) override;
|
|
|
|
bool BlockingRead(AuUInt64 offset, const Memory::MemoryViewStreamWrite ¶meters) override;
|
|
|
|
bool BlockingWrite(AuUInt64 offset, const Memory::MemoryViewStreamRead ¶meters) override;
|
|
|
|
|
|
|
|
void Init(const AuSPtr<FileHandle> &handle);
|
|
|
|
|
|
|
|
AuSPtr<FileHandle> GetHandle();
|
|
|
|
|
|
|
|
private:
|
|
|
|
AuSPtr<FileHandle> handle_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NtAsyncFileTransaction : IAsyncTransaction, AuEnableSharedFromThis<NtAsyncFileTransaction>
|
|
|
|
{
|
|
|
|
~NtAsyncFileTransaction();
|
|
|
|
|
|
|
|
bool Init(const AuSPtr<FileHandle> &handle);
|
2023-04-26 06:24:17 +00:00
|
|
|
void ResetAIO();
|
2022-04-17 12:40:08 +00:00
|
|
|
|
|
|
|
bool StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView) override;
|
|
|
|
bool StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView) override;
|
|
|
|
|
2022-06-24 19:33:55 +00:00
|
|
|
bool isIrredeemable_ {};
|
|
|
|
|
2022-06-11 23:01:27 +00:00
|
|
|
bool Complete() override;
|
|
|
|
|
2023-05-11 15:05:00 +00:00
|
|
|
bool CompleteEx(AuUInt completeRoutine, bool bForce = false);
|
2022-06-22 20:24:04 +00:00
|
|
|
|
2022-06-11 23:01:27 +00:00
|
|
|
bool Failed() override;
|
|
|
|
AuUInt GetOSErrorCode() override;
|
|
|
|
|
2022-04-17 12:40:08 +00:00
|
|
|
AuUInt32 GetLastPacketLength() override;
|
|
|
|
|
|
|
|
void SetCallback(const AuSPtr<IAsyncFinishedSubscriber> &sub) override;
|
|
|
|
|
|
|
|
bool Wait(AuUInt32 timeout) override;
|
2022-06-11 23:52:46 +00:00
|
|
|
AuSPtr<AuLoop::ILoopSource> NewLoopSource() override;
|
2022-04-17 12:40:08 +00:00
|
|
|
|
2022-05-05 10:24:44 +00:00
|
|
|
void Reset();
|
|
|
|
|
|
|
|
bool IDontWannaUsePorts();
|
|
|
|
|
2022-04-17 12:40:08 +00:00
|
|
|
void DispatchCb(AuUInt32 len);
|
|
|
|
HANDLE GetHandle();
|
|
|
|
AuSPtr<FileHandle> GetFileHandle();
|
|
|
|
|
2022-08-18 16:19:32 +00:00
|
|
|
OVERLAPPED overlap {};
|
|
|
|
HANDLE event = INVALID_HANDLE_VALUE;
|
|
|
|
AuSPtr<NtAsyncFileTransaction> pPin;
|
|
|
|
AuUInt32 dwLastAbstractStat {},
|
|
|
|
dwLastAbstractOffset {};
|
|
|
|
bool bLatch {};
|
|
|
|
AuUInt32 dwLastBytes {};
|
|
|
|
AuUInt32 dwOsErrorCode {};
|
|
|
|
bool bHasFailed {};
|
2022-06-11 23:01:27 +00:00
|
|
|
|
2022-08-18 16:19:32 +00:00
|
|
|
AuWPtr<Aurora::IO::IPC::IPCPipeImpl> pNtIpcPipeImpl;
|
|
|
|
AuSPtr<void> pMemoryHold;
|
2022-06-22 20:24:04 +00:00
|
|
|
|
2022-07-05 03:17:28 +00:00
|
|
|
private:
|
2022-08-18 16:19:32 +00:00
|
|
|
AuSPtr<FileHandle> pHandle_;
|
|
|
|
AuSPtr<IAsyncFinishedSubscriber> pSub_;
|
2022-04-17 12:40:08 +00:00
|
|
|
};
|
2021-09-14 13:13:58 +00:00
|
|
|
}
|