Search code examples
c++network-programminglibcurlbandwidth-throttling

Determine available upload/download bandwidth


I have an application which does file upload and download. I also am able to limit upload/download speed to a desired level (CONFIGURABLE), so that my application does not consume the whole available bandwidth. I am able to achieve this using the libcurl (http) library.

But my question is, if I have to limit my upload speed to say 75% of the available upload bandwidth, how do I find out my available upload bandwidth programatically? preferably in C/C++. If it is pre-configured, I have no issues, but if it has to be learnt and adapted each time, like I said, 75% of the available upload limit, I do not know who to figure it out. Same is applicable to download. Any pointers would be of great help.


Solution

  • There's no way to determine the absolute network capacity between two points on a regular network. The reason is that the traffic can be rerouted in between, other data streams appear or disappear or links can be severed.

    What you can do is figure out what is the available bandwidth right now. One way to do it is to upload/download a chunk of data (say 1MB) as fast as possible (no artificial caps), and measure how long it takes. From there you can figure out what bandwidth is available now and go from there.

    You could periodically measure the bandwidth again to make sure you're not too way off.