transfer speed measurement

svn path=/trunk/boinc/; revision=961
This commit is contained in:
Eric Heien 2003-02-24 23:59:46 +00:00
parent 81eab5e801
commit 8975310ada
2 changed files with 23 additions and 0 deletions

View File

@ -20,6 +20,7 @@
#include "windows_cpp.h"
#include <stdio.h>
#include <math.h>
#ifdef _WIN32
#include <afxwin.h>
@ -171,6 +172,8 @@ void NET_XFER::init(char* host, int p, int b) {
strcpy(hostname, host);
port = p;
blocksize = b;
xfer_speed = 0;
last_speed_update = 0;
}
// Insert a NET_XFER object into the set
@ -314,6 +317,7 @@ int NET_XFER_SET::do_select(
retval = nxp->do_xfer(n);
max_bytes -= n;
bytes_transferred += n;
nxp->update_speed(n);
}
} else {
nxp->io_ready = true;
@ -415,6 +419,22 @@ done:
return 0;
}
// Update the transfer speed for this NET_XFER
// Decay speed by 1/e every second
//
void NET_XFER::update_speed(int nbytes) {
clock_t now,delta_t;
double x;
now = clock();
if (last_speed_update==0) last_speed_update = now;
delta_t = now-last_speed_update;
if (delta_t<=0) delta_t = 0;
x = exp(-(double)delta_t/(double)CLOCKS_PER_SEC);
xfer_speed = (x*xfer_speed)+nbytes;
last_speed_update = now;
}
void NET_XFER::got_error() {
error = ERR_IO;
io_done = true;

View File

@ -49,12 +49,15 @@ public:
char hostname[256];
int port;
int blocksize;
double xfer_speed; // in bytes per second
clock_t last_speed_update;
void init(char* host, int port, int blocksize);
int get_ip_addr(char *hostname, int &ip_addr);
int open_server();
void close_socket();
int do_xfer(int&);
void update_speed(int);
void got_error();
};