Skip to content
Skillpedia
APIs & servers (backend)29k Β· #9544

boost-asio-pro

What it does

This skill guides the agent in writing async C++ networking code with Boost.Asio or standalone Asio. It is for C++ developers building TCP, UDP or SSL servers and clients who want to avoid hard-to-find crashes.

When to use it

  • βœ“When you are writing async networking code in C++ with Boost.Asio.
  • βœ“When you are reviewing C++ networking code for lifetime or threading bugs.
  • βœ“When you need to match Asio code to an older or newer Boost version.

Skill link

https://github.com/alirezarezvani/claude-skills/blob/main/engineering/boost-asio-pro/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/alirezarezvani/claude-skills/blob/main/engineering/boost-asio-pro/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œWrite a simple TCP echo server in C++ with Boost.Asio that works with our older Boost version.”

5 new skills a week. 1 minute to read.

How it works

The agent first checks your Boost version and C++ standard, then picks the matching style, such as coroutines for newer toolchains or callbacks for older ones. It applies rules on object lifetimes, strands and cancellation.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Boost.Asio / standalone Asio

Overview

Write async C++ networking code that compiles on the user's Boost, not the newest one. Asio's API changed shape three times (classic io_service β†’ io_context β†’ C++20 coroutines) and most Asio code on the internet is from the first era, so pick the style from the toolchain first, then follow that style's reference file.

References: Boost.Asio Β· standalone Asio

Use this skill whenever async C++ networking code is being written or reviewed β€” and especially when the target toolchain is old, where coroutine examples simply will not compile. The three worked implementations it references are CI-verified from Boost 1.62 (2016) through 1.90.

Step 1: pick the style (do this before writing code)

Determine the Boost (or Asio) version and the C++ standard actually in use β€” find_package(Boost) output, dpkg -l libboost-dev, brew info boost, CMAKE_CXX_STANDARD, or ask. Do not assume the newest.

Boost C++ std Style Read
β‰₯ 1.77 C++20 Coroutines (co_await + awaitable<T>) β€” preferred references/coroutines.md
β‰₯ 1.74 C++11–17 Completion handlers (callbacks) β€” the portable baseline references/pre-cpp20.md
β‰₯ 1.80 C++11–17 Stackful asio::spawn + yield_context (links Boost.Coroutine β€” not header-only) references/pre-cpp20.md
1.62–1.65 C++11 Classic io_service / strand.wrap / expires_from_now references/classic-boost.md

SSL/TLS in any style: references/ssl.md. CMake for any style: references/build.md.

io_context, make_strand, bind_executor, steady_timer, signal_set, async_read/async_write/async_read_until, buffers and resolver are library features β€” identical in the coroutine and callback styles. Only the suspension mechanism differs.

Step 2: version floors (verified by compiling, not from docs)

Reach for one of these and the build breaks on older distros:

Feature Floor
experimental/awaitable_operators.hpp (the || / && operators) Boost β‰₯ 1.77 / Asio β‰₯ 1.20
as_tuple completion token Boost β‰₯ 1.79 / Asio β‰₯ 1.21
co_composed (custom composed ops) Boost β‰₯ 1.85 / Asio β‰₯ 1.30
3-arg asio::spawn(ex, fn, token) Boost β‰₯ 1.80 (older Boost has only spawn(ex, fn))
any_io_executor (strand<any_io_executor>, tcp::socket's default executor) Boost β‰₯ 1.74 β€” the floor for the callback style; below it, use legacy io_context::strand
io_context, make_strand, expires_after Boost β‰₯ 1.66 β€” below it, classic io_service

Distro floors that bite: Debian bookworm ships Boost 1.74 (no awaitable_operators.hpp β€” #include fails outright), Ubuntu 20.04 ships 1.71 (no any_io_executor), Debian 9 ships 1.62.

Language, not library: the chrono literals 250ms / 30s are C++14. For a true C++11 build write std::chrono::milliseconds(250).

Step 3: the rules that are actually easy to get wrong

A strand does not serialize writes. A strand serializes handler execution, not whole composed operations. Two async_writes in flight on the same strand still interleave bytes on the wire. Full-duplex (a read loop plus concurrent pushes/replies) needs a per-connection strand and an outbound queue with an in-flight flag, so at most one async_write exists at a time. This is the single most common wrong answer about Asio.

Buffers do not own memory. asio::buffer() is a view. Storage must outlive the operation: coroutine locals are fine across co_await in the same frame; in callback style the same data must become a member, not a local.

Connections must outlive their handlers. enable_shared_from_this, and capture self in every co_spawn / handler β€” read loop, write loop, and each timer.

Frame with composed reads. async_read (fills the buffer exactly) for a length prefix and then the body; never async_read_some, which returns short.

Wrap as_tuple. Always as_tuple(use_awaitable). Bare as_tuple resolves against the operation's default token and compiles in some contexts, fails in others.

async_accept(make_strand(...)) changes two things: it forces a

FAQ

Why does the Boost version matter?

Asio's API has changed over time, and coroutine examples will not compile on older toolchains.

Which styles does it support?

Coroutines for C++20 setups, and completion handlers for older or C++11 to C++17 projects.

What kinds of bugs does it help avoid?

Classic async bugs such as lifetime problems and missed cancellations.

Details

Original description by the author

Use for any C++ networking code with Boost.Asio or standalone Asio (TCP/UDP, SSL, timers, strands, io_context, co_spawn, awaitable, completion handlers), before writing or reviewing it. Applies lifetime, strand and cancellation rules that avoid the classic async bugs.

repo: alirezarezvani/claude-skills

Popularity

GitHub stars
29k
Ranking position
#9544
License
MIT
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills