Refactor
Some checks failed
CI / Native Windows Build And Tests (push) Has been cancelled
CI / React UI Build (push) Has been cancelled
CI / Windows Release Package (push) Has been cancelled

This commit is contained in:
2026-05-06 09:28:46 +10:00
parent 437199f3f0
commit 0bfffa6552
41 changed files with 1592 additions and 1368 deletions

View File

@@ -0,0 +1,42 @@
#pragma once
#include <windows.h>
class UniqueHandle
{
public:
explicit UniqueHandle(HANDLE handle = NULL) : mHandle(handle) {}
~UniqueHandle() { reset(); }
UniqueHandle(const UniqueHandle&) = delete;
UniqueHandle& operator=(const UniqueHandle&) = delete;
UniqueHandle(UniqueHandle&& other) noexcept : mHandle(other.release()) {}
UniqueHandle& operator=(UniqueHandle&& other) noexcept
{
if (this != &other)
reset(other.release());
return *this;
}
HANDLE get() const { return mHandle; }
bool valid() const { return mHandle != NULL && mHandle != INVALID_HANDLE_VALUE; }
HANDLE release()
{
HANDLE handle = mHandle;
mHandle = NULL;
return handle;
}
void reset(HANDLE handle = NULL)
{
if (valid())
CloseHandle(mHandle);
mHandle = handle;
}
private:
HANDLE mHandle;
};

View File

@@ -0,0 +1,42 @@
#pragma once
#include <winsock2.h>
class UniqueSocket
{
public:
explicit UniqueSocket(SOCKET socket = INVALID_SOCKET) : mSocket(socket) {}
~UniqueSocket() { reset(); }
UniqueSocket(const UniqueSocket&) = delete;
UniqueSocket& operator=(const UniqueSocket&) = delete;
UniqueSocket(UniqueSocket&& other) noexcept : mSocket(other.release()) {}
UniqueSocket& operator=(UniqueSocket&& other) noexcept
{
if (this != &other)
reset(other.release());
return *this;
}
SOCKET get() const { return mSocket; }
bool valid() const { return mSocket != INVALID_SOCKET; }
SOCKET release()
{
SOCKET socket = mSocket;
mSocket = INVALID_SOCKET;
return socket;
}
void reset(SOCKET socket = INVALID_SOCKET)
{
if (valid())
closesocket(mSocket);
mSocket = socket;
}
private:
SOCKET mSocket;
};