Review Complete · Results Pending

Better Async
Networking

Thank you to everyone who tested Corosio, read the docs, filed issues, and wrote a review. The Boost formal review has closed and we're now waiting on the review manager's report. Corosio is still here to try, and we're still reading everything you send us.

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 has closed, but the work hasn't. 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.