93 lines
2.7 KiB
C++
93 lines
2.7 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: Async.Linux.hpp
|
|
Date: 2022-4-12
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
namespace Aurora::IO::IPC
|
|
{
|
|
struct IPCPipeImpl;
|
|
}
|
|
|
|
namespace Aurora::IO::FS
|
|
{
|
|
struct LinuxAsyncFileTransaction;
|
|
struct LinuxAsyncFileTransactionLoopSource;
|
|
|
|
struct ProcessBlock
|
|
{
|
|
AuMutex externalLock;
|
|
Processes::IProcess *pProcess;
|
|
AuList<Aurora::IO::UNIX::ASubmittable *> submits;
|
|
bool bDead {};
|
|
};
|
|
|
|
struct LinuxAsyncFileStream : 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<IIOHandle> &handle);
|
|
|
|
void CheckProcess();
|
|
void MakeProcess(Processes::IProcess *pProcess);
|
|
|
|
AuSPtr<IIOHandle> GetHandle();
|
|
private:
|
|
AuSPtr<ProcessBlock> pProcessBlock_;
|
|
AuSPtr<IIOHandle> pHandle_;
|
|
};
|
|
|
|
|
|
struct LinuxAsyncFileTransaction : IAsyncTransaction, AuEnableSharedFromThis<LinuxAsyncFileTransaction>, Aurora::IO::UNIX::ASubmittable
|
|
{
|
|
LinuxAsyncFileTransaction(AuSPtr<ProcessBlock> pProcessBlock);
|
|
~LinuxAsyncFileTransaction();
|
|
|
|
bool Init(const AuSPtr<IIOHandle> &handle);
|
|
|
|
bool StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView) override;
|
|
bool StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView) override;
|
|
|
|
bool Complete() override;
|
|
|
|
bool HasFailed() override;
|
|
AuUInt GetOSErrorCode() override;
|
|
|
|
bool HasCompleted() override;
|
|
|
|
AuUInt32 GetLastPacketLength() override;
|
|
|
|
void SetCallback(const AuSPtr<IAsyncFinishedSubscriber> &sub) override;
|
|
|
|
bool Wait(AuUInt32 timeout) override;
|
|
AuSPtr<AuLoop::ILoopSource> NewLoopSource() override;
|
|
|
|
void Reset() override;
|
|
|
|
void DispatchCb();
|
|
AuSPtr<IIOHandle> GetFileHandle();
|
|
|
|
void SetBaseOffset(AuUInt64 uBaseOffset) override;
|
|
|
|
virtual void LIOS_Process(AuUInt32 read, bool failure, int err, bool mark) override;
|
|
|
|
AuSPtr<ProcessBlock> pProcessBlock_;
|
|
private:
|
|
AuSPtr<IIOHandle> pHandle_;
|
|
AuUInt64 lastAbstractOffset_ {};
|
|
AuUInt32 lastFinishedStat_ {};
|
|
AuUInt64 uBaseOffset {};
|
|
bool latch_ {};
|
|
bool bTxFinished_ {};
|
|
AuSPtr<IAsyncFinishedSubscriber> sub_;
|
|
AuSPtr<LinuxAsyncFileTransactionLoopSource> loopSource_;
|
|
int error_ {};
|
|
bool hasError_ {};
|
|
};
|
|
} |