curl-library
Re: Bandwidth/rate limitation
Date: Tue, 10 Aug 2004 13:09:42 +0100
Hi Daniel,
Thanks for your reply, I took a look at that function and it's very
similar to what I've done already, except I got to the point where my
code could act on having too many bytes or hitting 1.0 second, but curl
was transferring more per loop than my limit, so I emailed here.
Anyway, I'll try that option now, cheers for that. One further
question, can this option be called DURING a transfer? or can it only be
called before it starts? as this could affect how I use the option.
Perhaps I can dynamically set this option, which would be great!
otherwise, I'll have to pick a minimum value and deal with it. I'm
wondering about how the overhead could possibily affect the cpu usage or
bandwidth I have available. Could having a smaller value start any
nasty consequences in your opinion?
Thanks mate!
Christopher
Daniel Stenberg wrote:
> 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
>
Received on 2004-08-10