|
Lines 120-125
Link Here
|
| 120 |
: timeout(_timeout) |
120 |
: timeout(_timeout) |
| 121 |
, reached(false) |
121 |
, reached(false) |
| 122 |
, report(_report) |
122 |
, report(_report) |
|
|
123 |
, drate_period(-1) |
| 124 |
, dload_period(0) |
| 125 |
, secs(0) |
| 126 |
, drate_avg(-1) |
| 123 |
, ltime( time(NULL)) |
127 |
, ltime( time(NULL)) |
| 124 |
, dload( 0) |
128 |
, dload( 0) |
| 125 |
, uload( 0) |
129 |
, uload( 0) |
|
Lines 128-135
Link Here
|
| 128 |
long timeout; |
132 |
long timeout; |
| 129 |
bool reached; |
133 |
bool reached; |
| 130 |
callback::SendReport<DownloadProgressReport> *report; |
134 |
callback::SendReport<DownloadProgressReport> *report; |
|
|
135 |
// download rate of the last period (cca 1 sec) |
| 136 |
double drate_period; |
| 137 |
// bytes downloaded at the start of the last period |
| 138 |
double dload_period; |
| 139 |
// seconds from the start of the download |
| 140 |
long secs; |
| 141 |
// average download rate |
| 142 |
double drate_avg; |
| 143 |
// last time the progress was reported |
| 131 |
time_t ltime; |
144 |
time_t ltime; |
|
|
145 |
// bytes downloaded at the moment the progress was last reported |
| 132 |
double dload; |
146 |
double dload; |
|
|
147 |
// bytes uploaded at the moment the progress was last reported |
| 133 |
double uload; |
148 |
double uload; |
| 134 |
zypp::Url url; |
149 |
zypp::Url url; |
| 135 |
}; |
150 |
}; |
|
Lines 1474-1489
Link Here
|
| 1474 |
// |
1489 |
// |
| 1475 |
// DESCRIPTION : Progress callback triggered from MediaCurl::getFile |
1490 |
// DESCRIPTION : Progress callback triggered from MediaCurl::getFile |
| 1476 |
// |
1491 |
// |
| 1477 |
int MediaCurl::progressCallback( void *clientp, double dltotal, double dlnow, |
1492 |
int MediaCurl::progressCallback( void *clientp, |
| 1478 |
double ultotal, double ulnow ) |
1493 |
double dltotal, double dlnow, |
|
|
1494 |
double ultotal, double ulnow) |
| 1479 |
{ |
1495 |
{ |
| 1480 |
ProgressData *pdata = reinterpret_cast<ProgressData *>(clientp); |
1496 |
ProgressData *pdata = reinterpret_cast<ProgressData *>(clientp); |
| 1481 |
if( pdata) |
1497 |
if( pdata) |
| 1482 |
{ |
1498 |
{ |
|
|
1499 |
time_t now = time(NULL); |
| 1500 |
if( now > 0) |
| 1501 |
{ |
| 1502 |
// reset time of last change in case initial time() |
| 1503 |
// failed or the time was adjusted (goes backward) |
| 1504 |
if( pdata->ltime <= 0 || pdata->ltime > now) |
| 1505 |
{ |
| 1506 |
pdata->ltime = now; |
| 1507 |
} |
| 1508 |
|
| 1509 |
// start time counting as soon as first data arrives |
| 1510 |
// (skip the connection / redirection time at begin) |
| 1511 |
time_t dif = 0; |
| 1512 |
if (dlnow > 0 || ulnow > 0) |
| 1513 |
{ |
| 1514 |
dif = (now - pdata->ltime); |
| 1515 |
dif = dif > 0 ? dif : 0; |
| 1516 |
|
| 1517 |
pdata->secs += dif; |
| 1518 |
} |
| 1519 |
|
| 1520 |
// update the drate_avg and drate_period only after a second has passed |
| 1521 |
// (this callback is called much more often than a second) |
| 1522 |
// otherwise the values would be far from accurate when measuring |
| 1523 |
// the time in seconds |
| 1524 |
//! \todo more accurate download rate computationn, e.g. compute average value from last 5 seconds, or work with milliseconds instead of seconds |
| 1525 |
|
| 1526 |
if ( pdata->secs > 0 && (dif > 0 || dlnow == dltotal )) |
| 1527 |
pdata->drate_avg = (dlnow / pdata->secs); |
| 1528 |
|
| 1529 |
if ( dif > 0 ) |
| 1530 |
{ |
| 1531 |
pdata->drate_period = ((dlnow - pdata->dload_period) / dif); |
| 1532 |
pdata->dload_period = dlnow; |
| 1533 |
} |
| 1534 |
} |
| 1535 |
|
| 1483 |
// send progress report first, abort transfer if requested |
1536 |
// send progress report first, abort transfer if requested |
| 1484 |
if( pdata->report) |
1537 |
if( pdata->report) |
| 1485 |
{ |
1538 |
{ |
| 1486 |
if (! (*(pdata->report))->progress(int( dlnow * 100 / dltotal ), pdata->url)) |
1539 |
if (!(*(pdata->report))->progress(int( dlnow * 100 / dltotal ), |
|
|
1540 |
pdata->url, |
| 1541 |
pdata->drate_avg, |
| 1542 |
pdata->drate_period)) |
| 1487 |
{ |
1543 |
{ |
| 1488 |
return 1; // abort transfer |
1544 |
return 1; // abort transfer |
| 1489 |
} |
1545 |
} |
|
Lines 1492-1507
Link Here
|
| 1492 |
// check if we there is a timeout set |
1548 |
// check if we there is a timeout set |
| 1493 |
if( pdata->timeout > 0) |
1549 |
if( pdata->timeout > 0) |
| 1494 |
{ |
1550 |
{ |
| 1495 |
time_t now = time(NULL); |
|
|
| 1496 |
if( now > 0) |
1551 |
if( now > 0) |
| 1497 |
{ |
1552 |
{ |
| 1498 |
bool progress = false; |
1553 |
bool progress = false; |
| 1499 |
|
1554 |
|
| 1500 |
// reset time of last change in case initial time() |
|
|
| 1501 |
// failed or the time was adjusted (goes backward) |
| 1502 |
if( pdata->ltime <= 0 || pdata->ltime > now) |
| 1503 |
pdata->ltime = now; |
| 1504 |
|
| 1505 |
// update download data if changed, mark progress |
1555 |
// update download data if changed, mark progress |
| 1506 |
if( dlnow != pdata->dload) |
1556 |
if( dlnow != pdata->dload) |
| 1507 |
{ |
1557 |
{ |