[+] IFileStream::ToStreamSeekingReader
[+] IFileStream::ToStreamSeekingWriter [*] Mitigation for Linshids god awful IO subsystems
This commit is contained in:
parent
66f3250983
commit
48aa0f01b1
@ -14,6 +14,7 @@ namespace Aurora::IO
|
||||
|
||||
namespace Aurora::IO::FS
|
||||
{
|
||||
// Thread-Local!
|
||||
struct IAsyncFileStream
|
||||
{
|
||||
virtual AuSPtr<IAsyncTransaction> NewTransaction() = 0;
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
namespace Aurora::IO::FS
|
||||
{
|
||||
// Thread-Local!
|
||||
struct IFileStream
|
||||
{
|
||||
/**
|
||||
@ -103,6 +104,10 @@ namespace Aurora::IO::FS
|
||||
*/
|
||||
virtual IO::IStreamWriter *ToStreamWriter() = 0;
|
||||
|
||||
virtual IO::ISeekingReader *ToStreamSeekingReader() = 0;
|
||||
|
||||
virtual IO::ISeekingWriter *ToStreamSeekingWriter() = 0;
|
||||
|
||||
AURT_ADD_USR_DATA;
|
||||
};
|
||||
}
|
@ -29,6 +29,7 @@ namespace Aurora::IO
|
||||
* Do not access this object across threads as there is no MT guarantee on this particular object
|
||||
* Using the synchronization primitives, loop or authreading, is fine.
|
||||
*/
|
||||
// Thread-Local!
|
||||
struct IAsyncTransaction
|
||||
{
|
||||
virtual bool StartRead(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewWrite> &memoryView) = 0;
|
||||
|
@ -143,8 +143,7 @@ namespace Aurora::IO
|
||||
return false;
|
||||
}
|
||||
|
||||
if (create.bAsyncHandle ||
|
||||
create.bDirectIOMode)
|
||||
if (create.bDirectIOMode)
|
||||
{
|
||||
this->bDirectIO = true;
|
||||
}
|
||||
|
@ -139,6 +139,26 @@ namespace Aurora::IO::FS
|
||||
|
||||
AuSPtr<IAsyncTransaction> LinuxAsyncFileStream::NewTransaction()
|
||||
{
|
||||
if (!AuStaticCast<AuIO::AFileHandle>(this->pHandle_)->bDirectIO)
|
||||
{
|
||||
auto &pFSReader = this->pCache_;
|
||||
|
||||
if (!pFSReader)
|
||||
{
|
||||
pFSReader = AuFS::OpenBlockingFileStreamFromHandle(this->pHandle_);
|
||||
}
|
||||
|
||||
if (!pFSReader)
|
||||
{
|
||||
SysPushErrorNested();
|
||||
return {};
|
||||
}
|
||||
|
||||
auto pStreamReader = AuSharedPointerFromShared(pFSReader->ToStreamSeekingReader(), pFSReader);
|
||||
auto pStreamWriter = AuSharedPointerFromShared(pFSReader->ToStreamSeekingWriter(), pFSReader);
|
||||
return Adapters::NewAsyncTransactionFromStreamSeekingPair(pStreamReader, pStreamWriter, {});
|
||||
}
|
||||
|
||||
auto shared = AuMakeShared<LinuxAsyncFileTransaction>(this->pProcessBlock_);
|
||||
if (!shared)
|
||||
{
|
||||
|
@ -41,6 +41,7 @@ namespace Aurora::IO::FS
|
||||
private:
|
||||
AuSPtr<ProcessBlock> pProcessBlock_;
|
||||
AuSPtr<IIOHandle> pHandle_;
|
||||
AuSPtr<IFileStream> pCache_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -18,7 +18,9 @@ namespace Aurora::IO::FS
|
||||
|
||||
WinFileStream::WinFileStream() :
|
||||
reader_(AuUnsafeRaiiToShared(this)),
|
||||
writer_(AuUnsafeRaiiToShared(this))
|
||||
writer_(AuUnsafeRaiiToShared(this)),
|
||||
sreader_(AuUnsafeRaiiToShared(this)),
|
||||
swriter_(AuUnsafeRaiiToShared(this))
|
||||
{
|
||||
|
||||
}
|
||||
@ -484,6 +486,16 @@ namespace Aurora::IO::FS
|
||||
return &this->writer_;
|
||||
}
|
||||
|
||||
IO::ISeekingReader *WinFileStream::ToStreamSeekingReader()
|
||||
{
|
||||
return &this->sreader_;
|
||||
}
|
||||
|
||||
IO::ISeekingWriter *WinFileStream::ToStreamSeekingWriter()
|
||||
{
|
||||
return &this->swriter_;
|
||||
}
|
||||
|
||||
HANDLE WinFileStream::GetWin32Handle(bool bReadOnly)
|
||||
{
|
||||
if (auto pHandle = this->pHandle_)
|
||||
|
@ -34,6 +34,8 @@ namespace Aurora::IO::FS
|
||||
void SetWriteEoSOnClose(bool bFlushOnClose) override;
|
||||
IO::IStreamReader *ToStreamReader() override;
|
||||
IO::IStreamWriter *ToStreamWriter() override;
|
||||
IO::ISeekingReader *ToStreamSeekingReader() override;
|
||||
IO::ISeekingWriter *ToStreamSeekingWriter() override;
|
||||
|
||||
HANDLE GetWin32Handle(bool bReadOnly = false);
|
||||
|
||||
@ -43,6 +45,8 @@ namespace Aurora::IO::FS
|
||||
HANDLE hEventHandle_ { INVALID_HANDLE_VALUE };
|
||||
AuFS::FileReader reader_;
|
||||
AuFS::FileWriter writer_;
|
||||
AuFS::FileSeekableReader sreader_;
|
||||
AuFS::FileSeekableWriter swriter_;
|
||||
};
|
||||
}
|
||||
#endif
|
@ -25,7 +25,9 @@ namespace Aurora::IO::FS
|
||||
|
||||
PosixFileStream::PosixFileStream() :
|
||||
reader_(AuUnsafeRaiiToShared(this)),
|
||||
writer_(AuUnsafeRaiiToShared(this))
|
||||
writer_(AuUnsafeRaiiToShared(this)),
|
||||
sreader_(AuUnsafeRaiiToShared(this)),
|
||||
swriter_(AuUnsafeRaiiToShared(this))
|
||||
{
|
||||
|
||||
}
|
||||
@ -371,6 +373,16 @@ namespace Aurora::IO::FS
|
||||
return &this->writer_;
|
||||
}
|
||||
|
||||
IO::ISeekingReader *PosixFileStream::ToStreamSeekingReader()
|
||||
{
|
||||
return &this->sreader_;
|
||||
}
|
||||
|
||||
IO::ISeekingWriter *PosixFileStream::ToStreamSeekingWriter()
|
||||
{
|
||||
return &this->swriter_;
|
||||
}
|
||||
|
||||
AUKN_SYM AuSPtr<IFileStream> OpenBlockingFileStreamFromHandle(AuSPtr<IIOHandle> pIOHandle)
|
||||
{
|
||||
auto pStream = AuMakeShared<PosixFileStream>();
|
||||
|
@ -35,6 +35,8 @@ namespace Aurora::IO::FS
|
||||
AuSPtr<IIOHandle> GetHandle() override;
|
||||
IO::IStreamReader *ToStreamReader() override;
|
||||
IO::IStreamWriter *ToStreamWriter() override;
|
||||
IO::ISeekingReader *ToStreamSeekingReader() override;
|
||||
IO::ISeekingWriter *ToStreamSeekingWriter() override;
|
||||
int GetUnixHandle();
|
||||
|
||||
private:
|
||||
@ -44,6 +46,8 @@ namespace Aurora::IO::FS
|
||||
bool bMadeTemporary {}, bShouldWriteEoS {};
|
||||
AuFS::FileReader reader_;
|
||||
AuFS::FileWriter writer_;
|
||||
AuFS::FileSeekableReader sreader_;
|
||||
AuFS::FileSeekableWriter swriter_;
|
||||
};
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user