Corosio is a coroutine-native C++20 networking library — the next evolution of Asio. Before we submit it to Boost for formal review, we'd love your eyes on it. Try the echo server below and tell us what's broken or confusing.
Two files, four commands, no dependency wrangling. Follow along, then scroll down and let us know how it went.
Make a new folder anywhere. Inside it, create CMakeLists.txt and main.cpp with the contents below.
cmake_minimum_required(VERSION 3.14...4.2)
project(echo_server VERSION 1.0 LANGUAGES CXX)
include(FetchContent)
FetchContent_Declare(corosio
GIT_REPOSITORY https://github.com/cppalliance/corosio.git
GIT_TAG develop
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(corosio)
add_executable(echo_server main.cpp)
target_link_libraries(echo_server Boost::corosio)
#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();
}
Run this from your project folder. CMake will fetch Corosio and all its dependencies automatically — nothing to install by hand.
Compile, then start the server. You should see it listening on port 8080.
Open a second terminal and send it something. You should see your message echoed back.
Whether you got it running or hit a wall on step one, we 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.