AuroraRuntime/Source/IO/FS/Async.NT.hpp
Reece 1fa433540b [*] Experimental lower-latency IO pipes
[*] revert win32 net tx hardening - do not use the Reset function to null pSocket
[*] fix a bytebuffer circular buffer path
[*] update how TLS protocol stacks can snap the stack
2023-05-11 16:05:00 +01:00

100 lines
2.8 KiB
C++

/***
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
namespace Aurora::IO::IPC
{
struct IPCPipeImpl;
}
namespace Aurora::IO::FS
{
struct FileHandle
{
~FileHandle();
bool Init(const AuString &path, EFileOpenMode openMode, bool directIO, EFileAdvisoryLockLevel lock);
void Init(HANDLE read, HANDLE write);
HANDLE handle {INVALID_HANDLE_VALUE}, writeHandle {INVALID_HANDLE_VALUE};
AuString path;
bool readOnly;
bool directIO;
bool bNoOwns { false };
bool bWriteLock { false };
bool bReadLock { false };
};
struct NtAsyncFileStream : IAsyncFileStream
{
AuSPtr<IAsyncTransaction> NewTransaction() override;
bool BlockingTruncate(AuUInt64 length) override;
bool BlockingRead(AuUInt64 offset, const Memory::MemoryViewStreamWrite &parameters) override;
bool BlockingWrite(AuUInt64 offset, const Memory::MemoryViewStreamRead &parameters) 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);
void ResetAIO();
bool StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView) override;
bool StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView) override;
bool isIrredeemable_ {};
bool Complete() override;
bool CompleteEx(AuUInt completeRoutine, bool bForce = false);
bool Failed() override;
AuUInt GetOSErrorCode() override;
AuUInt32 GetLastPacketLength() override;
void SetCallback(const AuSPtr<IAsyncFinishedSubscriber> &sub) override;
bool Wait(AuUInt32 timeout) override;
AuSPtr<AuLoop::ILoopSource> NewLoopSource() override;
void Reset();
bool IDontWannaUsePorts();
void DispatchCb(AuUInt32 len);
HANDLE GetHandle();
AuSPtr<FileHandle> GetFileHandle();
OVERLAPPED overlap {};
HANDLE event = INVALID_HANDLE_VALUE;
AuSPtr<NtAsyncFileTransaction> pPin;
AuUInt32 dwLastAbstractStat {},
dwLastAbstractOffset {};
bool bLatch {};
AuUInt32 dwLastBytes {};
AuUInt32 dwOsErrorCode {};
bool bHasFailed {};
AuWPtr<Aurora::IO::IPC::IPCPipeImpl> pNtIpcPipeImpl;
AuSPtr<void> pMemoryHold;
private:
AuSPtr<FileHandle> pHandle_;
AuSPtr<IAsyncFinishedSubscriber> pSub_;
};
}