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;
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-06-29 18:47:32 +00:00
|
|
|
bool CompleteEx(AuUInt completeRoutine);
|
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();
|
|
|
|
|
|
|
|
// Required for a very evil hack
|
|
|
|
OVERLAPPED overlap_ {};
|
|
|
|
HANDLE event_ = INVALID_HANDLE_VALUE;
|
|
|
|
AuSPtr<NtAsyncFileTransaction> pin_;
|
|
|
|
AuUInt32 lastAbstractStat_ {}, lastAbstractOffset_ {};
|
2022-05-05 10:24:44 +00:00
|
|
|
bool latch_ {};
|
2022-06-29 18:47:32 +00:00
|
|
|
AuUInt lastBytes {};
|
2022-06-11 23:01:27 +00:00
|
|
|
AuUInt32 osErrorCode {};
|
|
|
|
bool hasFailed {};
|
|
|
|
|
2022-06-22 20:24:04 +00:00
|
|
|
AuWPtr<Aurora::IO::IPC::IPCPipeImpl> ntIpcPipeImpl;
|
|
|
|
|
2022-04-17 12:40:08 +00:00
|
|
|
private:
|
|
|
|
AuSPtr<void> memoryHold_;
|
|
|
|
AuSPtr<FileHandle> handle_;
|
|
|
|
AuSPtr<IAsyncFinishedSubscriber> sub_;
|
|
|
|
};
|
2021-09-14 13:13:58 +00:00
|
|
|
}
|