Coder Social home page Coder Social logo

curl-asio's Introduction

curl-asio

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.

  • simple interface - Download and upload anything, synchronously or asynchronously, with just a few lines of code.
  • familiar - If you have used libcurl in a C application before, you will feel right at home.
  • exceptions - Libcurl errors throw exceptions. Integrates nicely with Boost.System's error_code class.
  • useful wrappers - C++ interfaces for libcurl's easy, multi, form, share and string list containers. All setopt calls are wrapped for type safety.
  • source/sink concept - Works nicely with Boost.Iostreams

Installation

  1. If not already done, install cURL and its header files
  2. Clone this git repository. There are no tags or packages yet.
  3. Run CMake and point it to cURL
  4. make && make install

Example

#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.

Todo

  • Testing suite based on libcurl's tests
  • API documentation, design documentation, more examples
  • Support for transport schemes using UDP and incoming TCP sockets (active FTP)
  • File upload streams
  • string_list iterators

License

Curl-asio is licensed under the same MIT/X derivate license used by libcurl.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.