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