From 5388f35cc4008b4ce7353b532bc938a47c3dc8c9 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Sat, 3 Feb 2024 11:34:00 +0400 Subject: [PATCH] BBA/HLE: Add NetworkRef::Clear method --- Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp | 38 ++++++++++--------------- Source/Core/Core/HW/EXI/BBA/BuiltIn.h | 4 ++- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp b/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp index be77eb6d59..785a67677b 100644 --- a/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp +++ b/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp @@ -91,11 +91,7 @@ bool CEXIETHERNET::BuiltInBBAInterface::Activate() m_router_mac = Common::GenerateMacAddress(Common::MACConsumer::BBA); m_arp_table[m_router_ip] = m_router_mac; - // clear all ref - for (auto& ref : network_ref) - { - ref.ip = 0; - } + network_ref.Clear(); m_upnp_httpd.listen(Common::SSDP_PORT, sf::IpAddress(ip)); m_upnp_httpd.setBlocking(false); @@ -113,16 +109,7 @@ void CEXIETHERNET::BuiltInBBAInterface::Deactivate() m_read_thread_shutdown.Set(); m_active = false; - // kill all active socket - for (auto& ref : network_ref) - { - if (ref.ip != 0) - { - ref.type == IPPROTO_TCP ? ref.tcp_socket.disconnect() : ref.udp_socket.unbind(); - } - ref.ip = 0; - } - + network_ref.Clear(); m_arp_table.clear(); m_upnp_httpd.close(); @@ -778,14 +765,7 @@ void CEXIETHERNET::BuiltInBBAInterface::RecvStart() void CEXIETHERNET::BuiltInBBAInterface::RecvStop() { m_read_enabled.Clear(); - for (auto& net_ref : network_ref) - { - if (net_ref.ip != 0) - { - net_ref.type == IPPROTO_TCP ? net_ref.tcp_socket.disconnect() : net_ref.udp_socket.unbind(); - } - net_ref.ip = 0; - } + network_ref.Clear(); m_queue_read = 0; m_queue_write = 0; } @@ -986,3 +966,15 @@ sf::Socket::Status BbaUdpSocket::Bind(u16 port, u32 net_ip) INFO_LOG_FMT(SP1, "SSDP multicast membership successful"); return sf::Socket::Status::Done; } + +void NetworkRef::Clear() +{ + for (auto& ref : m_stacks) + { + if (ref.ip != 0) + { + ref.type == IPPROTO_TCP ? ref.tcp_socket.disconnect() : ref.udp_socket.unbind(); + } + ref.ip = 0; + } +} diff --git a/Source/Core/Core/HW/EXI/BBA/BuiltIn.h b/Source/Core/Core/HW/EXI/BBA/BuiltIn.h index 3edfbd7840..697c73b8a0 100644 --- a/Source/Core/Core/HW/EXI/BBA/BuiltIn.h +++ b/Source/Core/Core/HW/EXI/BBA/BuiltIn.h @@ -72,7 +72,7 @@ public: struct StackRef { - u32 ip; + u32 ip = 0; u16 local; u16 remote; u16 type; @@ -107,6 +107,8 @@ public: auto end() { return m_stacks.end(); } auto end() const { return m_stacks.cend(); } + void Clear(); + private: StackRefs m_stacks; };