coio¶
A C++ asynchronous I/O library built on the sender/receiver model (std::execution), with first-class coroutine support.
#include <coio/core.h>
#include <coio/execution_context.h>
#include <coio/utils/timer.h>
using namespace std::chrono_literals;
auto job(coio::time_loop::scheduler sched, int value, std::chrono::seconds delay) -> coio::task<int> {
coio::timer timer{sched};
co_await timer.async_wait(delay);
co_return value;
}
auto main() -> int {
coio::time_loop context;
auto [i, j] = coio::this_thread::sync_wait(coio::when_all(
job(context.get_scheduler(), 114, 2s),
job(context.get_scheduler(), 514, 1s),
[&context]() -> coio::task<> { context.run(); co_return; }()
)).value();
// i == 114, j == 514, total wall time ≈ 2s
}
Features¶
- Sender/receiver model — every asynchronous operation is a sender, composable with
std::executionalgorithms and directlyco_await-able inside coio coroutines. - Coroutine types —
task<T, Allocator, Scheduler>for asynchronous computations,generator<Ref, Val, Allocator>for lazy synchronous sequences. - Execution contexts — the portable
time_loop, plus native async I/O backends:epoll_contextanduring_contexton Linux,iocp_contexton Windows. - Networking — TCP/UDP sockets with synchronous and asynchronous operations, address types and a resolver.
- Files and pipes — stream and random-access files, pipes, and complete-transfer read/write algorithms.
- Synchronization —
async_mutex,async_semaphore,async_latch: primitives that suspend coroutines instead of blocking threads. - Utilities — timers, structured concurrency scopes, signal handling, buffers and concurrent queues.
Note
Async I/O and networking backends are currently implemented on Linux (epoll and io_uring; the io_uring backend requires kernel 5.19 or newer) and Windows (IOCP).
Where to start¶
| Goal | Page |
|---|---|
| Build and install the library | Getting Started |
| Understand senders, coroutines, and cancellation in coio | Concepts |
| Write your first async program | task, time_loop |
| Do network I/O | Sockets, I/O Model & Lifetime |
| Understand the threading contracts | Execution Contexts, Thread Safety Summary |
License¶
coio is distributed under the MIT License.