mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Abort if wtimer_update is called on an uninitialized timer.
On the other hand, allow wtimer_read on such a timer.
This commit is contained in:
parent
0bd6576cde
commit
cb393a062d
@ -1,3 +1,10 @@
|
||||
2003-11-08 Hrvoje Niksic <hniksic@xemacs.org>
|
||||
|
||||
* utils.c (wtimer_allocate): Bless the use of wtimer_read on a
|
||||
timer that has merely been allocated because get_contents() does
|
||||
that.
|
||||
(wtimer_update): Abort if the timer is not initialized.
|
||||
|
||||
2003-11-08 Hrvoje Niksic <hniksic@xemacs.org>
|
||||
|
||||
* retr.c (get_contents): Pass the timer to limit_bandwidth().
|
||||
|
12
src/utils.c
12
src/utils.c
@ -1318,6 +1318,9 @@ typedef ULARGE_INTEGER wget_sys_time;
|
||||
#endif
|
||||
|
||||
struct wget_timer {
|
||||
/* Whether the start time has been initialized. */
|
||||
int initialized;
|
||||
|
||||
/* The starting point in time which, subtracted from the current
|
||||
time, yields elapsed time. */
|
||||
wget_sys_time start;
|
||||
@ -1331,13 +1334,15 @@ struct wget_timer {
|
||||
double elapsed_pre_start;
|
||||
};
|
||||
|
||||
/* Allocate a timer. It is not legal to do anything with a freshly
|
||||
allocated timer, except call wtimer_reset() or wtimer_delete(). */
|
||||
/* Allocate a timer. Calling wtimer_read on the timer will return
|
||||
zero. It is not legal to call wtimer_update with a freshly
|
||||
allocated timer -- use wtimer_reset first. */
|
||||
|
||||
struct wget_timer *
|
||||
wtimer_allocate (void)
|
||||
{
|
||||
struct wget_timer *wt = xnew (struct wget_timer);
|
||||
xzero (*wt);
|
||||
return wt;
|
||||
}
|
||||
|
||||
@ -1408,6 +1413,7 @@ wtimer_reset (struct wget_timer *wt)
|
||||
wtimer_sys_set (&wt->start);
|
||||
wt->elapsed_last = 0;
|
||||
wt->elapsed_pre_start = 0;
|
||||
wt->initialized = 1;
|
||||
}
|
||||
|
||||
static double
|
||||
@ -1444,6 +1450,8 @@ wtimer_update (struct wget_timer *wt)
|
||||
wget_sys_time now;
|
||||
double elapsed;
|
||||
|
||||
assert (wt->initialized != 0);
|
||||
|
||||
wtimer_sys_set (&now);
|
||||
elapsed = wt->elapsed_pre_start + wtimer_sys_diff (&now, &wt->start);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user