examples: add minimal multishot echo server#1597
Conversation
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>
| 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! |
- 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
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