diff --git a/Core/Util/PortManager.cpp b/Core/Util/PortManager.cpp index e8af73682565..2e70d892331f 100644 --- a/Core/Util/PortManager.cpp +++ b/Core/Util/PortManager.cpp @@ -54,16 +54,16 @@ PortManager::PortManager(): m_InitState(UPNP_INITSTATE_NONE), m_LocalPort(UPNP_LOCAL_PORT_ANY), m_leaseDuration("43200") { - // Since WSAStartup can be used multiple times it should be safe to do this right? - net::Init(); } PortManager::~PortManager() { // FIXME: On Windows it seems using any UPnP functions in this destructor that gets triggered when exiting PPSSPP will resulting to UPNPCOMMAND_HTTP_ERROR due to early WSACleanup (miniupnpc was getting WSANOTINITIALISED internally) +} + +void PortManager::Shutdown() { Clear(); Restore(); Terminate(); - net::Shutdown(); } void PortManager::Terminate() { @@ -502,9 +502,7 @@ int upnpService(const unsigned int timeout) // Cleaning up regardless of g_Config.bEnableUPnP to prevent lingering open ports on the router if (g_PortManager.GetInitState() == UPNP_INITSTATE_DONE) { - g_PortManager.Clear(); - g_PortManager.Restore(); - g_PortManager.Terminate(); + g_PortManager.Shutdown(); } // Should we ingore any leftover UPnP requests? instead of processing it on the next game start diff --git a/Core/Util/PortManager.h b/Core/Util/PortManager.h index 67f99a8fc58a..f284788a38f0 100644 --- a/Core/Util/PortManager.h +++ b/Core/Util/PortManager.h @@ -83,9 +83,6 @@ class PortManager { // timeout: milliseconds to wait for a router to respond (default = 2000 ms) bool Initialize(const unsigned int timeout = 2000); - // Uninitialize/Reset the state - void Terminate(); - // Get UPnP Initialization status int GetInitState(); @@ -95,16 +92,22 @@ class PortManager { // Remove a port mapping (external port) bool Remove(const char* protocol, unsigned short port); + // Call on exit. Does a full shutdown. + void Shutdown(); + +private: + // Retrieves port lists mapped by PPSSPP for current LAN IP & other's applications + bool RefreshPortList(); + // Removes any lingering mapped ports created by PPSSPP (including from previous crashes) bool Clear(); // Restore ports mapped by others that were taken by PPSSPP, better used after Clear() bool Restore(); - // Retrieves port lists mapped by PPSSPP for current LAN IP & other's applications - bool RefreshPortList(); + // Uninitialize/Reset the state + void Terminate(); -protected: struct UPNPUrls* urls = NULL; struct IGDdatas* datas = NULL; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 9b4c6ba3e4cb..c06aa59fa9f4 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -103,6 +103,7 @@ #include "Core/HLE/proAdhoc.h" #include "Core/HW/MemoryStick.h" #include "Core/Util/GameManager.h" +#include "Core/Util/PortManager.h" #include "Core/Util/AudioFormat.h" #include "Core/WebServer.h" #include "Core/TiltEventProcessor.h" @@ -1409,6 +1410,8 @@ void NativeShutdown() { System_ExitApp(); #endif + g_PortManager.Shutdown(); + net::Shutdown(); g_Discord.Shutdown();