2022-04-17 22:46:05 +00:00
|
|
|
/***
|
|
|
|
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
|
|
|
|
|
2022-08-09 06:48:29 +00:00
|
|
|
namespace Aurora::IO::IPC
|
|
|
|
{
|
|
|
|
struct IPCPipeImpl;
|
|
|
|
}
|
|
|
|
|
2022-04-17 22:46:05 +00:00
|
|
|
namespace Aurora::IO::FS
|
|
|
|
{
|
|
|
|
struct LinuxAsyncFileTransaction;
|
2022-06-12 13:53:35 +00:00
|
|
|
struct LinuxAsyncFileTransactionLoopSource;
|
2022-04-17 22:46:05 +00:00
|
|
|
|
2022-08-04 12:53:59 +00:00
|
|
|
struct LinuxAsyncFileStream : IAsyncFileStream
|
2022-04-17 22:46:05 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
void Init(const AuSPtr<IIOHandle> &handle);
|
2022-04-17 22:46:05 +00:00
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
AuSPtr<IIOHandle> GetHandle();
|
2022-04-17 22:46:05 +00:00
|
|
|
|
|
|
|
private:
|
2023-08-11 15:51:42 +00:00
|
|
|
AuSPtr<IIOHandle> pHandle_;
|
2022-04-17 22:46:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct LinuxAsyncFileTransaction : IAsyncTransaction, AuEnableSharedFromThis<LinuxAsyncFileTransaction>, Aurora::IO::UNIX::ASubmittable
|
|
|
|
{
|
|
|
|
~LinuxAsyncFileTransaction();
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
bool Init(const AuSPtr<IIOHandle> &handle);
|
2022-04-17 22:46:05 +00:00
|
|
|
|
|
|
|
bool StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView) override;
|
|
|
|
bool StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView) override;
|
|
|
|
|
2023-08-08 23:14:36 +00:00
|
|
|
bool Complete() override;
|
|
|
|
|
2022-06-12 13:53:35 +00:00
|
|
|
bool Failed() override;
|
|
|
|
AuUInt GetOSErrorCode() override;
|
|
|
|
|
2023-08-08 23:14:36 +00:00
|
|
|
bool HasCompleted() override;
|
|
|
|
|
2022-04-17 22:46:05 +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 22:46:05 +00:00
|
|
|
|
2022-05-05 11:48:37 +00:00
|
|
|
void Reset() override;
|
|
|
|
|
2022-04-17 22:46:05 +00:00
|
|
|
void DispatchCb();
|
2023-08-11 15:51:42 +00:00
|
|
|
AuSPtr<IIOHandle> GetFileHandle();
|
2022-04-17 22:46:05 +00:00
|
|
|
|
2023-08-08 23:02:35 +00:00
|
|
|
void SetBaseOffset(AuUInt64 uBaseOffset) override;
|
|
|
|
|
2022-04-17 22:46:05 +00:00
|
|
|
virtual void LIOS_Process(AuUInt32 read, bool failure, int err, bool mark) override;
|
|
|
|
|
|
|
|
private:
|
2023-08-11 15:51:42 +00:00
|
|
|
AuSPtr<IIOHandle> pHandle_;
|
2023-08-08 23:02:35 +00:00
|
|
|
AuUInt64 lastAbstractOffset_ {};
|
|
|
|
AuUInt32 lastFinishedStat_ {};
|
|
|
|
AuUInt64 uBaseOffset {};
|
2022-04-17 22:46:05 +00:00
|
|
|
bool latch_ {};
|
|
|
|
bool bTxFinished_ {};
|
|
|
|
AuSPtr<IAsyncFinishedSubscriber> sub_;
|
|
|
|
AuSPtr<LinuxAsyncFileTransactionLoopSource> loopSource_;
|
2022-06-12 13:53:35 +00:00
|
|
|
int error_ {};
|
|
|
|
bool hasError_ {};
|
2022-04-17 22:46:05 +00:00
|
|
|
};
|
|
|
|
}
|