cURL / Mailing Lists / curl-library / Single Mail

curl-library

FTP download speed throttling

From: Andrea Narciso <andrea.narciso_at_artgroup-spa.com>
Date: Tue, 16 Apr 2013 21:29:16 +0200

I have built an FTP client around the libcurl easy interface, and now
I'd like to add download bandwidth throttling at runtime. That is, being
able to change download speed depending on some external stimuli while
the download is already in progress.

I was looking for the best way to implement this feature; in the mailing
list I found some old responses that are quite tentative
and could be not valid anymore due to evolution in libcurl, so I still
have many doubts. In particular:

1) I can set the download speed for a connection by setting
CURLOPT_MAX_RECV_SPEED_LARGE and CURLOPT_BUFFERSIZE parameters at
startup. Are these parameters meant to be changed at runtime? Some old
threads hint at this, but nobody was sure if the approach was actually
feasible or even safe.

2) Somebody suggested pausing the connection, changing the
aforementioned parameters and resuming. Is this approach fine? Are there
any limitations/drawbacks?

3) I also considered the "rough" approach: implementing some kind of
variable delay inside the CURLOPT_WRITEFUNCTION callback. This is my
least favourite solution as I do not know enough of libcurl internal
structure, so having a somewhat blocking callback could be quite risky
(e.g. impairing libcurl operations, triggering timeouts in the FTP
server etc.). Is this approach also viable?

Do you have any suggestions?

Thanks in advance and regards,
Andrea
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-04-16