[+] Added _AU_SAW_WIN32_EARLY for AuLoop::NewLSHandle in AuWin32Utils.hpp

[*] Clean up AuROXTL
This commit is contained in:
Reece Wilson 2022-02-27 09:07:41 +00:00
parent 907b5d1b33
commit 805eae7f3d
5 changed files with 68 additions and 31 deletions

View File

@ -78,12 +78,12 @@ namespace Aurora::Loop
}
#endif
#if defined(AURORA_IS_MODERNNT_DERIVED)
//static AuSPtr<ILoopSource> NewLSHandle(HANDLE handle)
//{
// if (handle == INVALID_HANDLE_VALUE) return {};
// return NewLSOSHandle(reinterpret_cast<AuUInt>(handle));
//}
#if defined(AURORA_IS_MODERNNT_DERIVED) && defined(_AU_SAW_WIN32_EARLY)
static AuSPtr<ILoopSource> NewLSHandle(HANDLE handle)
{
if (handle == INVALID_HANDLE_VALUE) return {};
return NewLSOSHandle(reinterpret_cast<AuUInt>(handle));
}
#endif
}

View File

@ -165,10 +165,10 @@ static AuUInt8 AuPopCnt(T in)
#if defined(AU_CPU_ENDIAN_LITTLE)
if constexpr (sizeof(T) == sizeof(AuUInt64))
{
AuUInt64 m1 = 0x5555555555555555ll;
AuUInt64 m2 = 0x3333333333333333ll;
AuUInt64 m4 = 0x0F0F0F0F0F0F0F0Fll;
AuUInt64 h01 = 0x0101010101010101ll;
const AuUInt64 m1 = 0x5555555555555555ll;
const AuUInt64 m2 = 0x3333333333333333ll;
const AuUInt64 m4 = 0x0F0F0F0F0F0F0F0Fll;
const AuUInt64 h01 = 0x0101010101010101ll;
in -= (in >> 1) & m1;
in = (in & m2) + ((in >> 2) & m2);
@ -178,9 +178,16 @@ static AuUInt8 AuPopCnt(T in)
}
else if constexpr (sizeof(T) == sizeof(AuUInt32))
{
in = in - ((in >> 1) & 0x55555555);
in = (in & 0x33333333) + ((in >> 2) & 0x33333333);
return (((in + (in >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
const AuUInt32 m1 = 0x55555555l;
const AuUInt32 m2 = 0x33333333l;
const AuUInt32 m4 = 0x0F0F0F0Fl;
const AuUInt32 h01 = 0x01010101l;
in -= (in >> 1) & m1;
in = (in & m2) + ((in >> 2) & m2);
in = (in + (in >> 4)) & m4;
return (in * h01) >> 24;
}
#endif

View File

@ -7,6 +7,11 @@
***/
#pragma once
/**
* @brief
* @param buffer
* @return A non-determinstic/platform specific magic number that once written with respect to endianness emits the tag
*/
static constexpr auline AuUInt32 AuConvertMagicTag32(const char buffer[4])
{
AuUInt32 magic {};
@ -16,32 +21,22 @@ static constexpr auline AuUInt32 AuConvertMagicTag32(const char buffer[4])
magic |= AuUInt32(buffer[1]) << 8;
magic |= AuUInt32(buffer[2]) << 16;
magic |= AuUInt32(buffer[3]) << 24;
// LE will look alright in memory dumps
// MSFT uses tags that read back the initial string value when read back hex ints
// I prefer binary streams and file headers contain a 4x or 8x ascii char headers (eg. LuaX)
}
else
{
// Lazy reinterpret cast reads will always be flipped
// Assume byte buffers read/write machine endian
// Assume *reinterpret_cast<T*> returns machine endian
// BE needs to be flipped in memory
// BE will look fine in memory dumps
// BE will also look fine in stack/variable dumps when printed in hex
magic |= AuUInt32(buffer[4]);
magic |= AuUInt32(buffer[2]) << 8;
magic |= AuUInt32(buffer[1]) << 16;
magic |= AuUInt32(buffer[0]) << 24;
}
// Determinstic across platforms, perhaps unexpected by endian normalized streams
// When asserting read(noEndian) against a tag, an endian swap would cause the
// assertion to fail, thus providing you with the endian match check
// This step is delegated to a de-facto machine endian buffer builder
// ByteBuffers that normalize for endianness continue to work with tags
// irrespective of reader/writer endianness
return magic;
}
/**
* @brief
* @param buffer
* @return A non-determinstic/platform specific magic number that once written with respect to endianness emits the tag
*/
static constexpr auline AuUInt64 AuConvertMagicTag64(const char buffer[8])
{
AuUInt64 magic {};

View File

@ -8,6 +8,9 @@
#pragma once
#if defined(AURORA_IS_MODERNNT_DERIVED) && (defined(_WINDOWS_) || defined(_OTHER_MS_MAIN_HEADER_GUARDS_HERE))
#define _AU_SAW_WIN32_EARLY
static auline void AuWin32CloseHandle(HANDLE &handle)
{
HANDLE local;

View File

@ -6,27 +6,59 @@
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Net.hpp"
#include "IPAddress.hpp"
namespace Aurora::IO::Net
{
IPAddress::IPAddress()
{
this->ip = EIPProtocol::eEnumInvalid;
}
IPAddress::IPAddress(const AuString &parse)
{
unsigned char buf[64];
static_assert(AuArraySize(buf) >= sizeof(struct in6_addr));
static_assert(AuArraySize(buf) >= sizeof(struct in_addr));
this->ip = EIPProtocol::eEnumInvalid;
bool isIPV4 {};
if (parse.size() > 4)
{
isIPV4 = parse[1] == '.' || parse[2] == '.';
}
if (inet_pton(isIPV4 ? AF_INET : AF_INET6, parse.c_str(), buf) != 1)
{
return;
}
if (isIPV4)
{
AuWriteU32BE(this->v4, 0, AuReadU32LE(buf, 0));
}
else
{
auto ipv6 = reinterpret_cast<AuUInt16 *>(buf);
AuWriteU16BE(&this->v6[0], 0, ipv6[0]);
AuWriteU16BE(&this->v6[1], 0, ipv6[1]);
AuWriteU16BE(&this->v6[2], 0, ipv6[2]);
AuWriteU16BE(&this->v6[3], 0, ipv6[3]);
AuWriteU16BE(&this->v6[4], 0, ipv6[4]);
AuWriteU16BE(&this->v6[5], 0, ipv6[5]);
AuWriteU16BE(&this->v6[6], 0, ipv6[6]);
}
}
AuString IPAddress::ToString() const
{
return {};
}
bool IPAddress::IsValid() const
{
return {};
return EIPProtocolIsValid(this->ip);
}
}