mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-24 15:09:33 -05:00
compliance with win32
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1020 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
881f1395c8
commit
6efc71efd5
@ -1,4 +1,3 @@
|
|||||||
#include <sys/times.h>
|
|
||||||
#include "ftfileprovider.h"
|
#include "ftfileprovider.h"
|
||||||
|
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
@ -7,13 +6,17 @@
|
|||||||
ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string
|
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)
|
hash) : mSize(size), hash(hash), file_name(path), fd(NULL),transfer_rate(0),total_size(0)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_FT_FILE_PROVIDER
|
||||||
std::cout << "Creating file provider for " << hash << std::endl ;
|
std::cout << "Creating file provider for " << hash << std::endl ;
|
||||||
|
#endif
|
||||||
lastTS = time(NULL) ;
|
lastTS = time(NULL) ;
|
||||||
lastTS_t = times(NULL) ;
|
lastTS_t = lastTS ;
|
||||||
}
|
}
|
||||||
|
|
||||||
ftFileProvider::~ftFileProvider(){
|
ftFileProvider::~ftFileProvider(){
|
||||||
|
#ifdef DEBUG_FT_FILE_PROVIDER
|
||||||
std::cout << "Destroying file provider for " << hash << std::endl ;
|
std::cout << "Destroying file provider for " << hash << std::endl ;
|
||||||
|
#endif
|
||||||
if (fd!=NULL) {
|
if (fd!=NULL) {
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
}
|
}
|
||||||
@ -125,16 +128,17 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *da
|
|||||||
* (d) timestamp
|
* (d) timestamp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
long int clk = sysconf(_SC_CLK_TCK) ;
|
time_t now_t = 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
|
long int diff = (long int)now_t - (long int)lastTS_t ; // in bytes/s. Average over multiple samples
|
||||||
|
|
||||||
|
#ifdef DEBUG_FT_FILE_PROVIDER
|
||||||
std::cout << "diff = " << diff << std::endl ;
|
std::cout << "diff = " << diff << std::endl ;
|
||||||
|
#endif
|
||||||
|
|
||||||
if(diff > 200)
|
if(diff > 3)
|
||||||
{
|
{
|
||||||
transfer_rate = total_size / (float)diff * clk ;
|
transfer_rate = total_size / (float)diff ;
|
||||||
#ifdef DEBUG_FT_FILE_PROVIDER
|
#ifdef DEBUG_FT_FILE_PROVIDER
|
||||||
std::cout << "updated TR = " << transfer_rate << ", total_size=" << total_size << std::endl ;
|
std::cout << "updated TR = " << transfer_rate << ", total_size=" << total_size << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
@ -65,8 +65,8 @@ virtual int initializeFileAttrs(); /* does for both */
|
|||||||
std::string lastRequestor;
|
std::string lastRequestor;
|
||||||
uint64_t req_loc;
|
uint64_t req_loc;
|
||||||
uint32_t req_size;
|
uint32_t req_size;
|
||||||
time_t lastTS;
|
time_t lastTS; // used for checking if it's alive
|
||||||
clock_t lastTS_t;
|
time_t lastTS_t; // used for estimating transfer rate.
|
||||||
|
|
||||||
// these two are used for speed estimation
|
// these two are used for speed estimation
|
||||||
float transfer_rate ;
|
float transfer_rate ;
|
||||||
|
Loading…
Reference in New Issue
Block a user