mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-17 10:59:38 -04:00
Corrected potential mutex lock problem
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1130 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
33146cc7dc
commit
1aaf6f5c27
1 changed files with 16 additions and 10 deletions
|
@ -14,8 +14,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#define EXTADDRSEARCH_DEBUG
|
|
||||||
|
|
||||||
static const std::string ADDR_AGENT = "Mozilla/5.0";
|
static const std::string ADDR_AGENT = "Mozilla/5.0";
|
||||||
|
|
||||||
static std::string scan_ip(const std::string& text)
|
static std::string scan_ip(const std::string& text)
|
||||||
|
@ -180,8 +178,6 @@ bool ExtAddrFinder::hasValidIP(struct sockaddr_in *addr)
|
||||||
#ifdef EXTADDRSEARCH_DEBUG
|
#ifdef EXTADDRSEARCH_DEBUG
|
||||||
std::cerr << "ExtAddrFinder: Getting ip." << std::endl ;
|
std::cerr << "ExtAddrFinder: Getting ip." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
RsStackMutex mut(_addrMtx) ;
|
|
||||||
|
|
||||||
if(*_found)
|
if(*_found)
|
||||||
{
|
{
|
||||||
#ifdef EXTADDRSEARCH_DEBUG
|
#ifdef EXTADDRSEARCH_DEBUG
|
||||||
|
@ -191,14 +187,26 @@ bool ExtAddrFinder::hasValidIP(struct sockaddr_in *addr)
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!*_searching)
|
if(_addrMtx.trylock())
|
||||||
{
|
{
|
||||||
|
if(!*_searching)
|
||||||
|
{
|
||||||
#ifdef EXTADDRSEARCH_DEBUG
|
#ifdef EXTADDRSEARCH_DEBUG
|
||||||
std::cerr << "ExtAddrFinder: No stored ip: Initiating new search." << std::endl ;
|
std::cerr << "ExtAddrFinder: No stored ip: Initiating new search." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
*_searching = true ;
|
*_searching = true ;
|
||||||
start_request() ;
|
start_request() ;
|
||||||
|
}
|
||||||
|
#ifdef EXTADDRSEARCH_DEBUG
|
||||||
|
else
|
||||||
|
std::cerr << "ExtAddrFinder: Already searching." << std::endl ;
|
||||||
|
#endif
|
||||||
|
_addrMtx.unlock();
|
||||||
}
|
}
|
||||||
|
#ifdef EXTADDRSEARCH_DEBUG
|
||||||
|
else
|
||||||
|
std::cerr << "ExtAddrFinder: (Note) Could not acquire lock. Busy." << std::endl ;
|
||||||
|
#endif
|
||||||
|
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
@ -241,7 +249,5 @@ ExtAddrFinder::ExtAddrFinder()
|
||||||
_ip_servers.push_back(std::string( "www.showmyip.com" )) ;
|
_ip_servers.push_back(std::string( "www.showmyip.com" )) ;
|
||||||
_ip_servers.push_back(std::string( "showip.net" )) ;
|
_ip_servers.push_back(std::string( "showip.net" )) ;
|
||||||
_ip_servers.push_back(std::string( "www.displaymyip.com")) ;
|
_ip_servers.push_back(std::string( "www.displaymyip.com")) ;
|
||||||
|
|
||||||
start_request() ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue