Conditionally Accepted into Boost

Better Async
Networking

Corosio has been conditionally accepted into Boost. Thank you to everyone who tested it, read the docs, filed issues, and wrote a review. That scrutiny is what got us here. We're now working through the conditions raised during the review before Corosio lands in a Boost release.

Try It → Why Corosio?
Quick Test

Build an Echo Server in 10 Minutes.

Two files, four commands, no dependency wrangling. Still the fastest way to see what Corosio actually feels like.

1
Create Two Files

Make a new folder anywhere. Inside it, create CMakeLists.txt and main.cpp with the contents below.

CMakeLists.txt
cmake_minimum_required(VERSION 3.14...4.2)
project(echo_server VERSION 1.0 LANGUAGES CXX)

include(FetchContent)
FetchContent_Declare(capy
    GIT_REPOSITORY https://github.com/cppalliance/capy.git
    GIT_TAG develop
    GIT_SHALLOW TRUE)
FetchContent_Declare(corosio
    GIT_REPOSITORY https://github.com/cppalliance/corosio.git
    GIT_TAG develop
    GIT_SHALLOW TRUE)

FetchContent_MakeAvailable(capy corosio)

add_executable(echo_server main.cpp)
target_link_libraries(echo_server Boost::corosio)
main.cpp: Echo Server
#include <boost/capy.hpp>
#include <boost/corosio.hpp>
#include <iostream>

namespace corosio = boost::corosio;
namespace capy    = boost::capy;

capy::task<> echo_session(corosio::tcp_socket sock)
{
    char buf[1024];
    for (;;)
    {
        auto [ec, n] = co_await sock.read_some(
            capy::mutable_buffer(buf, sizeof(buf)));
        auto [wec, wn] = co_await capy::write(sock,
            capy::const_buffer(buf, n));
        if (ec || wec) break;
    }
    sock.close();
}

capy::task<> accept_loop(
    corosio::tcp_acceptor& acc,
    corosio::io_context& ioc)
{
    auto ep = acc.local_endpoint();
    std::cout << "Listening on port " << ep.port() << "\n";
    for (;;)
    {
        corosio::tcp_socket peer(ioc);
        auto [ec] = co_await acc.accept(peer);
        if (ec) { std::cout << ec.message(); continue; }
        capy::run_async(ioc.get_executor())(
            echo_session(std::move(peer)));
    }
}

int main(int argc, char* argv[])
{
    unsigned short port = 8080;
    if (argc > 1)
        port = static_cast<unsigned short>(std::atoi(argv[1]));
    corosio::io_context ioc;
    corosio::tcp_acceptor acc(ioc, corosio::endpoint(port));
    capy::run_async(ioc.get_executor())(accept_loop(acc, ioc));
    ioc.run();
}
⚠  The CMakeLists.txt may change. Check github.com/sgerbino/corosio-quickstart for the latest.
2
Configure

Run this from your project folder. CMake will fetch Corosio and all its dependencies automatically, with nothing to install by hand.

$ cmake -B build
3
Build & Run

Compile, then start the server. You should see it listening on port 8080.

$ cmake --build build
$ ./build/echo_server
Listening on port 8080
4
Test It

Open a second terminal and send it something. You should see your message echoed back.

$ echo "Hello World" | nc localhost 8080
Hello World
Quick Test Repo → Full Documentation
Your Experience

Feedback Is Still Open.

The review is over, but the work isn't. We're addressing the review conditions now, so this is a good moment to tell us what tripped you up. Whether you got it running or hit a wall on step one, we still want to hear about it. Doesn't need to be polished. Rough notes are great. Anything you tell us here goes directly to the people building this.