boost-asio-pro
Fungsinya
Skill ini memandu agent menulis kode jaringan C++ async dengan Boost.Asio atau Asio mandiri. Skill ini untuk pengembang C++ yang membangun server dan klien TCP, UDP, atau SSL dan ingin menghindari crash yang sulit ditemukan.
Kapan dipakai
- βSaat Anda menulis kode jaringan async di C++ dengan Boost.Asio.
- βSaat Anda meninjau kode jaringan C++ dari masalah masa hidup objek atau threading.
- βSaat Anda perlu mencocokkan kode Asio dengan versi Boost yang lebih lama atau lebih baru.
Link skill
https://github.com/alirezarezvani/claude-skills/blob/main/engineering/boost-asio-pro/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βTulis server echo TCP sederhana di C++ dengan Boost.Asio yang berfungsi dengan versi Boost kami yang lebih lama.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Agent pertama-tama memeriksa versi Boost dan standar C++ Anda, lalu memilih gaya yang sesuai, seperti coroutine untuk toolchain yang lebih baru atau callback untuk yang lebih lama. Agent menerapkan aturan tentang masa hidup objek, strand, dan pembatalan.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum
Mengapa versi Boost penting?
API Asio telah berubah seiring waktu, dan contoh coroutine tidak akan dikompilasi pada toolchain yang lebih lama.
Gaya apa saja yang didukung?
Coroutine untuk pengaturan C++20, dan completion handler untuk proyek yang lebih lama atau C++11 sampai C++17.
Bug apa yang membantu dihindari?
Bug async klasik seperti masalah masa hidup dan pembatalan yang terlewat.
Detail
Deskripsi asli dari pembuat
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.
Popularitas
- Bintang GitHub
- 29k
- Peringkat
- #9544
- Lisensi
- MIT
- Diperbarui
- 2/11/2026
Komentar
- β¦
Skill lain dari repositori ini
agent-launcher-orchestrator
29kMembantu agent Anda merencanakan, membangun, menguji, dan menjadwalkan agent Claude terkelola di akun Anda sendiri, langkah demi langkah.
grade-iterate
29kMembantu agent Anda menilai hasil kerja agent AI terkelola berdasarkan rubrik dan memperbaikinya dalam jumlah putaran tetap, agar tidak berputar tanpa henti.
interview
29kMembantu agent Anda mewawancarai Anda tentang ide agent AI dan mengubah jawaban Anda menjadi rencana pembangunan sederhana sebelum apa pun diluncurkan.
run-without-you
29kMembantu agent Anda disiapkan agar berjalan tanpa Anda sesuai jadwal atau saat sebuah peristiwa terjadi, dengan waktu cron diperiksa sebelum peluncuran.
Skill serupa
api-connector-builder
280kMembuat agent Anda membangun koneksi API baru mengikuti pola yang sudah ada. Gunakan saat ingin menambah integrasi lagi tanpa membuat cara baru.
api-design
280kMembantu agent Anda merancang REST API sesuai praktik terbaik. Berguna untuk mengatur cara API berkomunikasi, menampilkan error, dan mengorganisasi data.
backend-patterns
280kMembantu agent Anda dengan pola arsitektur sisi server dan optimasi database. Berguna untuk membangun atau meninjau kode yang berjalan di server.