boost-asio-pro
Skill này làm gì
Công cụ này giúp viết mã mạng C++ hoạt động bất đồng bộ (không làm đơ chương trình). Nó xử lý các kết nối mạng như TCP và UDP, bảo mật SSL/TLS, bộ hẹn giờ và các thao tác khác không cần chờ nhau.
Khi nào nên dùng
- ✓Khi tạo máy chủ hoặc client mạng bằng C++.
- ✓Khi mã cần xử lý nhiều kết nối cùng lúc mà không bị đơ.
- ✓Khi dùng các thư viện như Boost.Asio hoặc Asio cho các tác vụ mạng.
Liên kết skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/boost-asio-pro/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Làm sao để tạo một máy chủ TCP đơn giản bằng C++ với Boost.Asio, lắng nghe các kết nối?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Công cụ kiểm tra phiên bản Boost/Asio bạn đang dùng và tuân theo các quy tắc cụ thể cho phiên bản đó. Nó chú ý đến các chi tiết quan trọng như thời gian sống của dữ liệu và cách quản lý thao tác bất đồng bộ để tránh lỗi thường gặp.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Asio's API changed shape three times, so the same task has three correct answers depending on the Boost version in front of you. This skill makes the agent establish that version first, then apply the rules that are genuinely easy to get wrong — strand versus write serialization, buffer and connection lifetime, composed reads for framing — and finally check its own output against a list before calling it done.
When to Use This Skill
- Use when writing or reviewing async C++ networking code with Boost.Asio or standalone Asio: TCP/UDP servers and clients, SSL/TLS streams, timers, resolvers.
- Use when the code involves
io_context,io_service,co_spawn,awaitable,async_read,async_write,strand,asio::spawn,yield_context, or completion-handler callbacks. - Use when the target toolchain is old: an older Boost or a pre-C++20 standard, where coroutine examples will not compile.
- Use when async code compiles but misbehaves: interleaved writes, dangling buffers, sockets closing early,
operation_abortedtreated as an error.
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.
…
Câu hỏi thường gặp
“Bất đồng bộ” nghĩa là gì?
Nghĩa là chương trình có thể làm việc khác trong khi chờ một thao tác mạng hoàn tất, thay vì dừng lại và chờ.
Khác biệt giữa Boost.Asio và Asio là gì?
Boost.Asio là một phần của thư viện Boost, còn Asio (standalone) có thể dùng mà không cần toàn bộ Boost. Hai cái hoạt động khá giống nhau.
Tại sao có các “kiểu” khác nhau?
API của Asio (cách sử dụng) đã thay đổi theo thời gian. Các kiểu khác nhau tương ứng với những thay đổi này, để đảm bảo tương thích với các phiên bản C++ và Boost cũ hoặc mới.
Chi tiết
Mô tả gốc của tác giả
Use when writing asynchronous C++ networking code with Boost.Asio or standalone Asio — TCP/UDP servers and clients, SSL/TLS, timers, strands, composed async ops. Covers io_context, co_spawn, awaitable, async_read/async_write, asio::spawn, yield_context, and pre-C++20 callback styles.
Độ phổ biến
- Sao GitHub
- 48k
- Vị trí xếp hạng
- #4043
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
00-andruia-consultant
48kGiúp agent của bạn bắt đầu hoặc cải thiện các dự án AI. Phân tích mã, gợi ý công cụ và lập kế hoạch hành động bằng tiếng Tây Ban Nha.
007
48kCho phép agent của bạn thực hiện kiểm toán bảo mật và mô hình hóa mối đe dọa. Hữu ích để bảo vệ dự án khỏi các cuộc tấn công và lỗ hổng.
10-andruia-skill-smith
48kGiúp agent của bạn tạo hoặc cải thiện các công cụ AI. Xác định cách công cụ hoạt động, viết tài liệu và kiểm tra cấu trúc.
20-andruia-niche-intelligence
48kGiúp agent của bạn tạo bản tóm tắt về một ngành cụ thể. Hữu ích để hiểu bối cảnh, quy tắc, cách người dùng tương tác và rủi ro của dự án.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.