[*] Minor cleanup/refactor

This commit is contained in:
Reece Wilson 2022-12-14 05:03:37 +00:00
parent cbad382b6a
commit 49287f2a73
20 changed files with 118 additions and 97 deletions

View File

@ -17,19 +17,19 @@ namespace Aurora::Compression
* If the stream buffer runs out of memory, {bytesRead, 0} is expected, and although
* `GetAvailableProcessedBytes()` will still return some data, the decompressed data
* or uncompressed stream will be dropped in part, and you should destroy from the stream object
* @param bytesFromUnprocessedInputSource
* @param dwBytesFromUnprocessedInputSource
* @return
*/
virtual AuStreamReadWrittenPair_t Ingest(AuUInt32 bytesFromUnprocessedInputSource) = 0;
virtual AuStreamReadWrittenPair_t Ingest(AuUInt32 dwBytesFromUnprocessedInputSource) = 0;
/**
* @brief Returns the available bytes for immediate release
* @brief Returns the available bytes for immediate release by ::Read (or ::ReadEx(..., false))
* @return
*/
virtual AuUInt32 GetAvailableProcessedBytes() = 0;
/**
* @brief Returns the internal overhead to store the seekable stream buffer
* @brief Returns the allocation overhead of the seekable stream buffer
* @return
*/
virtual AuUInt32 GetInternalBufferSize() = 0;
@ -39,31 +39,31 @@ namespace Aurora::Compression
* If the destination is null and the length is a nonzero value, the stream seeks ahead
* If the destination is null and the length is a zero, {0, GetAvailableProcessedBytes} is returned
* @param destination
* @param ingestUntilEOS should continue to poll Ingest with an arbitrary page size to fulfill destination.length
* @param bIngestUntilEOS should continue to poll Ingest with an arbitrary page size to fulfill destination.length
* @return Bytes read / written
*/
virtual AuStreamReadWrittenPair_t ReadEx(const Memory::MemoryViewWrite & /*opt*/ destination, bool ingestUntilEOS = true) = 0;
virtual AuStreamReadWrittenPair_t ReadEx(const Memory::MemoryViewWrite & /*opt*/ destination, bool bIngestUntilEOS = true) = 0;
/**
* @brief Reads 'minimumProcessed', optionally into the first buffer, from the internal stream buffer
* @param destination
* @param dwOffset
* @return Bytes written
*/
virtual AuUInt32 Read(const Memory::MemoryViewWrite & /*opt*/ destination) = 0;
/**
* @brief Seek processed read functions backwards
* @param offset
* @brief Seek processed ::Read/::ReadEx backwards
* @param dwOffset
* @return
*/
virtual bool GoBackByProcessedN (AuUInt32 offset) = 0;
virtual bool GoBackByProcessedN (AuUInt32 dwOffset) = 0;
/**
* @brief Seek read processed forward
* @param offset
* @brief Seek processed ::Read/::ReadEx forwards
* @param dwOffset
* @return
*/
virtual bool GoForwardByProcessedN(AuUInt32 offset) = 0;
virtual bool GoForwardByProcessedN(AuUInt32 dwOffset) = 0;
/// Compression only
virtual bool Flush() = 0;

View File

