From 6efc71efd57fe5ed1026297b0834b258f938f111 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 8 Feb 2009 13:04:32 +0000 Subject: [PATCH] compliance with win32 git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1020 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/ft/ftfileprovider.cc | 16 ++++++++++------ libretroshare/src/ft/ftfileprovider.h | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libretroshare/src/ft/ftfileprovider.cc b/libretroshare/src/ft/ftfileprovider.cc index 217a99ec1..1f9bcff65 100644 --- a/libretroshare/src/ft/ftfileprovider.cc +++ b/libretroshare/src/ft/ftfileprovider.cc @@ -1,4 +1,3 @@ -#include #include "ftfileprovider.h" #include "util/rsdir.h" @@ -7,13 +6,17 @@ 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) { +#ifdef DEBUG_FT_FILE_PROVIDER std::cout << "Creating file provider for " << hash << std::endl ; +#endif lastTS = time(NULL) ; - lastTS_t = times(NULL) ; + lastTS_t = lastTS ; } ftFileProvider::~ftFileProvider(){ +#ifdef DEBUG_FT_FILE_PROVIDER std::cout << "Destroying file provider for " << hash << std::endl ; +#endif if (fd!=NULL) { fclose(fd); } @@ -125,16 +128,17 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *da * (d) timestamp */ - long int clk = sysconf(_SC_CLK_TCK) ; - clock_t now_t = times(NULL) ; + time_t now_t = time(NULL) ; 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 ; +#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 std::cout << "updated TR = " << transfer_rate << ", total_size=" << total_size << std::endl ; #endif diff --git a/libretroshare/src/ft/ftfileprovider.h b/libretroshare/src/ft/ftfileprovider.h index 2b982e5b7..ab14664f8 100644 --- a/libretroshare/src/ft/ftfileprovider.h +++ b/libretroshare/src/ft/ftfileprovider.h @@ -65,8 +65,8 @@ virtual int initializeFileAttrs(); /* does for both */ std::string lastRequestor; uint64_t req_loc; uint32_t req_size; - time_t lastTS; - clock_t lastTS_t; + time_t lastTS; // used for checking if it's alive + time_t lastTS_t; // used for estimating transfer rate. // these two are used for speed estimation float transfer_rate ;