diff --git a/Core/HLE/sceNet.cpp b/Core/HLE/sceNet.cpp index 85077c1afa..2af5ff7f03 100644 --- a/Core/HLE/sceNet.cpp +++ b/Core/HLE/sceNet.cpp @@ -149,7 +149,7 @@ void __NetShutdown() { __ResetInitNetLib(); - // Since PortManager supposed to be general purpose for whatever port forwarding PPSSPP needed, may be we shouldn't clear & restore ports in here? But currently there is an issue with UPnP functions used in PortManager's destructor :( + // Since PortManager supposed to be general purpose for whatever port forwarding PPSSPP needed, may be we shouldn't clear & restore ports in here? it will be cleared and restored by PortManager's destructor when exiting PPSSPP anyway if (g_PortManager.GetInitState() == UPNP_INITSTATE_DONE) { g_PortManager.Clear(); g_PortManager.Restore(); diff --git a/Core/Util/PortManager.cpp b/Core/Util/PortManager.cpp index 0ba1f2a83b..34819be5bc 100644 --- a/Core/Util/PortManager.cpp +++ b/Core/Util/PortManager.cpp @@ -33,6 +33,7 @@ #include "Core/Util/PortManager.h" #include #include "i18n/i18n.h" +#include "net/resolve.h" PortManager g_PortManager; @@ -43,16 +44,20 @@ 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: It seems using any UPnP functions in this destructor that gets triggered when exiting PPSSPP will resulting to UPNPCOMMAND_HTTP_ERROR :( Did miniUPnPc library already shutted down at this point? + // 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) Clear(); Restore(); Terminate(); + net::Shutdown(); } void PortManager::Terminate() { + INFO_LOG(SCENET, "PortManager::Terminate()"); if (urls) { FreeUPNPUrls(urls); free(urls); @@ -83,9 +88,9 @@ bool PortManager::Initialize(const unsigned int timeout) { unsigned char ttl = 2; // defaulting to 2 int error = 0; - INFO_LOG(SCENET, "PortManager::Init(%d)", timeout); + INFO_LOG(SCENET, "PortManager::Initialize(%d)", timeout); if (!g_Config.bEnableUPnP) { - ERROR_LOG(SCENET, "PortManager::Init - UPnP is Disabled on Networking Settings"); + ERROR_LOG(SCENET, "PortManager::Initialize - UPnP is Disabled on Networking Settings"); return false; }