implemented a short circuit to local cache transfers. This saves a large number of file descriptors, and improves reactivity of the software

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2876 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-05-09 13:52:05 +00:00
parent 20908b2c48
commit c87844277a
2 changed files with 42 additions and 13 deletions

View File

@ -609,7 +609,24 @@ bool ftController::moveFile(const std::string& source,const std::string& dest)
#endif #endif
// We could not rename, probably because we're dealing with different file systems. // We could not rename, probably because we're dealing with different file systems.
// Let's copy then. // Let's copy then.
if(!copyFile(source,dest))
return false ;
// copy was successfull, let's delete the original
std::cerr << "deleting original file " << source << std::endl ;
if(0 == remove(source.c_str()))
return true ;
else
{
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File erase error", "Error while removing hash file " + dest + "\nRead-only file system ?");
return false ;
}
}
bool ftController::copyFile(const std::string& source,const std::string& dest)
{
std::string error ; std::string error ;
static const int BUFF_SIZE = 10485760 ; // 10 MB buffer to speed things up. static const int BUFF_SIZE = 10485760 ; // 10 MB buffer to speed things up.
@ -648,21 +665,13 @@ bool ftController::moveFile(const std::string& source,const std::string& dest)
fclose(in) ; fclose(in) ;
fclose(out) ; fclose(out) ;
// copy was successfull, let's delete the original
std::cerr << "deleting original file " << source << std::endl ;
free(buffer) ; free(buffer) ;
if(0 == remove(source.c_str())) return true ;
return true ;
else
{
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File erase error", "Error while removing hash file " + dest + "\nRead-only file system ?");
return false ;
}
} }
bool ftController::completeFile(std::string hash) bool ftController::completeFile(std::string hash)
{ {
/* variables... so we can drop mutex later */ /* variables... so we can drop mutex later */
@ -1709,15 +1718,34 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size) bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
{ {
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
std::cerr << "ftController::RequestCacheFile(" << id << ","; std::cerr << "ftController::RequestCacheFile(" << id << ",";
std::cerr << path << "," << hash << "," << size << ")"; std::cerr << path << "," << hash << "," << size << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* Request File */ /* Request File */
std::list<std::string> ids; std::list<std::string> ids;
ids.push_back(id); ids.push_back(id);
FileInfo info ;
if(mSearch->search(hash, RS_FILE_HINTS_CACHE, info))
{
#ifdef CONTROL_DEBUG
std::cerr << "I already have this file:" << std::endl ;
std::cerr << " path: " << info.path << std::endl ;
std::cerr << " fname: " << info.fname << std::endl ;
std::cerr << " hash: " << info.hash << std::endl ;
std::cerr << "Copying it !!" << std::endl ;
#endif
if(copyFile(info.path,path+"/"+hash))
{
CompletedCache(hash);
return true ;
}
}
FileRequest(hash, hash, size, path, RS_FILE_HINTS_CACHE | RS_FILE_HINTS_NO_SEARCH, ids); FileRequest(hash, hash, size, path, RS_FILE_HINTS_CACHE | RS_FILE_HINTS_NO_SEARCH, ids);
return true; return true;

View File

@ -175,6 +175,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
bool FileDetails(std::string hash, FileInfo &info); bool FileDetails(std::string hash, FileInfo &info);
bool moveFile(const std::string& source,const std::string& dest) ; bool moveFile(const std::string& source,const std::string& dest) ;
bool copyFile(const std::string& source,const std::string& dest) ;
/***************************************************************/ /***************************************************************/
/********************** Cache Transfer *************************/ /********************** Cache Transfer *************************/