PDA

View Full Version : How to limit download speed with QHttp ?



THRESHE
15th November 2007, 15:57
In the app I'm writing I need to limit download speed. I'm using QHttp. Can I do that ?

danadam
15th November 2007, 19:22
You can implement tcp socket with rate control like in this article (http://doc.trolltech.com/qq/qq17-ratecontrol.html) and then replace the internal socket of QHttp using:

int QHttp::setSocket ( QTcpSocket * socket )

THRESHE
27th November 2007, 15:33
I've tried sources from the example . But I didn't get QHttp::authenticationRequired signal from my QHttp object :(
The resopnse header was "HTTP/1.0 401 Unauthorized"

Anybody knows how to fix the problem ?

THRESHE
28th November 2007, 12:49
Never mind. I've fixed this problem :)

But now I have a new problem :(
The use of CPU on my machine is about 50 percent ! And the use of memory is constantly growing :confused:

jacek
28th November 2007, 14:03
The use of CPU on my machine is about 50 percent !
Do you have any "busy wait" loops in your code? Or timers with short timeouts?


And the use of memory is constantly growing :confused:
You might have a memory leak. You can use valgrind find it, but I'm not sure how usable it is under Mac OS. There might be some similar tools for windows, but unfortunately I don't know any of them.

You can also look for leaks yourself by checking whether you delete all objects created using new operator. Remember that Qt will delete QObjects only when you delete their parent.

THRESHE
22nd December 2007, 12:39
Has anyone tried to compile and run source code from the article ? I've tried it both on MacOS and Windows but result is the same - half CPU time and constant memory growth :confused:
I've tried to use this source like this:


int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);

QString str = "http://ua.fishki.net/picsw/122007/21/video/switch_on.wmv";
QUrl url(str);

RcTcpSocket socket;
QHttpRequestHeader header("GET", str);
QHttp http;
QFile file("Rate.wmv");
http.setSocket(&socket);
http.setHost(url.host());
http.get(url.path(), &file);

RateController controller;
controller.setUploadLimit(512);
controller.setDownloadLimit(2048);
controller.addSocket(&socket);
return app.exec();
}

AlekseyK
25th November 2010, 11:55
Has anyone tried to compile and run source code from the article ? I've tried it both on MacOS and Windows but result is the same - half CPU time and constant memory growth :confused:
Yes, I had same problem: this is an error in the program or QIODevice behaviour change. I modified it a little according to similar Qt torrent example, that had fixed that problem. However program have another problem: coming (and may be sending) data is not complete - some data stays in socket buffer. Searching how to fix that currently.

Added after 1 47 minutes:
Andreas Aardal Hanssen, answered on this question here: http://labs.qt.nokia.com/2006/09/11/behavioral-changes-in-qiodevice-in-qt-42/

PPS: This change renders my trick from QQ17 (TCP Traffic Control) unusable; instead, the rate-controlled socket has to proxy an internal QTcpSocket instance. The examples/network/torrent example in Qt 4.2 will demonstrate what changes were necessary.