Coder Social home page Coder Social logo

cnsuhao / asio-extensions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timniederhausen/asio-extensions

0.0 1.0 0.0 1006 KB

Additional functionality built on top of (Boost.)Asio

License: Boost Software License 1.0

CMake 1.26% C++ 98.74%

asio-extensions's Introduction

Asio Extensions (AsioExt)

Build Status Build status

AsioExt is a collection of various components and functionality that builds on (Boost.)Asio. It is compatible with standalone Asio, as well as the Boost version.

Feature overview

Filesystem:

  • File handle types with support for:
    • Asio's *Stream concepts (SyncReadStream, SyncRandomAccessReadDevice, ...)
    • Querying/altering file metadata (size, permissions, attributes, file times)
  • Asynchronous file I/O with different implementations.
  • Utility functions for writing/reading files.

Networking:

  • SOCKS 5 client library
  • Utility functions that simplify common operations (e.g. resolve and connect)

This is a very coarse overview of the project's features. The documentation has all the details.

Simple example

#include <asioext/unique_file_handle.hpp>
#include <asioext/read_file.hpp>
#include <asioext/write_file.hpp>
#include <asioext/open.hpp>

#include <asio/read.hpp>

#include <iostream>
#include <cassert>

int main(int argc, const char* argv[])
{
  const std::string test_content("Hello world");

  try {
    // Utility functions write/read containers and buffer sequences to/from files.
    const std::array<asio::const_buffer, 2> buffers_to_write = {
      asio::buffer(test_content),
      asio::buffer(test_content),
    };
    asioext::write_file("myfile.txt", buffers_to_write);

    std::string read_content;
    asioext::read_file("myfile.txt", read_content);

    assert(read_content == test_content + test_content);

    // (unique_)file_handle simply wraps a native file handle.
    // (There's also basic_file, which needs an asio::io_service and provides
    // asynchronous I/O.)
    asioext::unique_file_handle file =
        asioext::open("myfile.txt", asioext::open_flags::access_read |
                                    asioext::open_flags::open_existing);

    assert(file.size() == test_content.size() * 2);

    std::string read_content2(test_content.size(), '\0');
    asio::read(file, asio::buffer(&read_content2[0], read_content2.size()));

    assert(read_content2 == test_content);
    return 0;
  } catch (std::exception& e) {
    // Exceptions are used for error reporting here.
    // All functions also offer a non-throwing overload,
    // which takes an asio::error_code& instead.
    std::cerr << "error: " << e.what() << std::endl;
    return 1;
  }
}

Take a look at the examples directory for more!

Documentation

The documentation can be found at http://timniederhausen.github.io/asio-extensions, or inside the gh-pages branch.

Additionally, the documentation can be generated by building the special asioext.doc target. Note that this target is only available if you have Doxygen installed.

License

Please see LICENSE_1_0.txt.

asio-extensions's People

Contributors

timniederhausen avatar

Watchers

 avatar

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.