curl-library
Re: Use of the limit-rate in C API
Date: Thu, 21 Nov 2002 08:33:50 +0100 (MET)
On Wed, 20 Nov 2002, Juan Ignacio Hervás wrote:
> I am very interesting in the new feature introduced in the 7.10 version
> related with the use of bandwidth limit. I think that this new option (
> --limit-rate <speed> ) has been introduced in the curl command line tool
> but, can it be used with the libcurl in a Visual C++ project? In that case,
> how to do it? is there any new CURLOPT_ option?
Yes, there was a new CURLOPT added (which is used when this feature is use
for downloads). CURLOPT_BUFFERSIZE sets the "prefered" read buffer size to
libcurl, and by doing that we can get a callback more often.
The read callback in curl is then making sure that it doesn't return control
back to libcurl too fast, like this:
if(config->recvpersecond) {
/*
* We know when we received data the previous time. We know how much data
* we get now. Make sure that this is not faster than we are told to run.
* If we're faster, sleep a while *before* doing the fwrite() here.
*/
time_t timediff;
time_t now;
now = time(NULL);
timediff = now - config->lastrecvtime;
if( size*nmemb > config->recvpersecond*timediff) {
/* figure out how many milliseconds to rest */
go_sleep ( (size*nmemb)*1000/config->recvpersecond - timediff*1000 );
now = time(NULL);
}
config->lastrecvtime = now;
}
/* make fwrite() here */
(go_sleep() is present in src/main.c and is a portable function for
ms-resolution sleeps.)
-- Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs. ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sfReceived on 2002-11-21