examples: add minimal multishot echo server#1597
Conversation
| struct io_uring_sqe *sqe; | ||
|
|
||
| sqe = get_sqe(); | ||
| if (!sqe) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
||
| count = 0; | ||
| io_uring_for_each_cqe(&ring, head, cqe) { | ||
| switch (decode_type(cqe->user_data)) { |
There was a problem hiding this comment.
Should probably have a default: error case?
There was a problem hiding this comment.
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.
|
Just a few minor comments, overall looks nice and simple and agree this would be a good example to add! |
|
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>
856bbbb to
395f27d
Compare
|
Done. Please let me know if it requires any further input from my side. |
Add a minimal multishot echo server example demonstrating:
This provides a simpler networking example than proxy.c for developers learning modern io_uring APIs.
Related: #1596