AuroraRuntime/Source/IO/FS/FileStream.Unix.hpp

54 lines
1.8 KiB
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: FileStream.Unix.hpp
2021-06-27 21:25:29 +00:00
Date: 2021-6-12
Author: Reece
***/
#pragma once
#if !defined(_AURUNTIME_GENERICFILESTREAM)
namespace Aurora::IO::FS
{
// Code-sharing for async API fallbacks...
bool PosixSetOffset(int fd, AuUInt64 offset);
AuUInt64 PosixGetLength(int fd);
bool PosixRead(int fd, void *buf, AuUInt32 count, AuUInt32 *pRead);
bool PosixWrite(int fd, const void *buf, AuUInt32 count, AuUInt32 *pWritten);
struct PosixFileStream : IFileStream
2021-06-27 21:25:29 +00:00
{
PosixFileStream();
~PosixFileStream();
2021-06-27 21:25:29 +00:00
bool Init(AuSPtr<IIOHandle> pHandle);
2021-06-27 21:25:29 +00:00
AuUInt64 GetOffset() override;
bool SetOffset(AuUInt64 offset) override;
AuUInt64 GetLength() override;
bool Read(const Memory::MemoryViewStreamWrite &parameters) override;
bool Write(const Memory::MemoryViewStreamRead & parameters) override;
2021-06-27 21:25:29 +00:00
void Close() override;
void Flush() override;
void WriteEoS() override;
void MakeTemporary() override;
bool IsFlushOnClose() const override;
void SetFlushOnClose(bool bFlushOnClose) override;
bool IsWriteEoSOnClose() const override;
void SetWriteEoSOnClose(bool bFlushOnClose) override;
AuSPtr<IIOHandle> GetHandle() override;
IO::IStreamReader *ToStreamReader() override;
IO::IStreamWriter *ToStreamWriter() override;
int GetUnixHandle();
2021-06-27 21:25:29 +00:00
private:
AuSPtr<IIOHandle> pHandle_;
2021-09-06 10:58:08 +00:00
AuString path_;
AuThreadPrimitives::SpinLock spinlock_;
bool bMadeTemporary {}, bShouldWriteEoS {};
AuFS::FileReader reader_;
AuFS::FileWriter writer_;
2021-06-27 21:25:29 +00:00
};
}
#endif