We discussed in part 1 that because select(), poll() and epoll report operations on local / regular files as always being in a ready state, libraries

io_uring By Example: Part 3 – A Web Server with io_uring

submited by
Style Pass
2022-09-21 20:30:25

We discussed in part 1 that because select(), poll() and epoll report operations on local / regular files as always being in a ready state, libraries like libuv (this one powers NodeJS) use a separate thread pool at deal with file I/O. One huge advantage with io_uring is that it presents a single, clean uniform and above all, working interface for many types of I/O.

In this example, we’ll look at an additional operation, accept() and how to do it using io_uring. Throw in operations for readv() and writev(), you have the capability to write a simple web server! This web server is based on code I wrote for ZeroHTTPd, a program that features in an article series I wrote to explore various Linux process models and how they perform compared to each other. I’ve rewritten ZeroHTTPd to use the io_uring interface exclusively.

Before anything else, the main() function calls setup_listening_socket() to listen on the designated port. But we do not call accept() to actually accept connections. We do that through a request to io_uring as explained later.

Leave a Comment