2022-04-13 11:00:35 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: Async.Linux.cpp
|
|
|
|
Date: 2022-4-12
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
|
|
|
#include "FS.hpp"
|
|
|
|
#include "FileAdvisory.Unix.hpp"
|
2022-06-11 23:52:46 +00:00
|
|
|
#include <Source/IO/Loop/Loop.hpp>
|
|
|
|
#include <Source/IO/Loop/LSHandle.hpp>
|
|
|
|
#include <Source/IO/Loop/LSEvent.hpp>
|
2022-04-13 11:00:35 +00:00
|
|
|
#include <Source/IO/UNIX/IOSubmit.Linux.hpp>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2022-04-17 14:51:37 +00:00
|
|
|
#include "FileStream.Unix.hpp"
|
2022-04-17 22:46:05 +00:00
|
|
|
#include "Async.Linux.hpp"
|
2022-12-16 00:41:01 +00:00
|
|
|
#include <Source/IO/IPC/AuIPCPipe.Unix.hpp>
|
2023-08-11 15:51:42 +00:00
|
|
|
#include <Source/IO/AuIOHandle.hpp>
|
2022-04-13 11:00:35 +00:00
|
|
|
|
|
|
|
namespace Aurora::IO::FS
|
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
#define IPC_PIPE AuStaticCast<AFileHandle>(this->pHandle_)->pIPCPipe
|
|
|
|
|
2022-06-12 13:53:35 +00:00
|
|
|
struct LinuxAsyncFileTransactionLoopSource : Aurora::IO::Loop::LSEvent
|
|
|
|
{
|
|
|
|
LinuxAsyncFileTransactionLoopSource(AuSPtr<LinuxAsyncFileTransaction> that);
|
|
|
|
|
|
|
|
virtual bool IsSignaled() override;
|
|
|
|
virtual bool OnTrigger(AuUInt handle) override;
|
|
|
|
virtual AuLoop::ELoopSource GetType() override;
|
2022-08-09 06:48:29 +00:00
|
|
|
|
|
|
|
virtual const AuList<AuUInt> &GetHandles() override;
|
|
|
|
virtual bool Singular() override;
|
|
|
|
|
2022-06-12 13:53:35 +00:00
|
|
|
private:
|
2022-08-09 06:48:29 +00:00
|
|
|
|
|
|
|
bool bExMode {};
|
2022-06-12 13:53:35 +00:00
|
|
|
AuWPtr<LinuxAsyncFileTransaction> caller_;
|
2022-08-09 06:48:29 +00:00
|
|
|
AuList<AuUInt> handles_;
|
2022-06-12 13:53:35 +00:00
|
|
|
};
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
LinuxAsyncFileTransactionLoopSource::LinuxAsyncFileTransactionLoopSource(AuSPtr<LinuxAsyncFileTransaction> that) :
|
|
|
|
caller_(that),
|
|
|
|
Loop::LSEvent(false, false, true)
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
2022-08-09 06:48:29 +00:00
|
|
|
if (that)
|
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
if (auto pPipe = AuStaticCast<AFileHandle>(that->GetFileHandle())->pIPCPipe)
|
2022-08-09 06:48:29 +00:00
|
|
|
{
|
|
|
|
this->bExMode = true;
|
2023-08-11 15:51:42 +00:00
|
|
|
this->handles_ = {pPipe->GetPreemptFd(), Loop::LSEvent::GetHandle()};
|
2022-08-09 06:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const AuList<AuUInt> &LinuxAsyncFileTransactionLoopSource::GetHandles()
|
|
|
|
{
|
|
|
|
return this->handles_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LinuxAsyncFileTransactionLoopSource::Singular()
|
|
|
|
{
|
|
|
|
return !this->bExMode;
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LinuxAsyncFileTransactionLoopSource::OnTrigger(AuUInt handle)
|
|
|
|
{
|
2022-05-05 11:48:37 +00:00
|
|
|
auto lock = caller_.lock();
|
|
|
|
|
|
|
|
if (lock)
|
|
|
|
{
|
|
|
|
return lock->Complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LinuxAsyncFileTransactionLoopSource::IsSignaled()
|
|
|
|
{
|
2022-05-05 11:48:37 +00:00
|
|
|
if (LSEvent::IsSignaled())
|
|
|
|
{
|
|
|
|
auto lock = caller_.lock();
|
|
|
|
return lock->Complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Loop::ELoopSource LinuxAsyncFileTransactionLoopSource::GetType()
|
|
|
|
{
|
|
|
|
return Loop::ELoopSource::eSourceAIO;
|
|
|
|
}
|
|
|
|
|
2023-12-24 06:22:58 +00:00
|
|
|
LinuxAsyncFileTransaction::LinuxAsyncFileTransaction(AuSPtr<ProcessBlock> pProcessBlock) :
|
|
|
|
pProcessBlock_(pProcessBlock)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-13 11:00:35 +00:00
|
|
|
LinuxAsyncFileTransaction::~LinuxAsyncFileTransaction()
|
|
|
|
{
|
2023-12-24 06:22:58 +00:00
|
|
|
if (this->pProcessBlock_)
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(this->pProcessBlock_->externalLock);
|
|
|
|
AuTryRemove(this->pProcessBlock_->submits, this);
|
|
|
|
}
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
void LinuxAsyncFileStream::Init(const AuSPtr<IIOHandle> &handle)
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
this->pHandle_ = handle;
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
2023-12-24 06:22:58 +00:00
|
|
|
void LinuxAsyncFileStream::MakeProcess(Processes::IProcess *pProcess)
|
|
|
|
{
|
|
|
|
this->pProcessBlock_ = AuMakeSharedThrow<ProcessBlock>();
|
|
|
|
this->pProcessBlock_->pProcess = pProcess;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinuxAsyncFileStream::CheckProcess()
|
|
|
|
{
|
|
|
|
if (this->pProcessBlock_)
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(this->pProcessBlock_->externalLock);
|
|
|
|
if (this->pProcessBlock_->pProcess &&
|
|
|
|
this->pProcessBlock_->pProcess->HasExited())
|
|
|
|
{
|
|
|
|
this->pProcessBlock_->pProcess = nullptr;
|
|
|
|
this->pProcessBlock_->bDead = true;
|
|
|
|
for (auto &pSubmittable : this->pProcessBlock_->submits)
|
|
|
|
{
|
|
|
|
pSubmittable->LIOS_Cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-13 11:00:35 +00:00
|
|
|
AuSPtr<IAsyncTransaction> LinuxAsyncFileStream::NewTransaction()
|
|
|
|
{
|
2023-12-24 06:22:58 +00:00
|
|
|
auto shared = AuMakeShared<LinuxAsyncFileTransaction>(this->pProcessBlock_);
|
2022-04-13 11:00:35 +00:00
|
|
|
if (!shared)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
if (!shared->Init(this->pHandle_))
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-12-24 06:22:58 +00:00
|
|
|
if (this->pProcessBlock_)
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(this->pProcessBlock_->externalLock);
|
|
|
|
if (!AuTryInsert(this->pProcessBlock_->submits, shared.get()))
|
|
|
|
{
|
|
|
|
SysPushErrorMemory();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-13 11:00:35 +00:00
|
|
|
return shared;
|
|
|
|
}
|
|
|
|
|
2022-04-17 14:51:37 +00:00
|
|
|
bool LinuxAsyncFileStream::BlockingTruncate(AuUInt64 length)
|
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
auto iOptSafe = this->pHandle_->GetOSWriteHandleSafe();
|
|
|
|
if (!iOptSafe)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto fd = (int)iOptSafe.Value();
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
SysPushErrorUninitialized();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ::ftruncate(fd, length) != -1;
|
2022-04-17 14:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LinuxAsyncFileStream::BlockingRead(AuUInt64 offset, const Memory::MemoryViewStreamWrite ¶meters)
|
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
auto iOptSafe = this->pHandle_->GetOSReadHandleSafe();
|
|
|
|
if (!iOptSafe)
|
2022-08-28 23:39:12 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
auto fd = (int)iOptSafe.Value();
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
SysPushErrorUninitialized();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IPC_PIPE)
|
2022-08-09 06:48:29 +00:00
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
if (IPC_PIPE->LIOS_PopOne())
|
2022-08-09 06:48:29 +00:00
|
|
|
{
|
|
|
|
parameters.outVariable = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-24 06:22:58 +00:00
|
|
|
if (this->pProcessBlock_ &&
|
|
|
|
this->pProcessBlock_->bDead)
|
|
|
|
{
|
|
|
|
parameters.outVariable = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
if (!PosixSetOffset(fd, offset))
|
2022-04-17 14:51:37 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt32 read;
|
2023-08-11 15:51:42 +00:00
|
|
|
if (!PosixRead(fd, parameters.ptr, parameters.length, &read))
|
2022-04-17 14:51:37 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LinuxAsyncFileStream::BlockingWrite(AuUInt64 offset, const Memory::MemoryViewStreamRead ¶meters)
|
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
auto iOptSafe = this->pHandle_->GetOSWriteHandleSafe();
|
|
|
|
if (!iOptSafe)
|
2022-08-28 23:39:12 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
auto fd = (int)iOptSafe.Value();
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
SysPushErrorUninitialized();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PosixSetOffset(fd, offset))
|
2022-04-17 14:51:37 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-24 06:22:58 +00:00
|
|
|
if (this->pProcessBlock_ &&
|
|
|
|
this->pProcessBlock_->bDead)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-17 14:51:37 +00:00
|
|
|
AuUInt32 read;
|
2023-08-11 15:51:42 +00:00
|
|
|
if (!PosixWrite(fd, parameters.ptr, parameters.length, &read))
|
2022-04-17 14:51:37 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
bool LinuxAsyncFileTransaction::Init(const AuSPtr<IIOHandle> &handle)
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
2023-12-24 06:22:58 +00:00
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2023-08-11 15:51:42 +00:00
|
|
|
this->pHandle_ = handle;
|
2022-04-13 11:00:35 +00:00
|
|
|
this->loopSource_ = AuMakeShared<LinuxAsyncFileTransactionLoopSource>(AuSharedFromThis());
|
|
|
|
return bool(this->loopSource_);
|
|
|
|
}
|
|
|
|
|
2023-08-08 23:02:35 +00:00
|
|
|
void LinuxAsyncFileTransaction::SetBaseOffset(AuUInt64 uBaseOffset)
|
|
|
|
{
|
|
|
|
this->uBaseOffset = uBaseOffset;
|
|
|
|
}
|
|
|
|
|
2022-04-13 11:00:35 +00:00
|
|
|
bool LinuxAsyncFileTransaction::StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView)
|
|
|
|
{
|
|
|
|
if (HasState())
|
|
|
|
{
|
|
|
|
SysPushErrorIO("IO Operation can not be reused yet.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
auto iOptSafe = this->pHandle_->GetOSReadHandleSafe();
|
|
|
|
if (!iOptSafe)
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
auto fd = (int)iOptSafe.Value();
|
|
|
|
if (fd == -1)
|
2022-08-28 23:39:12 +00:00
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
SysPushErrorUninitialized();
|
2022-08-28 23:39:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-13 11:00:35 +00:00
|
|
|
this->latch_ = false;
|
2022-06-12 13:53:35 +00:00
|
|
|
this->hasError_ = false;
|
2022-05-04 19:34:46 +00:00
|
|
|
this->bTxFinished_ = false;
|
|
|
|
this->lastFinishedStat_ = 0;
|
|
|
|
|
|
|
|
if (!this->loopSource_)
|
|
|
|
{
|
|
|
|
SysPushErrorUninitialized();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->loopSource_->Reset();
|
2022-04-13 11:00:35 +00:00
|
|
|
|
|
|
|
this->lastAbstractOffset_ = offset;
|
|
|
|
|
|
|
|
LIOS_Init(AuSharedFromThis());
|
|
|
|
SetMemory(memoryView);
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
if (IPC_PIPE)
|
2022-08-09 06:48:29 +00:00
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
if (IPC_PIPE->LIOS_PopOne())
|
2022-08-09 06:48:29 +00:00
|
|
|
{
|
|
|
|
LIOS_SendProcess(0, false, errno);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2023-08-08 23:02:35 +00:00
|
|
|
|
2023-12-24 06:22:58 +00:00
|
|
|
if (this->pProcessBlock_ &&
|
|
|
|
this->pProcessBlock_->bDead)
|
|
|
|
{
|
|
|
|
LIOS_SendProcess(0, false, errno);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-08-08 23:02:35 +00:00
|
|
|
offset += this->uBaseOffset;
|
2022-08-09 06:48:29 +00:00
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
if (!UNIX::LinuxOverlappedSubmitRead(fd, offset, this, this->loopSource_.get(), bool(IPC_PIPE)))
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
|
|
|
LIOS_SendProcess(0, true, errno);
|
2022-08-09 06:48:29 +00:00
|
|
|
return true;
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-29 00:58:48 +00:00
|
|
|
if (gRuntimeConfig.linuxConfig.bFIODisableBatching)
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
|
|
|
UNIX::SendIOBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LinuxAsyncFileTransaction::StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView)
|
|
|
|
{
|
|
|
|
if (HasState())
|
|
|
|
{
|
|
|
|
SysPushErrorIO("IO Operation can not be reused yet.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
auto iOptSafe = this->pHandle_->GetOSWriteHandleSafe();
|
|
|
|
if (!iOptSafe)
|
2022-08-28 23:39:12 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
auto fd = (int)iOptSafe.Value();
|
2022-04-13 11:00:35 +00:00
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
SysPushErrorUninitialized();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->latch_ = false;
|
2022-05-04 19:34:46 +00:00
|
|
|
this->bTxFinished_ = false;
|
2022-06-12 13:53:35 +00:00
|
|
|
this->hasError_ = false;
|
2022-05-04 19:34:46 +00:00
|
|
|
this->lastFinishedStat_ = 0;
|
|
|
|
|
|
|
|
if (!this->loopSource_)
|
|
|
|
{
|
|
|
|
SysPushErrorUninitialized();
|
|
|
|
return false;
|
|
|
|
}
|
2022-04-13 11:00:35 +00:00
|
|
|
|
2022-05-04 19:34:46 +00:00
|
|
|
this->loopSource_->Reset();
|
|
|
|
|
2022-04-13 11:00:35 +00:00
|
|
|
this->lastAbstractOffset_ = offset;
|
|
|
|
|
|
|
|
LIOS_Init(AuSharedFromThis());
|
|
|
|
SetMemory(memoryView);
|
|
|
|
|
2023-12-24 06:22:58 +00:00
|
|
|
if (this->pProcessBlock_ &&
|
|
|
|
this->pProcessBlock_->bDead)
|
|
|
|
{
|
|
|
|
LIOS_SendProcess(0, false, errno);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-08-08 23:02:35 +00:00
|
|
|
offset += this->uBaseOffset;
|
|
|
|
|
2022-04-13 11:00:35 +00:00
|
|
|
if (!UNIX::LinuxOverlappedSubmitWrite(fd, offset, this, this->loopSource_.get()))
|
|
|
|
{
|
|
|
|
LIOS_SendProcess(0, true, errno);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-29 00:58:48 +00:00
|
|
|
if (gRuntimeConfig.linuxConfig.bFIODisableBatching)
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
|
|
|
UNIX::SendIOBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-05 11:48:37 +00:00
|
|
|
void LinuxAsyncFileTransaction::Reset()
|
|
|
|
{
|
2023-12-24 05:41:03 +00:00
|
|
|
(void)this->LIOS_Cancel();
|
|
|
|
|
2022-05-05 11:48:37 +00:00
|
|
|
if (this->loopSource_)
|
|
|
|
{
|
|
|
|
this->loopSource_->Reset();
|
|
|
|
}
|
|
|
|
}
|
2022-04-13 11:00:35 +00:00
|
|
|
|
|
|
|
void LinuxAsyncFileTransaction::LIOS_Process(AuUInt32 read, bool failure, int err, bool mark)
|
|
|
|
{
|
2022-05-04 19:34:46 +00:00
|
|
|
this->lastFinishedStat_ = failure ? 0 : read;
|
2022-06-12 13:53:35 +00:00
|
|
|
this->hasError_ = failure;
|
|
|
|
this->error_ = err;
|
2022-04-13 11:00:35 +00:00
|
|
|
this->bTxFinished_ = true;
|
|
|
|
if (mark)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->DispatchCb();
|
2022-08-09 06:48:29 +00:00
|
|
|
|
|
|
|
if (read)
|
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
if (IPC_PIPE)
|
2022-08-09 06:48:29 +00:00
|
|
|
{
|
|
|
|
// Return value intentionally ignored
|
|
|
|
// We just need to poke on read...
|
2023-08-11 15:51:42 +00:00
|
|
|
IPC_PIPE->LIOS_PopOne();
|
2022-08-09 06:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LinuxAsyncFileTransaction::DispatchCb()
|
|
|
|
{
|
|
|
|
if (AuExchange(this->latch_, true))
|
|
|
|
{
|
2022-08-09 06:48:29 +00:00
|
|
|
// TODO (Reece): urgent
|
|
|
|
//SysPushErrorGeneric();
|
2022-04-13 11:00:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->sub_)
|
|
|
|
{
|
|
|
|
this->sub_->OnAsyncFileOpFinished(this->lastAbstractOffset_, this->lastFinishedStat_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LinuxAsyncFileTransaction::Complete()
|
|
|
|
{
|
|
|
|
if (this->bTxFinished_)
|
|
|
|
{
|
|
|
|
if (!this->latch_)
|
|
|
|
{
|
2022-05-04 19:34:46 +00:00
|
|
|
LIOS_SendProcess(this->lastFinishedStat_, this->lastFinishedStat_ == 0, 0, false);
|
|
|
|
//DispatchCb();
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
2022-08-09 06:48:29 +00:00
|
|
|
|
2022-04-13 11:00:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-08 23:14:36 +00:00
|
|
|
bool LinuxAsyncFileTransaction::HasCompleted()
|
|
|
|
{
|
|
|
|
return this->bTxFinished_;
|
|
|
|
}
|
|
|
|
|
2023-12-28 16:49:11 +00:00
|
|
|
bool LinuxAsyncFileTransaction::HasFailed()
|
2022-06-12 13:53:35 +00:00
|
|
|
{
|
|
|
|
return this->hasError_;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt LinuxAsyncFileTransaction::GetOSErrorCode()
|
|
|
|
{
|
|
|
|
return AuUInt(this->error_);
|
|
|
|
}
|
|
|
|
|
2022-04-13 11:00:35 +00:00
|
|
|
AuUInt32 LinuxAsyncFileTransaction::GetLastPacketLength()
|
|
|
|
{
|
|
|
|
return this->lastFinishedStat_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinuxAsyncFileTransaction::SetCallback(const AuSPtr<IAsyncFinishedSubscriber> &sub)
|
|
|
|
{
|
|
|
|
this->sub_ = sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LinuxAsyncFileTransaction::Wait(AuUInt32 timeout)
|
|
|
|
{
|
|
|
|
// TODO:
|
|
|
|
AuList<AuSPtr<IAsyncTransaction>> files {AuUnsafeRaiiToShared(this)};
|
|
|
|
return WaitMultiple(files, timeout);
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
AuSPtr<IIOHandle> LinuxAsyncFileTransaction::GetFileHandle()
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
return this->pHandle_;
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AuSPtr<Loop::ILoopSource> LinuxAsyncFileTransaction::NewLoopSource()
|
|
|
|
{
|
|
|
|
return AuStaticCast<Loop::ILoopSource>(AuStaticCast<Loop::ILSEvent>(this->loopSource_));
|
|
|
|
}
|
|
|
|
|
2022-08-21 02:53:50 +00:00
|
|
|
AUKN_SYM IAsyncFileStream *OpenAsyncNew(const AuString &path, EFileOpenMode openMode, bool bDirectIO, EFileAdvisoryLockLevel lock)
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
2023-12-24 06:22:58 +00:00
|
|
|
auto pHandle = AuIO::IOHandleShared();
|
2023-08-11 15:51:42 +00:00
|
|
|
if (!pHandle)
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
SysPushErrorMemory();
|
|
|
|
return nullptr;
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
AuIO::IIOHandle::HandleCreate createhandle(path);
|
|
|
|
createhandle.eAdvisoryLevel = lock;
|
|
|
|
createhandle.eMode = openMode;
|
|
|
|
createhandle.bFailIfNonEmptyFile = false;
|
|
|
|
createhandle.bDirectIOMode = bDirectIO;
|
|
|
|
createhandle.bAsyncHandle = true;
|
2022-04-13 11:00:35 +00:00
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
if (!pHandle->InitFromPath(createhandle))
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
|
|
|
SysPushErrorNested();
|
2023-08-11 15:51:42 +00:00
|
|
|
return nullptr;
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
auto pStream = _new LinuxAsyncFileStream();
|
|
|
|
if (!pStream)
|
2022-04-13 11:00:35 +00:00
|
|
|
{
|
2023-08-11 15:51:42 +00:00
|
|
|
SysPushErrorMemory();
|
|
|
|
return nullptr;
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
pStream->Init(pHandle);
|
|
|
|
return pStream;
|
2022-04-13 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void OpenAsyncRelease(IAsyncFileStream *handle)
|
|
|
|
{
|
|
|
|
AuSafeDelete<LinuxAsyncFileStream *>(handle);
|
|
|
|
}
|
|
|
|
}
|