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 <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;
};