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:
csoler 2009-02-06 20:42:01 +00:00
parent 99959b261f
commit 896fc45a22
2 changed files with 32 additions and 23 deletions

View file

@ -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 ;
}