ocean.sys.EventFD

Linux custom file descriptor event.

eventfd man page follows:

Creates an "eventfd object" that can be used as an event wait/notify mechanism by userspace applications, and by the kernel to notify userspace applications of events. The object contains an unsigned 64-bit integer (ulong) counter that is maintained by the kernel.

The following operations can be performed on the file descriptor:

read(2) If the eventfd counter has a nonzero value, then a read(2) returns 8 bytes containing that value, and the counter's value is reset to zero. (The returned value is in host byte order, i.e., the native byte order for integers on the host machine.) If the counter is zero at the time of the read(2), then the call either blocks until the counter becomes nonzero, or fails with the error EAGAIN if the file descriptor has been made non-blocking (via the use of the fcntl(2) F_SETFL operation to set the O_NONBLOCK flag).

A read(2) will fail with the error EINVAL if the size of the supplied buffer is less than 8 bytes.

write(2) A write(2) call adds the 8-byte integer value supplied in its buffer to the counter. The maximum value that may be stored in the counter is the largest unsigned 64-bit value minus 1 (i.e., 0xfffffffffffffffe). If the addition would cause the counter's value to exceed the maximum, then the write(2) either blocks until a read(2) is performed on the file descriptor, or fails with the error EAGAIN if the file descriptor has been made non-blocking. A write(2) will fail with the error EINVAL if the size of the supplied buffer is less than 8 bytes, or if an attempt is made to write the value 0xffffffffffffffff.

poll(2), select(2) (and similar) The returned file descriptor supports poll(2) (and analogously epoll(7)) and select(2), as follows:

The file descriptor is readable (the select(2) readfds argument; the poll(2) POLLIN flag) if the counter has a value greater than 0.

The file descriptor is writable (the select(2) writefds argument; the poll(2) POLLOUT flag) if it is possible to write a value of at least "1" without blocking.

The file descriptor indicates an exceptional condition (the select(2) exceptfds argument; the poll(2) POLLERR flag) if an overflow of the counter value was detected. As noted above, write(2) can never overflow the counter. However an overflow can occur if 2^64 eventfd "signal posts" were performed by the KAIO subsystem (theoretically possible, but practically unlikely). If an overflow has occurred, then read(2) will return that maximum uint64_t value (i.e., 0xffffffffffffffff). The eventfd file descriptor also supports the other file-descriptor multiplexing APIs: pselect(2), ppoll(2), and epoll(7).

close(2) When the file descriptor is no longer required it should be closed. When all file descriptors associated with the same eventfd object have been closed, the resources for object are freed by the kernel.

A copy of the file descriptor created by eventfd() is inherited by the child produced by fork(2). The duplicate file descriptor is associated with the same eventfd object. File descriptors created by eventfd() are preserved across execve(2).

Members

Classes

EventFD
class EventFD

Event fd class

Meta

License

Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. Alternatively, this file may be distributed under the terms of the Tango 3-Clause BSD License (see LICENSE_BSD.txt for details).