I assume by "how epoll works" you're referring to how it works from the user point of view (as in, how your code gets notified, and should deal with it), as opposed to the kernel point of view (as in, how epoll is implemented).
The short version is very simple: It's just like poll
, except for two things:
- It uses a handle to an opaque data structure so you're not passing as much data back and forth across the kernel boundary.
- It has options that
poll
doesn't have (notably edge triggering and one-shot notifications) that can let you write more efficient code in certain situations.
(There's also the fact that it only works on linux. BSD and related systems have kqueue
, a significantly different way to get some of the same advantages, Solaris has /dev/poll
, etc., and some *nixes have nothing equivalent. So if you want to write portable code, you either have to use poll
, or use some higher-level library like libevent
, or write the equivalent of libevent
yourself.)
If you already understand select
and poll
, the the Wikipedia article and the blog post linked in its References should, between them, tell you almost everything you need to know, and the man page will fill in any gaps.
If not, go learn about poll
first, and only then will it make sense to learn how epoll
is different.
I'm still not sure how this relates to your main question at all. You can epoll
an inotify
on a database file, or a pipe
or socket
underlying a messaging system, or just about anything else that can be represented as a file descriptor in linux, so I'm not sure how understanding epoll
will help you explain the differences between polling a database vs. polling a message queue. There are of course vast differences between the two, but the event-triggering mechanism is not one of them.
http://en.wikipedia.org/wiki/Epoll
, orhttp://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html
, both of which have general explanations? Also, I'm not sure how explainingepoll
will help explain the difference you're discussing. You canepoll
an inotify on the database file, or you canepoll
the queue underneath your messaging system, so… what are you aiming at? – Institutionalize