Results 1 to 7 of 7

Thread: QNetworkAccessManager bandwidth throttling

  1. #1
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QNetworkAccessManager bandwidth throttling

    Hi,

    I'm using the QNetworkAccessManager to manage some downloads from websites. I'd also like to limit the download rate.
    I came upon this wonderful article http://doc.trolltech.com/qq/qq17-ratecontrol.html that implements bandwidth throttling but unfortunately (for me) it does so by subclassing the QTcpSocket. I don't have that kind of control in the QNetworkAccessManager class.

    Does anyone have a suggestion how I would go about implementing (possibly integrating/using the source code in the article) bandwidth throttling in the QNetworkAccessManager?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager bandwidth throttling

    I don't think you can do that. The only virtual method in this class is QNetworkAccessManager::createRequest but this won't help you. The only thing you could do is to implement your own backend for QNetworkAccessManager but then it would be like doing everything from scratch.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QNetworkAccessManager bandwidth throttling

    Quote Originally Posted by wysota View Post
    I don't think you can do that. The only virtual method in this class is QNetworkAccessManager::createRequest but this won't help you. The only thing you could do is to implement your own backend for QNetworkAccessManager but then it would be like doing everything from scratch.
    Thank you for your reply.
    Do you have any other suggestion in mind other than implementing everything from scratch? Maybe I could copy the QNetworkAccessManager code and change some code there?

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager bandwidth throttling

    Quote Originally Posted by bluefly View Post
    Maybe I could copy the QNetworkAccessManager code and change some code there?
    You can change QNetworkAccessManager in your Qt sources as it is open source. Copying the code would be complicated because of "pimpl" - private implementation. Most of Qt classes (QNetworkAccessManager also) uses a lot of stuff which is not easily available for you when you write your program with Qt or using it is a bit dangerous as in those private impl headers stands:
    Qt Code:
    1. //
    2. // W A R N I N G
    3. // -------------
    4. //
    5. // This file is not part of the Qt API. It exists for the convenience
    6. // of the Network Access API. This header file may change from
    7. // version to version without notice, or even be removed.
    8. //
    9. // We mean it.
    10. //
    To copy to clipboard, switch view to plain text mode 
    So I would rather try to understand the QNetworkAccessManager code and modify it in it's source code.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. #5
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QNetworkAccessManager bandwidth throttling

    Quote Originally Posted by faldżip View Post
    You can change QNetworkAccessManager in your Qt sources as it is open source. Copying the code would be complicated because of "pimpl" - private implementation. Most of Qt classes (QNetworkAccessManager also) uses a lot of stuff which is not easily available for you when you write your program with Qt or using it is a bit dangerous as in those private impl headers stands:
    Qt Code:
    1. //
    2. // W A R N I N G
    3. // -------------
    4. //
    5. // This file is not part of the Qt API. It exists for the convenience
    6. // of the Network Access API. This header file may change from
    7. // version to version without notice, or even be removed.
    8. //
    9. // We mean it.
    10. //
    To copy to clipboard, switch view to plain text mode 
    So I would rather try to understand the QNetworkAccessManager code and modify it in it's source code.
    actually I tried to take a look at QNetworkAccessManager code and think of changing it but it looks so complicated... and all those private classes make it impossible! even if I do dig more into it I highly doubt there's a place I could just replace "QTcpSocket" with "MySocket" and it will work just like that...
    so the way I see it now the best option is not to use QNetworkAccessManager but instead work around the class proposed in the article and extend it.

  6. #6
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QNetworkAccessManager bandwidth throttling

    I just had a nice idea (well it's a dirty hack, but still):

    1. Create a Qt Library with class that uses QNetworkAccessManager (this will replace QNetworkAccessManager for me).
    2. Change QTcpSocket code in Qt to include the changes in the article.
    3. Do the other changes that are mentioned in the article in the appropriate place.
    4. Build & Link to Qt statically.
    5. Restore old Qt code.
    6. Use the library in my code instead of QNetworkAccessManager.

    The main idea is that I'm guessing somewhere QNetworkAccessManager uses QTcpSocket, so if I change QTcpSocket (rather than subclass it) I will get the desired result. I need the separate library since I don't want to change QTcpSocket in my "original" Qt, only where I need bandwidth throttling.
    The potential side effect is that QNetworkAccessManager might be using QTcpSocket in places where the modified one will break it.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager bandwidth throttling

    Quote Originally Posted by bluefly View Post
    Thank you for your reply.
    Do you have any other suggestion in mind other than implementing everything from scratch? Maybe I could copy the QNetworkAccessManager code and change some code there?
    You can use qFindChild() to access the tcp socket that handles your request and use event filters on it or connect to it to change its behaviour. But I don't know if that will be sufficient for you. It might be easier to reimplement createRequest() to have your own backend for QNetworkAccessManager.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.