cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Bandwidth/rate limitation

From: Daniel Stenberg <daniel-curl_at_haxx.se>
Date: Tue, 10 Aug 2004 08:00:00 +0200 (CEST)

On Mon, 9 Aug 2004, Evil Kosh wrote:

> I've come to require some way of limiting libcurl's bandwidth is has access
> to, I originally thought I could implement some kind of timer, then
> calculate the number of microseconds or bytes in each loop and cutoff either
> when the timer goes over 1.0 seconds or the rate I'm limiting to (and then
> could select for the remainder of that 1.0 seconds). But my problem, of
> course, is that libcurl can transfer more than 1024bytes or 2048 bytes in
> ONE transfer, so it seems like it's out of my hands, I need some way of
> telling libcurl to STOP when it gets to a certain number of bytes.

You can ask libcurl to use a smaller internal buffer: CURLOPT_BUFFERSIZE,
which will make it call your callback more often when downloading data.

> I read on the mailing list that someone had figured out a way of doing this,
> but then didnt go on to tell anymore about it. I was wondering if anyone
> has a way of doing this and wouldnt mind telling me!

There have been discussions in the past on how to add this feature to the
library but nothing has yet been decided or written. The curl tool provides a
--limit-rate option that does this, but the code that limits the rate is all
done in the app and not in the library. You might get some inspiration for
your code by checking out how we've done it in curl:

         http://curl.haxx.se/lxr/source/src/main.c#L2277

-- 
      Daniel Stenberg -- http://curl.haxx.se -- http://daniel.haxx.se
       Dedicated custom curl help for hire: http://haxx.se/curl.html
Received on 2004-08-10