Send correct informations to a http tracker.
[tairent.git] / src / main / ratemeasurer.cpp
blob7a0192f6249004262ec4065ada8552b520bb46da
1 /***************************************************************************
2 * *
3 * Copyright (C) 2006 David Brodsky *
4 * *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License as *
7 * published by the Free Software Foundation and appearing *
8 * in the file LICENSE.GPL included in the packaging of this file. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * General Public License for more details. *
14 * *
15 ***************************************************************************/
17 #include <tairon/net/timer.h>
19 #include "ratemeasurer.h"
21 namespace Tairent
24 namespace Main
27 /* {{{ RateMeasurer::RateMeasurer(double) */
28 RateMeasurer::RateMeasurer(double p) : period(p)
30 lastTime = (double) Tairon::Net::Timer::currentTime() / 1000;
31 startTime = lastTime - 1;
32 rate = 0;
34 /* }}} */
36 /* {{{ RateMeasurer::~RateMeasurer() */
37 RateMeasurer::~RateMeasurer()
40 /* }}} */
42 /* {{{ RateMeasurer::update(unsigned int) */
43 void RateMeasurer::update(unsigned int amount)
45 double t = (double) Tairon::Net::Timer::currentTime() / 1000;
46 rate = ((rate * (lastTime - startTime)) + amount) / (t - startTime);
47 lastTime = t;
48 if (startTime < t - period)
49 startTime = t - period;
51 /* }}} */
53 }; // namespace Main
55 }; // namespace Tairent
57 // vim: ai sw=4 ts=4 noet fdm=marker