Add hash server example and tutorial#203
Conversation
Demonstrates combining io_context for network I/O with thread_pool for CPU-bound work, using capy::run() to switch executors mid-coroutine.
📝 WalkthroughWalkthroughThis change introduces a new hash-server example application to the project. The updates include build configuration files in both CMake and Jamfile formats to integrate the new example into the existing build system, along with a complete C++ implementation of a TCP-based hash server that computes FNV-1a hashes asynchronously using a thread pool. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Acceptor as TCP Acceptor
participant Session as do_session()
participant Pool as Thread Pool
participant Hash as compute_fnv1a()
Client->>Acceptor: Connect to port
Acceptor->>Session: Spawn new session (coroutine)
Session->>Session: Read data from socket
Session->>Pool: Offload hash computation
Pool->>Hash: Execute FNV-1a algorithm
Hash-->>Pool: Return hash value (64-bit)
Pool-->>Session: Resume coroutine
Session->>Session: Format hash as hex string
Session->>Client: Send hex result
Session->>Session: Close socket
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan for PR comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
example/hash-server/hash_server.cpp (1)
58-90: Consider adding a brief overview comment and optionally logging write errors.The Cppcheck warning about "missing return statement" at line 74 is a false positive—
co_return;is the correct way to exit acapy::task<>coroutine.Two optional improvements:
- As per coding guidelines, files with non-trivial implementation logic benefit from a
/* */block comment after includes providing a high-level overview.- Lines 86-87 silently discard write errors. For a tutorial example, logging the error could help users debug connection issues.
💡 Optional: log write errors for debugging
auto [wec, wn] = co_await capy::write( sock, capy::const_buffer( result.data(), result.size() ) ); - (void)wec; - (void)wn; + if (wec) + std::cerr << "Write error: " << wec.message() << "\n"; + (void)wn;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@example/hash-server/hash_server.cpp` around lines 58 - 90, Add a short block comment after the includes describing the purpose of this file (high-level flow: accept connection, read, compute FNV-1a hash on thread pool, write hex result, close socket) and update do_session to not silently discard write errors: when co_await capy::write(...) returns (wec, wn) check wec and log or report the error (include context like socket id or that the write failed after compute_fnv1a/to_hex) before closing sock; keep the existing co_return usage for coroutine exit unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@example/hash-server/hash_server.cpp`:
- Around line 58-90: Add a short block comment after the includes describing the
purpose of this file (high-level flow: accept connection, read, compute FNV-1a
hash on thread pool, write hex result, close socket) and update do_session to
not silently discard write errors: when co_await capy::write(...) returns (wec,
wn) check wec and log or report the error (include context like socket id or
that the write failed after compute_fnv1a/to_hex) before closing sock; keep the
existing co_return usage for coroutine exit unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 06e6c675-7c1f-4fcb-9285-145dd225014c
⛔ Files ignored due to path filters (2)
doc/modules/ROOT/nav.adocis excluded by!**/doc/**doc/modules/ROOT/pages/3.tutorials/3e.hash-server.adocis excluded by!**/doc/**
📒 Files selected for processing (5)
example/CMakeLists.txtexample/Jamfileexample/hash-server/CMakeLists.txtexample/hash-server/Jamfileexample/hash-server/hash_server.cpp
|
An automated preview of the documentation is available at https://203.corosio.prtest3.cppalliance.org/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-03-12 15:06:59 UTC |
|
GCOVR code coverage report https://203.corosio.prtest3.cppalliance.org/gcovr/index.html Build time: 2026-03-12 15:16:45 UTC |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #203 +/- ##
========================================
Coverage 76.25% 76.25%
========================================
Files 99 99
Lines 10570 10570
Branches 2407 2407
========================================
Hits 8060 8060
Misses 1797 1797
Partials 713 713 Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Demonstrates combining io_context for network I/O with thread_pool for CPU-bound work, using capy::run() to switch executors mid-coroutine.
Summary by CodeRabbit