The method to epoll’s madness

The syntax of epoll

1) epoll_create

#include <sys/epoll.h>
int epoll_create(int size);
int epoll_create1(int flags);

2) epoll_ctl

#include <sys/epoll.h>
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);

3) epoll_wait

#include <sys/epoll.h>
int epoll_wait(int epfd, struct epoll_event *evlist, int maxevents, int timeout);

The gotchas of epoll

The bowels of epoll

Why epoll is more performant that select and poll

int poll(struct pollfd *fds, nfds_t nfds, int timeout);int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

Edge triggered epoll

function Poller:register(fd, r, w)
local ev = self.ev[0]
ev.events = bit.bor(C.EPOLLET, C.EPOLLERR, C.EPOLLHUP)
if r then
ev.events = bit.bor(ev.events, C.EPOLLIN)
end
if w then
ev.events = bit.bor(ev.events, C.EPOLLOUT)
end
ev.data.u64 = fd
local rc = C.epoll_ctl(self.fd, C.EPOLL_CTL_ADD, fd, ev)
if rc < 0 then errors.get(rc):abort() end
end
At t0, input arrives on the socket.
At time t4, the process calls epoll_wait
At time t6, the process calls epoll_wait again

Conclusion

--

--

--

@copyconstruct on Twitter. views expressed on this blog are solely mine, not those of present or past employers.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cindy Sridharan

Cindy Sridharan

@copyconstruct on Twitter. views expressed on this blog are solely mine, not those of present or past employers.

More from Medium

Installing WSL 2 on Windows 10 and Kafka with Confluent Platform on Ubuntu (local environment…

Address Autocomplete: Improving Performance at Scale

photo of intersection of street signs

HarperDB’s Journey on Verizon 5G Edge: Collapsing the stack in a 5G world

Just-in-Time Nomad: Templating HashiCorp Nomad Jobs with Nomad Packs