curl-library
RE: Determine download speed
Date: Mon, 14 Jun 2010 02:00:29 +0200
Hey,
I think I finally got it done. Here is the part of the code:
// DownloadStruct should contain:
// time_t myTime
// curl_off_t myWriteCount
// Should be initialized to 0 before given to the callback.
int callback(char *data, unsigned int size, unsigned int nmemb, struct
DownloadStruct *ptr)
{
int result = 0;
if (ptr)
{
result = size * nmemb;
// write to file...
double div = difftime(time(0), ptr->myTime);
if (div >= 1)
{
double speed = ptr->myWriteCount / div;
speed /= 1024; // kilobytes per second
// do something with speed
ptr->myWriteCount = 0;
ptr->myTime = time(0);
}
else
{
ptr->myWriteCount += result;
}
}
return result;
}
I think that should work very well. Thank you very much for the help :)
Patrick K.
_________________________________________________________________
http://redirect.gimas.net/?n=M1006xHMTL4
Künftig E-Mails über Hotmail ohne Werbung versenden!
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-06-14