[+] AuFS::OpenAsyncFromSharedHandle

This commit is contained in:
Reece Wilson 2024-03-09 00:56:59 +00:00
parent 48aa0f01b1
commit a9fd9221b7
3 changed files with 49 additions and 11 deletions

View File

@ -12,13 +12,9 @@ namespace Aurora::IO::FS
AUKN_SHARED_API(OpenAsync, IAsyncFileStream,
const AuString &path,
EFileOpenMode openMode,
bool bDirectIO = true, // true disables buffering under Win32
// true enables non-blocking ticks under Linux aio by bypassing the kernels cache
EFileAdvisoryLockLevel lock = EFileAdvisoryLockLevel::eNoSafety);
AuOptional<bool> optbDirectIO = { true },
AuOptional<EFileAdvisoryLockLevel> optLock = { EFileAdvisoryLockLevel::eNoSafety });
#if defined(AUX_FSAOPEX)
AUKN_SYM AuSPtr<IAsyncTransaction> OpenDirectIOAsyncFileStreamFromHandle(AuSPtr<IIOHandle> pIOHandle);
AUKN_SYM AuSPtr<IAsyncTransaction> OpenBufferedAsyncFileStreamFromHandle(AuSPtr<IIOHandle> pIOHandle);
#endif
AUKN_SHARED_API(OpenAsyncFromSharedHandle, IAsyncFileStream,
const AuSPtr<IIOHandle> &pIOHandle);
}

View File

@ -611,8 +611,11 @@ namespace Aurora::IO::FS
}
}
AUKN_SYM IAsyncFileStream *OpenAsyncNew(const AuString &path, EFileOpenMode openMode, bool bDirectIO, EFileAdvisoryLockLevel lock)
AUKN_SYM IAsyncFileStream *OpenAsyncNew(const AuString &path, EFileOpenMode openMode, AuOptional<bool> optbDirectIO, AuOptional<EFileAdvisoryLockLevel> optLock)
{
auto bDirectIO = optbDirectIO.ValueOr(true);
auto lock = optLock.ValueOr(EFileAdvisoryLockLevel::eNoSafety);
auto pHandle = AuIO::IOHandleShared();
if (!pHandle)
{
@ -648,4 +651,22 @@ namespace Aurora::IO::FS
{
AuSafeDelete<LinuxAsyncFileStream *>(handle);
}
AUKN_SYM IAsyncFileStream *OpenAsyncFromSharedHandleNew(const AuSPtr<IIOHandle> &pIOHandle)
{
auto pStream = _new LinuxAsyncFileStream();
if (!pStream)
{
SysPushErrorMemory();
return nullptr;
}
pStream->Init(pIOHandle);
return pStream;
}
AUKN_SYM void OpenAsyncFromSharedHandleRelease(IAsyncFileStream *handle)
{
AuSafeDelete<LinuxAsyncFileStream *>(handle);
}
}

View File

@ -667,8 +667,11 @@ namespace Aurora::IO::FS
}
}
AUKN_SYM IAsyncFileStream *OpenAsyncNew(const AuString &path, EFileOpenMode openMode, bool directIO, EFileAdvisoryLockLevel lock)
AUKN_SYM IAsyncFileStream *OpenAsyncNew(const AuString &path, EFileOpenMode openMode, AuOptional<bool> optbDirectIO, AuOptional<EFileAdvisoryLockLevel> optLock)
{
auto bDirectIO = optbDirectIO.ValueOr(true);
auto lock = optLock.ValueOr(EFileAdvisoryLockLevel::eNoSafety);
auto pHandle = AuIO::IOHandleShared();
if (!pHandle)
{
@ -680,7 +683,7 @@ namespace Aurora::IO::FS
createhandle.eAdvisoryLevel = lock;
createhandle.eMode = openMode;
createhandle.bFailIfNonEmptyFile = false;
createhandle.bDirectIOMode = directIO;
createhandle.bDirectIOMode = bDirectIO;
createhandle.bAsyncHandle = true;
if (!pHandle->InitFromPath(createhandle))
@ -704,4 +707,22 @@ namespace Aurora::IO::FS
{
AuSafeDelete<NtAsyncFileStream *>(handle);
}
AUKN_SYM IAsyncFileStream *OpenAsyncFromSharedHandleNew(const AuSPtr<IIOHandle> &pIOHandle)
{
auto pStream = _new NtAsyncFileStream();
if (!pStream)
{
SysPushErrorMemory();
return nullptr;
}
pStream->Init(pIOHandle);
return pStream;
}
AUKN_SYM void OpenAsyncFromSharedHandleRelease(IAsyncFileStream *handle)
{
AuSafeDelete<NtAsyncFileStream *>(handle);
}
}