/* */ #ifndef _D_SPEED_CALC_H_ #define _D_SPEED_CALC_H_ #include "common.h" #include "TimeA2.h" namespace aria2 { class SpeedCalc { private: uint64_t lengthArray[2]; int sw; Time cpArray[2]; unsigned int maxSpeed; unsigned int prevSpeed; Time start; uint64_t accumulatedLength; time_t nextInterval; bool isIntervalOver() const; bool isIntervalOver(int64_t milliElapsed) const; void changeSw(); public: SpeedCalc() { reset(); } ~SpeedCalc() {} /** * Returns download/upload speed in byte per sec */ unsigned int calculateSpeed(); unsigned int calculateSpeed(const struct timeval& now); unsigned int getMaxSpeed() const { return maxSpeed; } unsigned int calculateAvgSpeed() const; void update(size_t bytes); void reset(); }; } // namespace aria2 #endif // _D_SPEED_CALC_H_