Skip to content

examples: add minimal multishot echo server#1597

Open
Kprateek283 wants to merge 2 commits into
axboe:masterfrom
Kprateek283:add-multishot-echo-server
Open

examples: add minimal multishot echo server#1597
Kprateek283 wants to merge 2 commits into
axboe:masterfrom
Kprateek283:add-multishot-echo-server

Conversation

@Kprateek283

@Kprateek283 Kprateek283 commented Jun 9, 2026

Copy link
Copy Markdown

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

Add a basic echo server demonstrating modern io_uring networking
features including:

- Multishot accept
- Multishot receive
- Provided buffer rings with proper lifecycle management

This example provides a simpler entry point than proxy.c for
developers learning the networking API.

Signed-off-by: Prateek <kprateek283@gmail.com>
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
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
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!

    - Make get_sqe() failure fatal with exit(1) instead of returning NULL
    - Remove dead NULL checks in multishot accept/recv/send callers
    - Add default error case to event_loop switch statement for unknown CQEs
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