/* */ #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