[*] IOHandle is now 192 bytes
[*] Autohandle duplication
This commit is contained in:
parent
582b32ded9
commit
3f265cf19b
@ -159,7 +159,7 @@ namespace Aurora::IO
|
||||
virtual AuUInt64 GetFileLength() = 0;
|
||||
};
|
||||
|
||||
AUKN_SHARED_SOO_CC(IOHandle, IIOHandle, 256);
|
||||
AUKN_SHARED_SOO_CC(IOHandle, IIOHandle, 192);
|
||||
|
||||
AUKN_SYM bool IsHandleTTY(AuUInt uHandle);
|
||||
|
||||
|
@ -19,6 +19,11 @@
|
||||
|
||||
namespace Aurora::IO
|
||||
{
|
||||
AFileHandle::AFileHandle()
|
||||
{
|
||||
this->uThreadId = AuUInt(AuThreads::GetThreadId());
|
||||
}
|
||||
|
||||
AFileHandle::~AFileHandle()
|
||||
{
|
||||
if (this->SharingIsShared())
|
||||
@ -411,6 +416,11 @@ namespace Aurora::IO
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool AFileHandle::ShouldClone()
|
||||
{
|
||||
return this->uThreadId != AuUInt(AuThreads::GetThreadId());
|
||||
}
|
||||
|
||||
AUKN_SYM IIOHandle *IOHandleNew()
|
||||
{
|
||||
return _new AFileHandle();
|
||||
|
@ -16,6 +16,8 @@ namespace Aurora::IO
|
||||
{
|
||||
struct AFileHandle : IIOHandle
|
||||
{
|
||||
AFileHandle();
|
||||
|
||||
~AFileHandle();
|
||||
|
||||
bool InitFromHandle(AuSPtr<IIOHandle> pHandle) override;
|
||||
@ -79,6 +81,8 @@ namespace Aurora::IO
|
||||
|
||||
AuUInt64 GetFileLength() override;
|
||||
|
||||
bool ShouldClone();
|
||||
|
||||
AuOptionalEx<AuUInt64> uOSWriteHandle;
|
||||
AuOptionalEx<AuUInt64> uOSReadHandle;
|
||||
AuSPtr<IIOHandle> pThat;
|
||||
@ -90,6 +94,7 @@ namespace Aurora::IO
|
||||
mutable AuOptional<bool> optIsPipe;
|
||||
mutable AuOptional<bool> optIsTTY;
|
||||
mutable AuSPtr<AuString> pIPCString;
|
||||
AuUInt uThreadId {};
|
||||
|
||||
protected:
|
||||
// Implement me:
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "FS.hpp"
|
||||
#include "FileStream.NT.hpp"
|
||||
#include "FileAdvisory.NT.hpp"
|
||||
#include <Source/IO/AuIOHandle.hpp>
|
||||
|
||||
#if !defined(_AURUNTIME_GENERICFILESTREAM)
|
||||
|
||||
@ -515,9 +516,20 @@ namespace Aurora::IO::FS
|
||||
|
||||
AUKN_SYM AuSPtr<IFileStream> OpenBlockingFileStreamFromHandle(AuSPtr<IIOHandle> pIOHandle)
|
||||
{
|
||||
SysCheckArgNotNull(pIOHandle, {});
|
||||
|
||||
auto pStream = AuMakeShared<WinFileStream>();
|
||||
SysCheckNotNullMemory(pStream, {});
|
||||
|
||||
if (!AuStaticCast<AFileHandle>(pIOHandle)->pIPCPipe &&
|
||||
AuStaticCast<AFileHandle>(pIOHandle)->ShouldClone())
|
||||
{
|
||||
auto pOld = pIOHandle;
|
||||
pIOHandle = AuMakeShared<AFileHandle>();
|
||||
SysCheckNotNullMemory(pIOHandle, {});
|
||||
pIOHandle->InitFromPair(pOld->GetOSReadHandleSafe(), pOld->GetOSWriteHandle());
|
||||
}
|
||||
|
||||
pStream->Init(pIOHandle);
|
||||
return pStream;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <Source/IO/AuIOHandle.hpp>
|
||||
|
||||
#if !defined(_AURUNTIME_GENERICFILESTREAM)
|
||||
|
||||
@ -385,11 +386,18 @@ namespace Aurora::IO::FS
|
||||
|
||||
AUKN_SYM AuSPtr<IFileStream> OpenBlockingFileStreamFromHandle(AuSPtr<IIOHandle> pIOHandle)
|
||||
{
|
||||
SysCheckArgNotNull(pIOHandle, {});
|
||||
|
||||
auto pStream = AuMakeShared<PosixFileStream>();
|
||||
if (!pStream)
|
||||
SysCheckNotNullMemory(pStream, {});
|
||||
|
||||
if (!AuStaticCast<AFileHandle>(pIOHandle)->pIPCPipe &&
|
||||
AuStaticCast<AFileHandle>(pIOHandle)->ShouldClone())
|
||||
{
|
||||
SysPushErrorMemory();
|
||||
return nullptr;
|
||||
auto pOld = pIOHandle;
|
||||
pIOHandle = AuMakeShared<AFileHandle>();
|
||||
SysCheckNotNullMemory(pIOHandle, {});
|
||||
pIOHandle->InitFromPair(pOld->GetOSReadHandleSafe(), pOld->GetOSWriteHandle());
|
||||
}
|
||||
|
||||
pStream->Init(pIOHandle);
|
||||
|
Loading…
Reference in New Issue
Block a user