boost-asio-pro
Was er macht
Dieser Skill führt den Agenten beim Schreiben von asynchronem C++-Netzwerkcode mit Boost.Asio oder eigenständigem Asio. Er ist für C++-Entwickler gedacht, die TCP-, UDP- oder SSL-Server und -Clients bauen und schwer auffindbare Abstürze vermeiden wollen.
Wann du ihn nutzt
- ✓Wenn du asynchronen Netzwerkcode in C++ mit Boost.Asio schreibst.
- ✓Wenn du C++-Netzwerkcode auf Fehler bei Lebensdauer oder Threading prüfst.
- ✓Wenn du Asio-Code an eine ältere oder neuere Boost-Version anpassen musst.
Link zum Skill
https://github.com/alirezarezvani/claude-skills/blob/main/engineering/boost-asio-pro/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Schreibe einen einfachen TCP-Echo-Server in C++ mit Boost.Asio, der mit unserer älteren Boost-Version läuft.”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Der Agent prüft zuerst deine Boost-Version und den C++-Standard und wählt dann den passenden Stil, etwa Coroutinen für neuere Toolchains oder Callbacks für ältere. Dabei gelten Regeln für Objektlebensdauern, Strands und Abbruch.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von 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
Häufige Fragen
Warum ist die Boost-Version wichtig?
Die API von Asio hat sich im Laufe der Zeit geändert, und Coroutinen-Beispiele lassen sich auf älteren Toolchains nicht kompilieren.
Welche Stile unterstützt er?
Coroutinen für C++20-Setups und Completion-Handler für ältere Projekte mit C++11 bis C++17.
Vor welchen Fehlern hilft er?
Klassische asynchrone Fehler wie Probleme mit der Lebensdauer und verpasste Abbrüche.
Details
Originalbeschreibung des Autors
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.
Beliebtheit
- GitHub-Sterne
- 29k
- Platz im Ranking
- #9544
- Lizenz
- MIT
- Aktualisiert
- 2.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
agent-launcher-orchestrator
29kBegleitet dich Schritt für Schritt von einer klaren Idee zu einem lauffähigen Claude Managed Agent in deinem eigenen Konto, inklusive Tests und Zeitplan.
grade-iterate
29kLässt die Arbeit eines verwalteten KI-Agenten anhand eines Bewertungsrasters prüfen und in festen Runden verbessern, ohne endlose Schleifen.
interview
29kLässt deinen Agenten dich zu einer KI-Agenten-Idee befragen und deine Antworten in einen einfachen Bauplan verwandeln, bevor etwas gestartet wird.
run-without-you
29kRichtet einen verwalteten KI-Agenten für Zeitpläne oder Ereignisse ein und prüft vor dem Start die Cron-Zeiten, damit nichts schiefläuft.
Ähnliche Skills
api-connector-builder
280kLässt deinen Agenten neue API-Anbindungen nach dem bestehenden Muster bauen. Nutze es, wenn du eine weitere Integration ergänzen willst, ohne neue Wege einzuführen.
api-design
280kHilft deinem Agenten, REST-APIs nach Best Practices zu entwerfen. Nützlich für die Kommunikation, die Fehlerausgabe und die Organisation von Daten.
backend-patterns
280kHilft deinem Agenten bei Architekturmustern für die Serverseite und bei der Datenbankoptimierung. Nützlich zum Bauen und Prüfen von Server-Code.