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