I've never done it, but I would try to subsclass QNetworkAccessManager and QNetworkReply (QIODevice subclass) and have your derived ThrottledNetworkAccessManager return a ThrottledNetworkReply, in which you only read according to your throughput calculation. Once the OS TCP connection buffers are full it should push back against the server, slowing reply. You might also just subclass Q(Tcp|Ssl)Socket and write a client if the QNetworkAccessManager approach is too intrusive.
 
 
Sent: Tuesday, December 29, 2015 at 11:32 AM
From: "Jason Kretzer" <ja...@gocodigo.com>
To: "interest@qt-project.org" <interest@qt-project.org>
Subject: [Interest] Throttle downloads

Hello all,

 

I have an application that must download files in the background.  I separate this process off into a separate thread so that it does not interfere with the UI.  Unfortunately, when it starts downloading, it uses the full pipe that it has access to and adversely affects the rest of the network – causing other internet connections to slow to a crawl.  The application is installed on networks which I do not control and cannot throttle it that way.  What I would like to do is have the application not eat so much bandwidth during the download.

 

The code I am using to download is pretty run of the mill (error checks removed for brevity):

void ContentDownloader::downloadFile(QUrl url, QString filename)

{

    QNetworkRequest request(url);

    QNetworkAccessManager* _manager = new QNetworkAccessManager(this);

    QNetworkReply* reply = _manager->get(request);

 

    QEventLoop loop;

    connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));

    loop.exec();

 

    QFile file(filename);

    file.open(QIODevice::WriteOnly);

    file.write(reply->readAll());

    file.close();

}

 

Thoughts on how to make it “slow down”?  I have been toying with the setReadBufferSize in the reply but does not really seem to change anything.

 

Thanks!

 

-Jason

 

- - - - - - - - - - - - - - - - - - - - - - -

Jason R. Kretzer

 

Lead Application Developer

ja...@gocodigo.com

 

“quidquid latine dictum sit altum videtur”

 

Logo_EmailSig

 

 

_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to