Artifact a9cb283e4e005e26ff1d4e9d86f2671f7646e9935623f29625e42b0c620b17ce:
- File
utils/ofhttp/ProgressBar.h
— part of check-in
[30e8df31a0]
at
2020-08-10 20:55:21
on branch trunk
— ofhttp: Average the speed over the last 10 seconds
This avoids the speed and hence also the ETA jumping like crazy on a
flaky connection. (user: js, size: 1181) [annotate] [blame] [check-ins using]
/* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018, 2019, 2020 * Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" @class OFDate; @class OFTimer; #define BPS_WINDOW_SIZE 10 @interface ProgressBar: OFObject { intmax_t _received, _lastReceived, _length, _resumedFrom; OFDate *_startDate, *_lastReceivedDate; OFTimer *_drawTimer, *_BPSTimer; bool _stopped; float _BPS; double _ETA; float _BPSWindow[BPS_WINDOW_SIZE]; size_t _BPSWindowIndex, _BPSWindowLength; } - (instancetype)initWithLength: (intmax_t)length resumedFrom: (intmax_t)resumedFrom; - (void)setReceived: (intmax_t)received; - (void)draw; - (void)calculateBPSAndETA; - (void)stop; @end