[+] Optional blocking operations for Linux async file objects
This commit is contained in:
parent
e90be1801a
commit
1f15674016
@ -15,6 +15,7 @@
|
||||
#include <Source/IO/UNIX/IOSubmit.Linux.hpp>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "FileStream.Unix.hpp"
|
||||
|
||||
namespace Aurora::IO::FS
|
||||
{
|
||||
@ -46,6 +47,9 @@ namespace Aurora::IO::FS
|
||||
struct LinuxAsyncFileStream : public 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<FileHandle> &handle);
|
||||
|
||||
@ -180,6 +184,43 @@ namespace Aurora::IO::FS
|
||||
return shared;
|
||||
}
|
||||
|
||||
bool LinuxAsyncFileStream::BlockingTruncate(AuUInt64 length)
|
||||
{
|
||||
return ::ftruncate(this->handle_->handle, length) != -1;
|
||||
}
|
||||
|
||||
bool LinuxAsyncFileStream::BlockingRead(AuUInt64 offset, const Memory::MemoryViewStreamWrite ¶meters)
|
||||
{
|
||||
if (!PosixSetOffset(this->handle_->handle, offset))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AuUInt32 read;
|
||||
if (!PosixRead(this->handle_->handle, parameters.ptr, parameters.length, &read))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LinuxAsyncFileStream::BlockingWrite(AuUInt64 offset, const Memory::MemoryViewStreamRead ¶meters)
|
||||
{
|
||||
if (!PosixSetOffset(this->handle_->handle, offset))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AuUInt32 read;
|
||||
if (!PosixWrite(this->handle_->handle, parameters.ptr, parameters.length, &read))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LinuxAsyncFileTransaction::Init(const AuSPtr<FileHandle> &handle)
|
||||
{
|
||||
this->handle_ = handle;
|
||||
|
8
Source/IO/FS/FileStream.Unix.cpp
Normal file → Executable file
8
Source/IO/FS/FileStream.Unix.cpp
Normal file → Executable file
@ -41,7 +41,7 @@ namespace Aurora::IO::FS
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
SysPushErrorIO("PosixLseek63 IO Error: %i", ret);
|
||||
//SysPushErrorIO("PosixLseek63 IO Error: %i", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ namespace Aurora::IO::FS
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool PosixSetOffset(int fd, AuUInt64 offset)
|
||||
bool PosixSetOffset(int fd, AuUInt64 offset)
|
||||
{
|
||||
return PosixLseek63(fd, offset, SEEK_SET, nullptr);
|
||||
}
|
||||
@ -84,7 +84,7 @@ namespace Aurora::IO::FS
|
||||
return status ? ret : 0;
|
||||
}
|
||||
|
||||
static bool PosixRead(int fd, void *buf, AuUInt32 count, AuUInt32 *pRead)
|
||||
bool PosixRead(int fd, void *buf, AuUInt32 count, AuUInt32 *pRead)
|
||||
{
|
||||
auto ret = read(fd, buf, count);
|
||||
|
||||
@ -102,7 +102,7 @@ namespace Aurora::IO::FS
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool PosixWrite(int fd, const void *buf, AuUInt32 count, AuUInt32 *pWritten)
|
||||
bool PosixWrite(int fd, const void *buf, AuUInt32 count, AuUInt32 *pWritten)
|
||||
{
|
||||
auto ret = write(fd, buf, count);
|
||||
|
||||
|
@ -11,6 +11,11 @@
|
||||
|
||||
namespace Aurora::IO::FS
|
||||
{
|
||||
// Code-sharing for async API fallbacks...
|
||||
bool PosixSetOffset(int fd, AuUInt64 offset);
|
||||
bool PosixRead(int fd, void *buf, AuUInt32 count, AuUInt32 *pRead);
|
||||
bool PosixWrite(int fd, const void *buf, AuUInt32 count, AuUInt32 *pWritten);
|
||||
|
||||
class PosixFileStream : public IFileStream
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user