Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 732
Joey Adams Avatar asked Dec 03 '22 14:12

Joey Adams


1 Answers

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

like image 162
Joakim Karlsson Avatar answered Dec 09 '22 15:12

Joakim Karlsson