@ -1175,13 +1175,14 @@ namespace Aurora::Console::ConsoleTTY
return;
}
TTYSetPos(pos);
#if defined(AURORA_IS_MODERNNT_DERIVED)
DWORD idc;
auto line2 = AuLocale::ConvertFromUTF8(in);
SetConsoleCursorPosition(GetTTYHandle(), COORD { AuStaticCast<short>(pos.first), AuStaticCast<short>(pos.second) });
WriteConsoleW(GetTTYHandle(), line2.data(), AuUInt32(line2.size()), &idc, NULL);
#else
TTYSetPos(pos);
ConsoleStd::WriteStdOutBlocking2(in.data(), in.size());
#endif
@ -1198,7 +1199,6 @@ namespace Aurora::Console::ConsoleTTY
return;
}
TTYSetPos(pos);
#if defined(AURORA_IS_MODERNNT_DERIVED)
DWORD idc;
@ -1218,12 +1218,15 @@ namespace Aurora::Console::ConsoleTTY
auto line2 = AuLocale::ConvertFromUTF8(in);
SetConsoleTextAttribute(hConsole, attrib);
SetConsoleCursorPosition(GetTTYHandle(), COORD { AuStaticCast<short>(pos.first), AuStaticCast<short>(pos.second) });
WriteConsoleW(hConsole, line2.data(), AuUInt32(line2.size()), &idc, NULL);
SetConsoleTextAttribute(hConsole, FOREGROUND_WHITE);
}
//WriteConsoleA(GetTTYHandle(), in.data(), AuUInt32(in.size()), &idc, NULL);
#else
TTYSetPos(pos);
AuString writeLine;
const char *pAnsiCode =

View File

@ -1,13 +1,13 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCHandle.cpp
File: AuIPCHandle.cpp
Date: 2022-4-13
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "IPC.hpp"
#include "IPCHandle.hpp"
#include "AuIPCHandle.hpp"
namespace Aurora::IO::IPC
{

View File

@ -1,7 +1,7 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCHandle.hpp
File: AuIPCHandle.hpp
Date: 2022-4-13
Author: Reece
***/

View File

@ -1,14 +1,14 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCMemory.NT.cpp
File: AuIPCMemory.NT.cpp
Date: 2022-4-15
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "IPC.hpp"
#include "IPCHandle.hpp"
#include "IPCMemory.NT.hpp"
#include "AuIPCHandle.hpp"
#include "AuIPCMemory.NT.hpp"
namespace Aurora::IO::IPC
{
@ -16,17 +16,23 @@ namespace Aurora::IO::IPC
// Shared memory
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
IPCSharedMemoryImpl::IPCSharedMemoryImpl(HANDLE handle, void *ptr, const IPC::IPCHandle &ipcHandle) :
base_(ptr), len_(ipcHandle.values[0].token.word), handle_(handle), ipcHandle_(ipcHandle)
IPCSharedMemoryImpl::IPCSharedMemoryImpl(HANDLE handle,
void *pBase,
const IPC::IPCHandle &ipcHandle) :
pBase_(pBase),
uLen_(ipcHandle.values[0].token.word),
handle_(handle),
ipcHandle_(ipcHandle)
{
}
IPCSharedMemoryImpl::~IPCSharedMemoryImpl()
{
if (this->base_)
if (this->pBase_)
{
::UnmapViewOfFile(this->base_);
::UnmapViewOfFile(this->pBase_);
this->pBase_ = nullptr;
}
AuWin32CloseHandle(this->handle_);
@ -34,12 +40,12 @@ namespace Aurora::IO::IPC
Memory::MemoryViewWrite IPCSharedMemoryImpl::GetMemory()
{
return AuMemoryViewWrite(this->base_, this->len_);
return AuMemoryViewWrite(this->pBase_, this->uLen_);
}
AuUInt IPCSharedMemoryImpl::GetLength()
{
return this->len_;
return this->uLen_;
}
AuString IPCSharedMemoryImpl::ExportToString()
@ -47,12 +53,12 @@ namespace Aurora::IO::IPC
return this->ipcHandle_.ToString();
}
AUKN_SYM AuSPtr<IPCSharedMemory> NewSharedMemory(AuUInt length)
AUKN_SYM AuSPtr<IPCSharedMemory> NewSharedMemory(AuUInt uLength)
{
IPC::IPCHandle handle;
IPC::IPCToken token;
token.NewId();
token.word = length;
token.word = uLength;
handle.PushId(EIPCHandleType::eIPCMemory, token);
@ -61,11 +67,11 @@ namespace Aurora::IO::IPC
nullptr,
PAGE_READWRITE,
#if defined(AURORA_IS_64BIT)
AuBitsToHigher(length),
AuBitsToLower(length),
AuBitsToHigher(uLength),
AuBitsToLower(uLength),
#else
0,
length,
uLength,
#endif
path.c_str());
@ -79,7 +85,7 @@ namespace Aurora::IO::IPC
FILE_MAP_ALL_ACCESS,
0,
0,
length);
uLength);
if (!map)
{
SysPushErrorIO();
@ -87,8 +93,8 @@ namespace Aurora::IO::IPC
return {};
}
auto object = AuMakeShared<IPCSharedMemoryImpl>(file, map, handle);
if (!object)
auto pObject = AuMakeShared<IPCSharedMemoryImpl>(file, map, handle);
if (!pObject)
{
SysPushErrorMem();
::UnmapViewOfFile(map);
@ -96,7 +102,7 @@ namespace Aurora::IO::IPC
return {};
}
return object;
return pObject;
}
AUKN_SYM AuSPtr<IPCSharedMemory> ImportSharedMemory(const AuString &handleString)
@ -116,7 +122,7 @@ namespace Aurora::IO::IPC
return {};
}
auto length = token->token.word;
auto uLength = token->token.word;
auto path = token->token.ToNTPath();
auto file = ::OpenFileMappingA(FILE_MAP_ALL_ACCESS,
FALSE,
@ -132,7 +138,7 @@ namespace Aurora::IO::IPC
FILE_MAP_ALL_ACCESS,
0,
0,
length);
uLength);
if (!map)
{
SysPushErrorIO();
@ -140,8 +146,8 @@ namespace Aurora::IO::IPC
return {};
}
auto object = AuMakeShared<IPCSharedMemoryImpl>(file, map, handle);
if (!object)
auto pObject = AuMakeShared<IPCSharedMemoryImpl>(file, map, handle);
if (!pObject)
{
SysPushErrorMem();
::UnmapViewOfFile(map);
@ -149,6 +155,6 @@ namespace Aurora::IO::IPC
return {};
}
return object;
return pObject;
}
}

