Results 1 to 7 of 7

Thread: How to limit download speed with QHttp ?

  1. #1
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Exclamation How to limit download speed with QHttp ?

    In the app I'm writing I need to limit download speed. I'm using QHttp. Can I do that ?
    C++ & AMD forever

  2. #2
    Join Date
    Aug 2006
    Location
    Switzerland
    Posts
    52
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to limit download speed with QHttp ?

    You can implement tcp socket with rate control like in this article and then replace the internal socket of QHttp using:
    Qt Code:
    1. int QHttp::setSocket ( QTcpSocket * socket )
    To copy to clipboard, switch view to plain text mode 
    Last edited by danadam; 15th November 2007 at 19:23. Reason: updated contents
    The Wheel weaves as the Wheel wills.

  3. The following 3 users say thank you to danadam for this useful post:

    gfunk (15th November 2007), THRESHE (15th November 2007), xEsk (16th November 2007)

  4. #3
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to limit download speed with QHttp ?

    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 ?
    C++ & AMD forever

  5. #4
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to limit download speed with QHttp ?

    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
    C++ & AMD forever

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to limit download speed with QHttp ?

    Quote Originally Posted by THRESHE View Post
    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?

    Quote Originally Posted by THRESHE View Post
    And the use of memory is constantly growing
    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.

  7. #6
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to limit download speed with QHttp ?

    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
    I've tried to use this source like this:
    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. QCoreApplication app(argc, argv);
    4.  
    5. QString str = "http://ua.fishki.net/picsw/122007/21/video/switch_on.wmv";
    6. QUrl url(str);
    7.  
    8. RcTcpSocket socket;
    9. QHttpRequestHeader header("GET", str);
    10. QHttp http;
    11. QFile file("Rate.wmv");
    12. http.setSocket(&socket);
    13. http.setHost(url.host());
    14. http.get(url.path(), &file);
    15.  
    16. RateController controller;
    17. controller.setUploadLimit(512);
    18. controller.setDownloadLimit(2048);
    19. controller.addSocket(&socket);
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 
    C++ & AMD forever

  8. #7
    Join Date
    Nov 2010
    Posts
    47
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to limit download speed with QHttp ?

    Quote Originally Posted by THRESHE View Post
    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
    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/...vice-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.
    Attached Files Attached Files
    Last edited by AlekseyK; 25th November 2010 at 11:55.

Similar Threads

  1. QHttp download file problem.
    By fengtian.we in forum Qt Programming
    Replies: 12
    Last Post: 12th June 2007, 09:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.