Epoll
Encyclopedia
epoll
is a scalable I/O event notification mechanism for LinuxLinux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
, first introduced in Linux 2.5.44 . It is meant to replace the older POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...
select(2)
Select (Unix)
select is a system call and application programming interface in Unix-like and POSIX-compliant operating systems for examining the status of file descriptors of open input/output channels...
and
poll(2)
system callsSystem call
In computing, a system call is how a program requests a service from an operating system's kernel. This may include hardware related services , creating and executing new processes, and communicating with integral kernel services...
, to achieve better performance in more demanding applications, where the number of watched file descriptors
File descriptor
In computer programming, a file descriptor is an abstract indicator for accessing a file. The term is generally used in POSIX operating systems...
is large (unlike the older system calls, which operate at O(n),
epoll
operates in O(1) ). epoll
is similar to FreeBSDFreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...
's
kqueue
Kqueue
Kqueue is a scalable event notification interface introduced in FreeBSD 4.1, also supported in NetBSD, OpenBSD, DragonflyBSD, and Mac OS X. It's the foundation of Apple's Grand Central Dispatch....
, in that it operates on a configurable kernel object, exposed to user space
User space
A conventional computer operating system usually segregates virtual memory into kernel space and user space. Kernel space is strictly reserved for running the kernel, kernel extensions, and most device drivers...
as a file descriptor of its own.
API
Creates an
epoll
object and returns its file descriptor.Controls (configures) which file descriptors are watched by this object, and for which events.
Waits for any of the registered events, until at least one occurs or the timeout elapses.
Triggering Modes
epoll
provides both edge-triggered and level-triggered modes. In edge-triggered mode, a call to epoll_wait
will return only when a new event is enqueued with the epoll
object, while in level-triggered mode, epoll_wait
will return as long as the condition withholds.For instance, if a pipe
Anonymous pipe
In computer science, an anonymous pipe is a simplex FIFO communication channel that may be used for one-way interprocess communication . An implementation is often integrated into the operating system's file IO subsystem...
, registered with
epoll
, has received data, a call to epoll_wait
will return, signaling the presence of data to be read. Suppose the reader only consumed part of data from the buffer. In level-triggered mode, further calls to epoll_wait
will return immediately, as long as the pipe's buffer contains data to be read. In edge-triggered mode, however, epoll_wait
will return only once new data is written to the pipe.