void UPnP::CloseMapping () { const auto& a = context.GetRouterInfo().GetAddresses(); for (const auto& address : a) { if (!address->host.is_v6 ()) CloseMapping (address); } }
void UPnP::Stop () { if (m_IsRunning) { LogPrint(eLogInfo, "UPnP: stopping"); m_IsRunning = false; m_Timer.cancel (); m_Service.stop (); if (m_Thread) { m_Thread->join (); m_Thread.reset (nullptr); } CloseMapping (); Close (); } }
void UPnP::TryPortMapping (int type, int port) { std::string strType, strPort (std::to_string (port)); switch (type) { case I2P_UPNP_TCP: strType = "TCP"; break; case I2P_UPNP_UDP: default: strType = "UDP"; } int r; std::string strDesc = "I2Pd"; try { for (;;) { #ifndef UPNPDISCOVER_SUCCESS /* miniupnpc 1.5 */ r = UPNP_AddPortMappingFunc (m_upnpUrls.controlURL, m_upnpData.first.servicetype, strPort.c_str (), strPort.c_str (), m_NetworkAddr, strDesc.c_str (), strType.c_str (), 0); #else /* miniupnpc 1.6 */ r = UPNP_AddPortMappingFunc (m_upnpUrls.controlURL, m_upnpData.first.servicetype, strPort.c_str (), strPort.c_str (), m_NetworkAddr, strDesc.c_str (), strType.c_str (), 0, "0"); #endif if (r!=UPNPCOMMAND_SUCCESS) { LogPrint (eLogError, "UPnP: AddPortMapping (", strPort.c_str () ,", ", strPort.c_str () ,", ", m_NetworkAddr, ") failed with code ", r); return; } else { LogPrint (eLogDebug, "UPnP: Port Mapping successful. (", m_NetworkAddr ,":", strPort.c_str(), " type ", strType.c_str () ," -> ", m_externalIPAddress ,":", strPort.c_str() ,")"); return; } std::this_thread::sleep_for(std::chrono::minutes(20)); // c++11 //boost::this_thread::sleep_for(); // pre c++11 //sleep(20*60); // non-portable } } catch (boost::thread_interrupted) { CloseMapping(type, port); Close(); throw; } }
CSharedMemory::~CSharedMemory() { CloseMapping(); }
void CSharedMemory::OpenFileMapping(const TCHAR* pName) { CloseMapping(); m_hMemory = ::OpenFileMapping(FILE_MAP_WRITE, false, pName); }