#define POLLIN 0b00000001 #define POLLOUT 0b00000010 #define POLLPRI 0b00000100 #define POLLHUP 0b00001000 #define POLLERR 0b00010000 #define POLLNVAL 0b01000000 struct pollfd { uint32_t fd; uint16_t events; uint16_t revents; }; int poll(struct pollfd *fds, nfds_t nfds, struct timespec *timeout, const sigset_t *sigmask);
This syscall allows to wait for a series of events to happen to the passed
FDs, in a manner similar to POSIX’s select.
fds is an array of nfds length of pollfd structures. Each
structure represents one FD, for which events is a list of events
to wait for and revents is a bitmap written by the kernel to indicate
which events of the waited ones did happen. If the FD of an structure is
negative, that is, it has the first bit set, it is ignored, and revents
is set to 0.
If passed no FDs to ppoll, that is, with nfds == 0, ppoll will
block for timeout time. This is used by some software as a means to
implement sleep/pause functionality, for those cases,
clock_nanosleep.
If sigmask is not NULL, it will atomically set the passed
sigmask for waiting.
Both events and revents are bitmaps of the values:
POLLINThe passed FD has data pending for reading.
POLLOUTThe passed FD will not block when written to.
POLLPRIThe passed FD has prioritary data for processing, this data depends on what is polled, some examples are a change of termios information on a PTY, or Out-Of-Band (OOB) data for a TCP socket.
POLLERROnly for revents, it is set when encountering an error waiting. This bit
is also set for FDs referring to the write end of a pipe when the read end has
been closed.
POLLHUPOnly for revents, it is set in the case of the passed FD having lost
connection, or the FD being the reader end of a broken pipe.
POLLNVALOnly for revents, equivalent of EBADFD, that is, the passed FD
is not valid.
The call will block until either a file descriptor gets an event, the call is interrupted by a signal handler, or the timeout expires.
The syscall returns the number of FDs to have an event happen on success or
-1 on failure, with the following errno:
EFAULTThe passed pointers are not in addressable memory.
EINVALThe passed values are not valid.