core, yuzu: Address first part of review comments

This commit is contained in:
FearlessTobi 2022-08-01 22:47:39 +02:00
parent a5cd639cb6
commit 6d41088153
9 changed files with 70 additions and 71 deletions

View file

@ -352,8 +352,8 @@ std::optional<IPv4Address> GetHostIPv4Address() {
return {};
}
char ip_addr[16] = {};
ASSERT(inet_ntop(AF_INET, &interface->ip_address, ip_addr, sizeof(ip_addr)) != nullptr);
std::array<char, 16> ip_addr = {};
ASSERT(inet_ntop(AF_INET, &interface->ip_address, ip_addr.data(), sizeof(ip_addr)) != nullptr);
return TranslateIPv4(interface->ip_address);
}
@ -402,9 +402,9 @@ Socket::Socket(Socket&& rhs) noexcept {
}
template <typename T>
Errno Socket::SetSockOpt(SOCKET _fd, int option, T value) {
Errno Socket::SetSockOpt(SOCKET fd_, int option, T value) {
const int result =
setsockopt(_fd, SOL_SOCKET, option, reinterpret_cast<const char*>(&value), sizeof(value));
setsockopt(fd_, SOL_SOCKET, option, reinterpret_cast<const char*>(&value), sizeof(value));
if (result != SOCKET_ERROR) {
return Errno::SUCCESS;
}

View file

@ -30,19 +30,19 @@ void ProxySocket::HandleProxyPacket(const ProxyPacket& packet) {
closed) {
return;
}
std::lock_guard<std::mutex> guard(packets_mutex);
std::lock_guard guard(packets_mutex);
received_packets.push(packet);
}
template <typename T>
Errno ProxySocket::SetSockOpt(SOCKET _fd, int option, T value) {
Errno ProxySocket::SetSockOpt(SOCKET fd_, int option, T value) {
socket_options[option] = reinterpret_cast<const char*>(&value);
return Errno::SUCCESS;
}
Errno ProxySocket::Initialize(Domain domain, Type type, Protocol socket_protocol) {
protocol = socket_protocol;
socket_options[0x1008] = reinterpret_cast<const char*>(&type);
SetSockOpt(fd, SO_TYPE, type);
return Errno::SUCCESS;
}
@ -101,7 +101,7 @@ std::pair<s32, Errno> ProxySocket::RecvFrom(int flags, std::vector<u8>& message,
ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
{
std::lock_guard<std::mutex> guard(packets_mutex);
std::lock_guard guard(packets_mutex);
if (received_packets.size() > 0) {
return ReceivePacket(flags, message, addr, message.size());
}
@ -115,7 +115,7 @@ std::pair<s32, Errno> ProxySocket::RecvFrom(int flags, std::vector<u8>& message,
return {-1, Errno::AGAIN};
}
std::lock_guard<std::mutex> guard(packets_mutex);
std::lock_guard guard(packets_mutex);
if (received_packets.size() > 0) {
return ReceivePacket(flags, message, addr, message.size());
}

View file

@ -14,7 +14,7 @@ namespace Network {
class ProxySocket : public SocketBase {
public:
ProxySocket(RoomNetwork& room_network_) noexcept;
explicit ProxySocket(RoomNetwork& room_network_) noexcept;
~ProxySocket() override;
ProxySocket(const ProxySocket&) = delete;
@ -82,6 +82,7 @@ public:
bool IsOpened() const override;
private:
bool broadcast = false;
bool closed = false;
u32 send_timeout = 0;

View file

@ -32,7 +32,7 @@ public:
std::unique_ptr<SocketBase> socket;
SockAddrIn sockaddr_in;
};
virtual ~SocketBase() {}
virtual ~SocketBase() = default;
virtual SocketBase& operator=(const SocketBase&) = delete;
@ -89,11 +89,7 @@ public:
virtual void HandleProxyPacket(const ProxyPacket& packet) = 0;
#if defined(_WIN32)
SOCKET fd = INVALID_SOCKET;
#elif YUZU_UNIX
int fd = -1;
#endif
};
class Socket : public SocketBase {