Esempio n. 1
0
void handle_download_completed(const boost::system::error_code& err, std::string url, curl::easy* easy)
{
	if (!err)
	{
		std::cout << "Download of " << url << " completed" << std::endl;
	}
	else
	{
		std::cout << "Download of " << url << " failed: " << err.message() << std::endl;
	}
	
	active_downloads.erase(*easy);
}
Esempio n. 2
0
void start_download(curl::multi& multi, const std::string& url)
{
	std::auto_ptr<curl::easy> easy(new curl::easy(multi));
	
	// see 'Use server-provided file names' example for a more detailed implementation of this function which receives
	// the target file name from the server using libcurl's header callbacks
	std::string file_name = url.substr(url.find_last_of('/') + 1);
	
	easy->set_url(url);
	easy->set_sink(boost::make_shared<std::ofstream>(file_name.c_str(), std::ios::binary));
	easy->async_perform(boost::bind(handle_download_completed, boost::asio::placeholders::error, url, easy.get()));
	
	active_downloads.insert(easy);
}
		void insert(boost::ptr_set<T>   &arg_ptr_set,  ///< The ptr_set into which the value should be inserted
		            std::unique_ptr<T> &&arg_ptr_value ///< The associated value to insert, held by unique_ptr
		            ) {
			arg_ptr_set.insert( arg_ptr_value.release() );
		}