From 6d41088153b4b932b4f2524d4252993a5642f998 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Mon, 1 Aug 2022 22:47:39 +0200 Subject: core, yuzu: Address first part of review comments --- src/core/announce_multiplayer_session.cpp | 6 +++--- src/core/hle/service/nifm/nifm.cpp | 1 + src/core/internal_network/network.cpp | 8 ++++---- src/core/internal_network/socket_proxy.cpp | 10 +++++----- src/core/internal_network/socket_proxy.h | 3 ++- src/core/internal_network/sockets.h | 6 +----- 6 files changed, 16 insertions(+), 18 deletions(-) (limited to 'src/core') diff --git a/src/core/announce_multiplayer_session.cpp b/src/core/announce_multiplayer_session.cpp index d73a488cf..6737ce85a 100644 --- a/src/core/announce_multiplayer_session.cpp +++ b/src/core/announce_multiplayer_session.cpp @@ -31,7 +31,7 @@ AnnounceMultiplayerSession::AnnounceMultiplayerSession(Network::RoomNetwork& roo } WebService::WebResult AnnounceMultiplayerSession::Register() { - std::shared_ptr room = room_network.GetRoom().lock(); + auto room = room_network.GetRoom().lock(); if (!room) { return WebService::WebResult{WebService::WebResult::Code::LibError, "Network is not initialized", ""}; @@ -102,7 +102,7 @@ void AnnounceMultiplayerSession::UpdateBackendData(std::shared_ptr lock(callback_mutex); + std::lock_guard lock(callback_mutex); for (auto callback : error_callbacks) { (*callback)(result); } @@ -120,7 +120,7 @@ void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() { std::future future; while (!shutdown_event.WaitUntil(update_time)) { update_time += announce_time_interval; - std::shared_ptr room = room_network.GetRoom().lock(); + auto room = room_network.GetRoom().lock(); if (!room) { break; } diff --git a/src/core/hle/service/nifm/nifm.cpp b/src/core/hle/service/nifm/nifm.cpp index 42ed17187..e3ef06481 100644 --- a/src/core/hle/service/nifm/nifm.cpp +++ b/src/core/hle/service/nifm/nifm.cpp @@ -381,6 +381,7 @@ void IGeneralService::GetCurrentIpAddress(Kernel::HLERequestContext& ctx) { rb.Push(ResultSuccess); rb.PushRaw(*ipv4); } + void IGeneralService::CreateTemporaryNetworkProfile(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_NIFM, "called"); diff --git a/src/core/internal_network/network.cpp b/src/core/internal_network/network.cpp index 160cc83e4..3b6906f7d 100644 --- a/src/core/internal_network/network.cpp +++ b/src/core/internal_network/network.cpp @@ -352,8 +352,8 @@ std::optional GetHostIPv4Address() { return {}; } - char ip_addr[16] = {}; - ASSERT(inet_ntop(AF_INET, &interface->ip_address, ip_addr, sizeof(ip_addr)) != nullptr); + std::array 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 -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(&value), sizeof(value)); + setsockopt(fd_, SOL_SOCKET, option, reinterpret_cast(&value), sizeof(value)); if (result != SOCKET_ERROR) { return Errno::SUCCESS; } diff --git a/src/core/internal_network/socket_proxy.cpp b/src/core/internal_network/socket_proxy.cpp index b9c50430e..216893ba1 100644 --- a/src/core/internal_network/socket_proxy.cpp +++ b/src/core/internal_network/socket_proxy.cpp @@ -30,19 +30,19 @@ void ProxySocket::HandleProxyPacket(const ProxyPacket& packet) { closed) { return; } - std::lock_guard guard(packets_mutex); + std::lock_guard guard(packets_mutex); received_packets.push(packet); } template -Errno ProxySocket::SetSockOpt(SOCKET _fd, int option, T value) { +Errno ProxySocket::SetSockOpt(SOCKET fd_, int option, T value) { socket_options[option] = reinterpret_cast(&value); return Errno::SUCCESS; } Errno ProxySocket::Initialize(Domain domain, Type type, Protocol socket_protocol) { protocol = socket_protocol; - socket_options[0x1008] = reinterpret_cast(&type); + SetSockOpt(fd, SO_TYPE, type); return Errno::SUCCESS; } @@ -101,7 +101,7 @@ std::pair ProxySocket::RecvFrom(int flags, std::vector& message, ASSERT(message.size() < static_cast(std::numeric_limits::max())); { - std::lock_guard 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 ProxySocket::RecvFrom(int flags, std::vector& message, return {-1, Errno::AGAIN}; } - std::lock_guard guard(packets_mutex); + std::lock_guard guard(packets_mutex); if (received_packets.size() > 0) { return ReceivePacket(flags, message, addr, message.size()); } diff --git a/src/core/internal_network/socket_proxy.h b/src/core/internal_network/socket_proxy.h index c9155f1af..ad917cac3 100644 --- a/src/core/internal_network/socket_proxy.h +++ b/src/core/internal_network/socket_proxy.h @@ -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; diff --git a/src/core/internal_network/sockets.h b/src/core/internal_network/sockets.h index 92dc49993..a70429b19 100644 --- a/src/core/internal_network/sockets.h +++ b/src/core/internal_network/sockets.h @@ -32,7 +32,7 @@ public: std::unique_ptr 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 { -- cgit v1.2.3