Joey Adams
Joey Adams

Reputation: 43410

Downloading HTTP URLs asynchronously in C++

What's a good way to download HTTP URLs (e.g. such as http://0.0.0.0/foo.htm ) in C++ on Linux ? I strongly prefer something asynchronous. My program will have an event loop that repeatedly initiates multiple (very small) downloads and acts on them when they finish (either by polling or being notified somehow). I would rather not have to spawn multiple threads/processes to accomplish this. That shouldn't be necessary.

Should I look into libraries like libcurl? I suppose I could implement it manually with non-blocking TCP sockets and select() calls, but that would likely be less convenient.

Upvotes: 4

Views: 5804

Answers (4)

Joakim Karlsson
Joakim Karlsson

Reputation: 1122

You can use boost::asio to perform async IO operations. Heres an example of an async http client.

Upvotes: 9

Ankur Gupta
Ankur Gupta

Reputation: 2300

Qt's QThread instance when run can have it's own event loop. Insides QThread you can have an instance of QHttp and since QHttp uses Qt Event loop to function you have your async Http calls from mail thread. Also note that inter thread communication is very easy.

Head straight to http://doc.qt.nokia.com and look at the classes's documentation to understand better.

Upvotes: 0

Donotalo
Donotalo

Reputation: 13035

Have you considered Qt's network module? They provide some classes for asynchronous download for example QNetworkAccessManager.

Upvotes: 1

Matt
Matt

Reputation: 509

Libcurl is the way to go. See http://curlpp.org for C++ bindings and an excellent set of tutorials.

Upvotes: 7

Related Questions