mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-18 20:34:26 -05:00
small fix to upload transfer rates
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1017 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
99959b261f
commit
896fc45a22
@ -7,10 +7,13 @@
|
||||
ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string
|
||||
hash) : mSize(size), hash(hash), file_name(path), fd(NULL),transfer_rate(0),total_size(0)
|
||||
{
|
||||
std::cout << "Creating file provider for " << hash << std::endl ;
|
||||
lastTS = time(NULL) ;
|
||||
lastTS_t = times(NULL) ;
|
||||
}
|
||||
|
||||
ftFileProvider::~ftFileProvider(){
|
||||
std::cout << "Destroying file provider for " << hash << std::endl ;
|
||||
if (fd!=NULL) {
|
||||
fclose(fd);
|
||||
}
|
||||
@ -57,20 +60,6 @@ bool ftFileProvider::FileDetails(FileInfo &info)
|
||||
inf.peerId = lastRequestor ;
|
||||
inf.status = FT_STATE_DOWNLOADING ;
|
||||
|
||||
long int clk = sysconf(_SC_CLK_TCK) ;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
clock_t now_t = times(NULL) ;
|
||||
|
||||
long int diff = (long int)now_t - (long int)lastTS_t ; // in bytes/s. Average over multiple samples
|
||||
|
||||
if(diff > 100)
|
||||
{
|
||||
transfer_rate = total_size / (float)diff * clk ;
|
||||
total_size = 0 ;
|
||||
lastTS_t = now_t ;
|
||||
}
|
||||
|
||||
inf.tfRate = transfer_rate/1024.0 ;
|
||||
info.tfRate = transfer_rate/1024.0 ;
|
||||
info.peers.push_back(inf) ;
|
||||
@ -92,10 +81,6 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *da
|
||||
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
/*
|
||||
* Use private data, which has a pointer to file, total size etc
|
||||
*/
|
||||
|
||||
/*
|
||||
* FIXME: Warning of comparison between unsigned and signed int?
|
||||
*/
|
||||
@ -140,9 +125,25 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *da
|
||||
* (d) timestamp
|
||||
*/
|
||||
|
||||
time_t now = time(NULL);
|
||||
long int clk = sysconf(_SC_CLK_TCK) ;
|
||||
clock_t now_t = times(NULL) ;
|
||||
|
||||
long int diff = (long int)now_t - (long int)lastTS_t ; // in bytes/s. Average over multiple samples
|
||||
|
||||
std::cout << "diff = " << diff << std::endl ;
|
||||
|
||||
if(diff > 200)
|
||||
{
|
||||
transfer_rate = total_size / (float)diff * clk ;
|
||||
#ifdef DEBUG_FT_FILE_PROVIDER
|
||||
std::cout << "updated TR = " << transfer_rate << ", total_size=" << total_size << std::endl ;
|
||||
#endif
|
||||
lastTS_t = now_t ;
|
||||
total_size = 0 ;
|
||||
}
|
||||
|
||||
req_loc = offset;
|
||||
lastTS = now ;
|
||||
lastTS = time(NULL) ;
|
||||
req_size = data_size;
|
||||
total_size += req_size ;
|
||||
}
|
||||
|
@ -193,8 +193,11 @@ void ftServer::run()
|
||||
{
|
||||
if (FileDetails(sit->first,RS_FILE_HINTS_UPLOAD,info))
|
||||
{
|
||||
if ((now - info.lastTS) > 5)
|
||||
if ((now - info.lastTS) > 10)
|
||||
{
|
||||
#ifdef SERVER_DEBUG
|
||||
std::cout << "info.lastTS = " << info.lastTS << ", now=" << now << std::endl ;
|
||||
#endif
|
||||
toDels.push_back(sit->first);
|
||||
}
|
||||
}
|
||||
@ -204,9 +207,13 @@ void ftServer::run()
|
||||
for (it = toDels.begin();it != toDels.end(); it++)
|
||||
{
|
||||
sit = mFtDataplex->mServers.find(*it);
|
||||
|
||||
if(mFtDataplex->mServers.end() != sit)
|
||||
{
|
||||
delete sit->second;
|
||||
mFtDataplex->mServers.erase(sit);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
Sleep(1000);
|
||||
@ -229,6 +236,7 @@ void ftServer::run()
|
||||
bool ftServer::FileRequest(std::string fname, std::string hash, uint64_t size,
|
||||
std::string dest, uint32_t flags, std::list<std::string> srcIds)
|
||||
{
|
||||
std::cerr << "Requesting " << fname << std::endl ;
|
||||
return mFtController->FileRequest(fname, hash, size,
|
||||
dest, flags, srcIds);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user