Skip to content

Add hash server example and tutorial#203

Merged
sgerbino merged 1 commit intocppalliance:developfrom
sgerbino:pr/hash-server-example
Mar 12, 2026
Merged

Add hash server example and tutorial#203
sgerbino merged 1 commit intocppalliance:developfrom
sgerbino:pr/hash-server-example

Conversation

@sgerbino
Copy link
Collaborator

@sgerbino sgerbino commented Mar 12, 2026

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

  • New Features
    • Added a new example application demonstrating a coroutine-based TCP hash server with asynchronous hash computation and thread pool integration.

Demonstrates combining io_context for network I/O with thread_pool
for CPU-bound work, using capy::run() to switch executors mid-coroutine.
@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Build System Integration
example/CMakeLists.txt, example/Jamfile
Added hash-server subdirectory reference and build target alongside existing echo-server target.
Hash Server Build Configuration
example/hash-server/CMakeLists.txt, example/hash-server/Jamfile
New build configuration files defining the corosio_example_hash_server executable target, dependencies on Boost::corosio, and Boost.Build project setup.
Hash Server Implementation
example/hash-server/hash_server.cpp
New 147-line C++ application implementing a coroutine-based TCP server that accepts connections, reads data, computes FNV-1a hashes asynchronously on a thread pool, and returns hex-encoded results.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hash server hops into view,
With FNV-1a magic through and through,
Threads dance in a pool so grand,
TCP connections hand in hand,
Boost CorosIO stands tall—a builder's dream come true! 🌟

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Add hash server example and tutorial' accurately reflects the main changes, which involve adding a new hash server example to the repository with associated build configuration files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan for PR comments
  • Generate coding plan

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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 a capy::task<> coroutine.

Two optional improvements:

  1. As per coding guidelines, files with non-trivial implementation logic benefit from a /* */ block comment after includes providing a high-level overview.
  2. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6d10efa and 88e89de.

⛔ Files ignored due to path filters (2)
  • doc/modules/ROOT/nav.adoc is excluded by !**/doc/**
  • doc/modules/ROOT/pages/3.tutorials/3e.hash-server.adoc is excluded by !**/doc/**
📒 Files selected for processing (5)
  • example/CMakeLists.txt
  • example/Jamfile
  • example/hash-server/CMakeLists.txt
  • example/hash-server/Jamfile
  • example/hash-server/hash_server.cpp

@cppalliance-bot
Copy link

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

@cppalliance-bot
Copy link

GCOVR code coverage report https://203.corosio.prtest3.cppalliance.org/gcovr/index.html
LCOV code coverage report https://203.corosio.prtest3.cppalliance.org/genhtml/index.html
Coverage Diff Report https://203.corosio.prtest3.cppalliance.org/diff-report/index.html

Build time: 2026-03-12 15:16:45 UTC

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.25%. Comparing base (6d10efa) to head (88e89de).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d10efa...88e89de. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sgerbino sgerbino merged commit 9f057bd into cppalliance:develop Mar 12, 2026
44 checks passed
@sgerbino sgerbino deleted the pr/hash-server-example branch March 12, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants