Limit QNetworkAccessManager download speed
-
Have you tried to use
setReadBufferSize
function of QNetworkReply?http://doc.qt.io/qt-5/qnetworkreply.html#setReadBufferSize
QNetworkReply will try to stop reading from the network once this buffer is full (i.e., bytesAvailable() returns size or more), thus causing the download to throttle down as well. If the buffer is not limited in size, QNetworkReply will try to download as fast as possible from the network.
-
Thank you very much.
I haven't tested yet but I know it was a bugged before in earlier versions, let's see if it's solved.Muito obrigado, eu já pesquisei sobre isso antes e sei que estava com um problema, mas não sei se já resolveram, no entanto irei testar para ver.
-
You can't directly control how quickly the other end of the connection sends you packets. So there's no definite way with TCP to limit a connection's bandwidth usage to guarantee that it doesn't fill up a link.
But, assuming the other end is reasonably well behaved, it will only send packets once it gets an acknowledgement from your system. So, cranking down the read buffer size, like KillerSmath mentioned will help because once all the buffers get full, your machine will stop sending acknowledgements of new packets, forcing the sending side to stop sending so quickly. Another thing you can do is to only read the incoming data at your set rate. This will help guarantee that your buffers get full and packets start getting dropped, throttling the connection.
So, oddly, the best way to get the sending side to only send at a certain rate, is to only read at that rate. Everything will basically sort itself out from there.