diff --git a/Core/Util/PortManager.cpp b/Core/Util/PortManager.cpp index d3221242a8..0f6112970d 100644 --- a/Core/Util/PortManager.cpp +++ b/Core/Util/PortManager.cpp @@ -477,6 +477,9 @@ int upnpService(const unsigned int timeout) // Service Loop while (upnpServiceRunning && coreState != CORE_POWERDOWN) { + // Sleep for 1ms for faster response if active, otherwise sleep longer (TODO: Improve on this). + sleep_ms(g_Config.bEnableUPnP ? 1 : 100); + // Attempts to reconnect if not connected yet or got disconnected if (g_Config.bEnableUPnP && g_PortManager.GetInitState() == UPNP_INITSTATE_NONE) { g_PortManager.Initialize(timeout); @@ -506,9 +509,6 @@ int upnpService(const unsigned int timeout) upnpLock.unlock(); } } - - // Sleep for 1ms for faster response - sleep_ms(1); } // Cleaning up regardless of g_Config.bEnableUPnP to prevent lingering open ports on the router