TCP Server in Zig - Part 6 - Epoll
More from openmymind.net
In the last post, we looked at some of Zig' weirder syntax. Specifically, this line of code: var gpa = std.heap.GeneralPurposeAllocator(.{}){}; While you'll commonly run into the above when looking at Zig code or going through Zig learning resources, some people pointed out that the code could be improved by doing: var gpa:...
One of the first pieces of Zig code that you're likely to see, and write, is this beginner-unfriendly line: var gpa = std.heap.GeneralPurposeAllocator(.{}){}; While we can reason that we're creating an allocator, the (.{}){} syntax can seem a bit much. This is a combination of three separate language features: generics, anonymous struct literals...
Now that we're more familiar with epoll and kqueue individually, it's time to bring everything together. We'll begin by looking at the possible interaction between evented I/O and threads and then look at writing a basic cross-platform abstraction over the platform-specific epoll and kqueue. Evented I/O + Multithreading We began our journey with...
kqueue is a BSD/MacOS alternative over poll. In most ways, kqueue is similar to the Linux-specific epoll, which itself is important, but important, incremental upgrade to poll. Because kqueue has a single function it superficially looks like poll. But, as we'll soon see, that single function can behave in two different ways, making its API and...
In the previous part we introduced non-blocking sockets and used them, along with the poll system call, to maximize the efficiency of our server. Rather than having a thread-per-connection, waiting on data, a single thread can now manage multiple client connections. But this performance leap doesn't come for free: our code has gotten more...