Skip to content

examples: add minimal multishot echo server#1597

Merged
axboe merged 1 commit into
axboe:masterfrom
Kprateek283:add-multishot-echo-server
Jun 10, 2026
Merged

examples: add minimal multishot echo server#1597
axboe merged 1 commit into
axboe:masterfrom
Kprateek283:add-multishot-echo-server

Conversation

@Kprateek283

@Kprateek283 Kprateek283 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Add a minimal multishot echo server example demonstrating:

  • Multishot accept
  • Multishot receive
  • Provided buffer rings

This provides a simpler networking example than proxy.c for developers learning modern io_uring APIs.
Related: #1596

Comment thread examples/echo-server.c Outdated
struct io_uring_sqe *sqe;

sqe = get_sqe();
if (!sqe)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

These should probably be fatal conditions, not silently ignored. There are a few of those. It's really a "this should never happen" scenario, hence could be an assert() too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I've updated it to be a fatal error via exit(1). I chose exit(1) over assert() to ensure the failure is still caught and the error message is printed even when the example is compiled with -DNDEBUG.

Comment thread examples/echo-server.c

count = 0;
io_uring_for_each_cqe(&ring, head, cqe) {
switch (decode_type(cqe->user_data)) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Should probably have a default: error case?

@Kprateek283 Kprateek283 Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right. Added a default: case with exit(1). An unknown event type should be impossible, so this is a fatal logic error rather than a recoverable condition.

@axboe

axboe commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Just a few minor comments, overall looks nice and simple and agree this would be a good example to add!

@axboe

axboe commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Can you squash the two commits? Mostly just so that intermediate state doesn't show up in the tree, but also because you didn't add your SOB to commit 2.

    Adds a basic echo server to demonstrate modern io_uring networking
    best practices including:
    - Multishot accept
    - Multishot receive
    - Provided buffer rings with proper lifecycle management

    This serves as a simpler entry point than proxy.c for beginners
    learning the API.

Signed-off-by: Prateek <kprateek283@gmail.com>
@Kprateek283 Kprateek283 force-pushed the add-multishot-echo-server branch from 856bbbb to 395f27d Compare June 10, 2026 12:00
@Kprateek283

Copy link
Copy Markdown
Contributor Author

Done. Please let me know if it requires any further input from my side.

@axboe axboe merged commit 41533f6 into axboe:master Jun 10, 2026
20 checks passed
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