diff options
| author | Leo Lam <leolino.lam@gmail.com> | 2017-08-10 14:41:50 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-10 14:41:50 +0800 |
| commit | 15e46cb216f83fadac1fec0d87f461139bce227d (patch) | |
| tree | 64d108f4e0dc4c9b329e580a8c422be7772b4823 /Source | |
| parent | 13b0ba3f55a9fae13d87ee166f7cc4c23721d6d5 (diff) | |
| parent | 9e81fec81603d18290cdef170f4749cdd0188b16 (diff) | |
Merge pull request #5900 from ligfx/fixupnpinit
Fix UPnP init
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/Core/Core/NetPlayServer.cpp | 18 | ||||
| -rw-r--r-- | Source/Core/Core/NetPlayServer.h | 2 |
2 files changed, 8 insertions, 12 deletions
diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index f7c4f401c8..5eaddab1e2 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -943,8 +943,6 @@ struct UPNPUrls NetPlayServer::m_upnp_urls; struct IGDdatas NetPlayServer::m_upnp_data; std::string NetPlayServer::m_upnp_ourip; u16 NetPlayServer::m_upnp_mapped = 0; -bool NetPlayServer::m_upnp_inited = false; -bool NetPlayServer::m_upnp_error = false; std::thread NetPlayServer::m_upnp_thread; // called from ---GUI--- thread @@ -958,10 +956,7 @@ void NetPlayServer::TryPortmapping(u16 port) // UPnP thread: try to map a port void NetPlayServer::mapPortThread(const u16 port) { - if (!m_upnp_inited) - initUPnP(); - - if (m_upnp_inited && UPnPMapPort(m_upnp_ourip, port)) + if (initUPnP() && UPnPMapPort(m_upnp_ourip, port)) { NOTICE_LOG(NETPLAY, "Successfully mapped port %d to %s.", port, m_upnp_ourip.c_str()); return; @@ -981,16 +976,19 @@ void NetPlayServer::unmapPortThread() // discovers the IGD bool NetPlayServer::initUPnP() { + static bool s_inited = false; + static bool s_error = false; + std::vector<UPNPDev*> igds; int descXMLsize = 0, upnperror = 0; char cIP[20]; // Don't init if already inited - if (m_upnp_inited) + if (s_inited) return true; // Don't init if it failed before - if (m_upnp_error) + if (s_error) return false; memset(&m_upnp_urls, 0, sizeof(UPNPUrls)); @@ -1007,8 +1005,7 @@ bool NetPlayServer::initUPnP() { WARN_LOG(NETPLAY, "An error occurred trying to discover UPnP devices."); - m_upnp_error = true; - m_upnp_inited = false; + s_error = true; return false; } @@ -1047,6 +1044,7 @@ bool NetPlayServer::initUPnP() } } + s_inited = true; return true; } diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index e741990800..a4adacdcba 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -136,8 +136,6 @@ private: static struct IGDdatas m_upnp_data; static std::string m_upnp_ourip; static u16 m_upnp_mapped; - static bool m_upnp_inited; - static bool m_upnp_error; static std::thread m_upnp_thread; #endif }; |
