Note (2018): This library is currently unmaintained and a rewrite for C++14/17, possibly as simple header-only library, is planned.
Here be dragons. Although this library generally works quite well, it is still being developed and has not been extensively tested. You will probably be fine, but don't look at me when things catch fire.
This library makes use of libcurl's multi interface in order to enable easy integration into Boost.Asio applications.
make && make install
#include <boost/asio.hpp>
#include <boost/make_shared.hpp>
#include <curl-asio.h>
#include <fstream>
int main(int argc, char* argv[])
{
// this example program downloads argv[1] to argv[2] (arg validation omitted for readability)
char* url = argv[1];
char* file_name = argv[2];
// start by creating an io_service object
boost::asio::io_service io_service;
// construct an instance of curl::easy
curl::easy downloader(io_service);
// set the object's properties
downloader.set_url(url);
downloader.set_sink(boost::make_shared<std::ofstream>(file_name, std::ios::binary));
// download the file
boost::system::error_code ec;
downloader.perform(ec);
// error handling
if (!ec)
{
std::cerr << "Download succeeded" << std::endl;
}
else
{
std::cerr << "Download failed: " << ec.message() << std::endl;
}
return 0;
}
More examples, including one for curl-asio's asynchronous interface, can be found in the wiki and the examples
directory.
Curl-asio is licensed under the same MIT/X derivate license used by libcurl.