Giter Site home page Giter Site logo

theclonerx / bad_io Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 331 KB

An async, event driven, IO library. Highly inspired in asio.

License: GNU Lesser General Public License v2.1

CMake 1.62% C++ 98.38%
cpp cpp20 asynchronous input-output concurrency

bad_io's Introduction

bad_io

(the name is temporary, will change later)

This is an attempt to creating an async, event based, IO library. Highly inspired in asio.

Currently I'm quite happy how tcx::ioring_service ended up being, and as of now, it should be thread-safe.

I wrote tcx::function_view thinking it would be useful for this project. Currently it's not, but I'm not going to let my efford go to waste.

tcx::unique_function was originally intended to be an allocator aware storage for callable move-only objects, but i dropped support for allocator awareness due to incrementing the complexity too much. Why not std::function? Well, that doesn't support move only types, which is a bummer. Now that std::move_only_function was added to C++23 im going to try aiming for this to be a pollyfil, but maybe other libraries like boost or abseil might do this better.

tcx::unsynchronized_execution_context is essentially just a function queue, and as it's name implies, it's not thread safe.

tcx::synchronized_execution_context is also just a function queue, but this one is thread safe. It allows calling run() and post() from multiple threads, allowing for multiple completions to be executed and posted in parallel.

Services should work with arbitrary executors. For example:

asio::system_executor ctx;
tcx::ioring_service io_service;

tcx::async_open(ctx, io_service, "/dev/null", "rb", [&ctx, &io_service](std::error_code ec, int fd) {
    if (ec)
        throw std::system_error(ec);
    tcx::async_close(ctx. io_service, fd, tcx::detached);
});

this will post the completion to an asio::system_executor, and the lambda will be executed in an arbitrary thread.

Some services themselves can be used as executors:

tcx::ioring_service io_service;
io_service.post([](){
    std::puts("Hello World");
});

TODO

  • Implement arguments for tcx::function_view
  • Implement SBO for tcx::unique_functiom
  • [ ] Implement allocator aware move operations for tcx::unique_function
  • [ ] Make the executor fully allocator aware
  • Learn about how overlapping IO works on Windows
  • Implement following IO services:
    • tcx::epoll_service
    • tcx::poll_service
    • tcx::overlapped_service
    • tcx::kqueue_service
  • Implement tcx::thread_service (might be redundant with tcx::synchronized_execution_context)
  • Implement tcx::synchronized_execution_context
  • How to run any coroutine inside the executors. (I really dont want to create a coroutine future just to use in the executors like asio::awaitable)

BUILDING

Dependencies are managed using Conan, so make sure you have it properly installed and setup.

mkdir build/
cd build;
conan install .. -u -b missing
cmake ..
cmake --build . --parallel

DOCUMENTATION

Documentation can be built with doxygen using cmake, execute the followin the build folder:

cmake --build . --target docs
firefox html/index.html

bad_io's People

Contributors

theclonerx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

cyberflamego

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.