corrected a bug that caused file descriptors to never get closed. Adding some tracing comments.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3958 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-01-08 23:27:33 +00:00
parent dae62c6821
commit c9911694ff
2 changed files with 52 additions and 13 deletions

View File

@ -755,12 +755,21 @@ void ftDataMultiplex::deleteUnusedServers()
for(std::map<std::string, ftFileProvider *>::iterator sit(mServers.begin());sit != mServers.end();)
if(sit->second->purgeOldPeers(now,10))
{
#ifdef SERVER_DEBUG
std::cout << "info.lastTS = " << info.lastTS << ", now=" << now << std::endl ;
#ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::deleteUnusedServers(): provider " << (void*)sit->second << " has no active peers. Removing. Now=" << now << std::endl ;
#endif
// We don't delete servers that are clients at the same time !
if(dynamic_cast<ftFileCreator*>(sit->second) == NULL)
{
#ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::deleteUnusedServers(): deleting file provider " << (void*)sit->second << std::endl ;
#endif
delete sit->second;
}
#ifdef MPLEX_DEBUG
else
std::cerr << "ftDataMultiplex::deleteUnusedServers(): " << (void*)sit->second << " was not deleted because it's also a file creator." << std::endl ;
#endif
std::map<std::string, ftFileProvider *>::iterator tmp(sit);
++tmp ;
@ -823,18 +832,33 @@ bool ftDataMultiplex::handleSearchRequest(const std::string& peerId, const std::
if (mSearch->search(hash, hintflags, info))
{
#ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::handleSearchRequest(";
std::cerr << " Found Local File, sharing...";
std::cerr << std::endl;
#endif
/* setup a new provider */
RsStackMutex stack(dataMtx); /******* LOCK MUTEX ******/
ftFileProvider *provider = new ftFileProvider(info.path, info.size, hash);
// We might already have a file provider, if two requests have got stacked in the request queue. So let's
// check that before.
#ifdef MPLEX_DEBUG
std::cerr << "ftDataMultiplex::handleSearchRequest(";
std::cerr << " Found Local File, sharing...";
#endif
std::map<std::string,ftFileProvider*>::const_iterator it = mServers.find(hash) ;
ftFileProvider *provider ;
if(it == mServers.end())
{
provider = new ftFileProvider(info.path, info.size, hash);
mServers[hash] = provider;
#ifdef MPLEX_DEBUG
std::cerr << " created new file provider " << (void*)provider << std::endl;
#endif
}
else
{
#ifdef MPLEX_DEBUG
std::cerr << " re-using existing file provider " << (void*)it->second << std::endl;
#endif
}
return true;
}

View File

@ -14,7 +14,6 @@
* #define DEBUG_TRANSFERS 1 // TO GET TIMESTAMPS of DATA READING
********/
#ifdef DEBUG_TRANSFERS
#include "util/rsprint.h"
#include <iomanip>
@ -34,13 +33,17 @@ ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string hash
#endif
}
ftFileProvider::~ftFileProvider(){
ftFileProvider::~ftFileProvider()
{
#ifdef DEBUG_FT_FILE_PROVIDER
std::cout << "Destroying file provider for " << hash << std::endl ;
std::cout << "ftFileProvider::~ftFileProvider(): Destroying file provider for " << hash << std::endl ;
#endif
if (fd!=NULL) {
fclose(fd);
fd = NULL ;
#ifdef DEBUG_FT_FILE_PROVIDER
std::cout << "ftFileProvider::~ftFileProvider(): closed file: " << hash << std::endl ;
#endif
}
}
@ -102,10 +105,16 @@ bool ftFileProvider::purgeOldPeers(time_t now,uint32_t max_duration)
{
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
#ifdef DEBUG_FT_FILE_PROVIDER
std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": examining peers." << std::endl ;
#endif
bool ret = true ;
for(std::map<std::string,PeerUploadInfo>::iterator it(uploading_peers.begin());it!=uploading_peers.end();)
if( (*it).second.lastTS+max_duration < (uint32_t)now)
{
#ifdef DEBUG_FT_FILE_PROVIDER
std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": peer " << it->first << " is too old. Removing." << std::endl ;
#endif
std::map<std::string,PeerUploadInfo>::iterator tmp = it ;
++tmp ;
uploading_peers.erase(it) ;
@ -113,6 +122,9 @@ bool ftFileProvider::purgeOldPeers(time_t now,uint32_t max_duration)
}
else
{
#ifdef DEBUG_FT_FILE_PROVIDER
std::cerr << "ftFileProvider::purgeOldPeers(): " << (void*)this << ": peer " << it->first << " will be kept." << std::endl ;
#endif
ret = false ;
++it ;
}
@ -320,6 +332,9 @@ int ftFileProvider::initializeFileAttrs()
return 0;
}
}
#ifdef DEBUG_FT_FILE_PROVIDER
std::cerr << "ftFileProvider:: openned file " << file_name << std::endl ;
#endif
return 1;
}