View File

@ -1,20 +1,22 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCMemory.NT.hpp
File: AuIPCMemory.NT.hpp
Date: 2022-4-15
Author: Reece
***/
#pragma once
#include <Source/IO/IPC/IPC.hpp>
#include <Source/IO/IPC/IPCHandle.hpp>
#include <Source/IO/IPC/AuIPCHandle.hpp>
namespace Aurora::IO::IPC
{
struct IPCSharedMemoryImpl : IPCSharedMemory
{
IPCSharedMemoryImpl(HANDLE handle, void *ptr, const IPC::IPCHandle &ipcHandle);
IPCSharedMemoryImpl(HANDLE handle,
void *pBase,
const IPC::IPCHandle &ipcHandle);
~IPCSharedMemoryImpl();
virtual Memory::MemoryViewWrite GetMemory() override;
@ -24,9 +26,9 @@ namespace Aurora::IO::IPC
private:
IPC::IPCHandle ipcHandle_;
bool owns_;
HANDLE handle_ {};
void *base_{};
AuUInt len_ {};
void *pBase_ {};
AuUInt uLen_ {};
bool bOwns_;
};
}

View File

@ -1,14 +1,14 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCMemory.Unix.cpp
File: AuIPCMemory.Unix.cpp
Date: 2022-4-14
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "IPC.hpp"
#include "IPCHandle.hpp"
#include "IPCMemory.Unix.hpp"
#include "AuIPCHandle.hpp"
#include "AuIPCMemory.Unix.hpp"
#include <sys/mman.h>
#include <sys/stat.h> /* For mode constants */
@ -34,17 +34,24 @@ namespace Aurora::IO::IPC
return path;
}
IPCSharedMemoryImpl::IPCSharedMemoryImpl(int fd, void *ptr, const IPC::IPCHandle &handle, bool owns) :
fd_(fd), base_(ptr), len_(handle.values[0].token.word), owns_(owns), handle_(handle)
IPCSharedMemoryImpl::IPCSharedMemoryImpl(int fd,
void *pBase,
const IPC::IPCHandle &handle,
bool bOwns) :
fd_(fd),
pBase_(ptr),
uLen_(handle.values[0].token.word),
bOwns_(bOwns),
handle_(handle)
{
}
IPCSharedMemoryImpl::~IPCSharedMemoryImpl()
{
if (this->base_)
if (this->pBase_)
{
::munmap(this->base_, this->len_);
::munmap(this->pBase_, this->uLen_);
}
int fd {-1};
@ -56,12 +63,12 @@ namespace Aurora::IO::IPC
Memory::MemoryViewWrite IPCSharedMemoryImpl::GetMemory()
{
return AuMemoryViewWrite(this->base_, this->len_);
return AuMemoryViewWrite(this->pBase_, this->uLen_);
}
AuUInt IPCSharedMemoryImpl::GetLength()
{
return this->len_;
return this->uLen_;
}
AuString IPCSharedMemoryImpl::ExportToString()
@ -69,12 +76,12 @@ namespace Aurora::IO::IPC
return this->handle_.ToString();
}
AUKN_SYM AuSPtr<IPCSharedMemory> NewSharedMemory(AuUInt length)
AUKN_SYM AuSPtr<IPCSharedMemory> NewSharedMemory(AuUInt uLength)
{
IPC::IPCHandle handle;
IPC::IPCToken token;
token.pid = handle.pid;
token.word = length;
token.word = uLength;
token.NewId();
handle.PushId(EIPCHandleType::eIPCMemory, token);
@ -87,14 +94,14 @@ namespace Aurora::IO::IPC
return {};
}
if (::ftruncate(fd, length) == -1)
if (::ftruncate(fd, uLength) == -1)
{
SysPushErrorMem();
::close(fd);
return {};
}
auto map = ::mmap(nullptr, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
auto map = ::mmap(nullptr, uLength, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (map == MAP_FAILED)
{
SysPushErrorIO();
@ -102,16 +109,16 @@ namespace Aurora::IO::IPC
return {};
}
auto object = AuMakeShared<IPCSharedMemoryImpl>(fd, map, handle, true);
if (!object)
auto pObject = AuMakeShared<IPCSharedMemoryImpl>(fd, map, handle, true);
if (!pObject)
{
SysPushErrorMem();
::munmap(map, length);
::munmap(map, uLength);
::close(fd);
return {};
}
return object;
return pObject;
}
AuSPtr<IPCSharedMemory> ImportSharedMemoryEx(const IPCToken &token)
@ -135,8 +142,8 @@ namespace Aurora::IO::IPC
IPC::IPCHandle handle;
handle.PushId(EIPCHandleType::eIPCMemory, token);
auto object = AuMakeShared<IPCSharedMemoryImpl>(fd, map, handle, false);
if (!object)
auto pObject = AuMakeShared<IPCSharedMemoryImpl>(fd, map, handle, false);
if (!pObject)
{
SysPushErrorMem();
::munmap(map, token.word);
@ -144,7 +151,7 @@ namespace Aurora::IO::IPC
return {};
}
return object;
return pObject;
}
AUKN_SYM AuSPtr<IPCSharedMemory> ImportSharedMemory(const AuString &handleString)

View File

@ -1,7 +1,7 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCMemory.Unix.hpp
File: AuIPCMemory.Unix.hpp
Date: 2022-4-14
Author: Reece
***/
@ -14,7 +14,10 @@ namespace Aurora::IO::IPC
{
struct IPCSharedMemoryImpl : IPCSharedMemory
{
IPCSharedMemoryImpl(int fd, void *ptr, const IPC::IPCHandle &handle, bool owns);
IPCSharedMemoryImpl(int fd,
void *pBase,
const IPC::IPCHandle &handle,
bool bOwns);
~IPCSharedMemoryImpl();
virtual Memory::MemoryViewWrite GetMemory() override;
@ -24,10 +27,10 @@ namespace Aurora::IO::IPC
IPC::IPCHandle handle_;
private:
bool owns_;
void *pBase_ {};
AuUInt uLen_ {};
int fd_ {};
void *base_{};
AuUInt len_ {};
bool bOwns_;
};
AuString GetServerPath(const IPC::IPCToken &handle);

View File

@ -1,17 +1,17 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCMutexFutex.Linux.cpp
File: AuIPCMutexFutex.Linux.cpp
Date: 2022-
Author: Reece
Note:
***/
#include <Source/RuntimeInternal.hpp>
#include "IPC.hpp"
#include "IPCHandle.hpp"
#include "IPCMutexFutex.Linux.hpp"
#include "IPCPrimitives.Linux.hpp"
#include "IPCMemory.Unix.hpp"
#include "AuIPCHandle.hpp"
#include "AuIPCMutexFutex.Linux.hpp"
#include "AuIPCPrimitives.Linux.hpp"
#include "AuIPCMemory.Unix.hpp"
// LINUX SYSCALL APIS
#include <linux/futex.h>

View File

@ -1,7 +1,7 @@
#pragma once
#include "IPCHandle.hpp"
#include "IPCPrimitives.Linux.hpp"
#include "AuIPCHandle.hpp"
#include "AuIPCPrimitives.Linux.hpp"
namespace Aurora::IO::IPC
{

View File

@ -1,20 +1,20 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCPipe.NT.cpp
File: AuIPCPipe.NT.cpp
Date: 2022-4-15
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "IPC.hpp"
#include "IPCHandle.hpp"
#include "AuIPCHandle.hpp"
#include <Source/IO/Loop/ILoopSourceEx.hpp>
#include <Source/IO/Loop/LSHandle.hpp>
#include <Source/IO/Loop/LSEvent.hpp>
#include <Source/IO/FS/Async.NT.hpp>
#include "IPCPipe.NT.hpp"
#include "AuIPCPipe.NT.hpp"
namespace Aurora::IO::IPC
{

View File

@ -1,7 +1,7 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCPipe.NT.hpp
File: AuIPCPipe.NT.hpp
Date: 2022-4-15
Author: Reece
***/
@ -9,7 +9,7 @@
#include "IPC.hpp"
#include <Source/IO/IPC/IPCHandle.hpp>
#include <Source/IO/IPC/AuIPCHandle.hpp>
namespace Aurora::IO::IPC
{

View File

@ -1,14 +1,14 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCPipe.Linux.cpp
File: AuIPCPipe.Linux.cpp
Date: 2022-4-14
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "IPC.hpp"
#include "IPCHandle.hpp"
#include "IPCPipe.Unix.hpp"
#include "AuIPCHandle.hpp"
#include "AuIPCPipe.Unix.hpp"
#include <Source/IO/UNIX/FDIpcServer.hpp>
#include <fcntl.h>
#include <sys/ioctl.h>

View File

@ -1,7 +1,7 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCPipe.Unix.hpp
File: AuIPCPipe.Unix.hpp
Date: 2022-4-14
Author: Reece
***/

View File

@ -1,7 +1,7 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCPrimitives.Linux.cpp
File: AuIPCPrimitives.Linux.cpp
Date: 2022-4-13
Author: Reece
***/

View File

@ -1,7 +1,7 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCPrimitives.Linux.hpp
File: AuIPCPrimitives.Linux.hpp
Date: 2022-4-13
Author: Reece
***/

View File

@ -1,14 +1,14 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCPrimitives.NT.cpp
File: AuIPCPrimitives.NT.cpp
Date: 2022-4-13
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "IPC.hpp"
#include "IPCHandle.hpp"
#include "IPCPrimitives.NT.hpp"
#include "AuIPCHandle.hpp"
#include "AuIPCPrimitives.NT.hpp"
#include <Source/IO/Loop/LSMutex.hpp>
#include <Source/IO/Loop/LSSemaphore.hpp>

View File

@ -1,7 +1,7 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCPrimitives.NT.hpp
File: AuIPCPrimitives.NT.hpp
Date: 2022-4-13
Author: Reece
***/