Monitors conditions on multiple file descriptors. Format #include <poll.h> int poll (struct pollfd fds[], nfds_t nfds, int timeout);
1 – Arguments
fds An array of pollfd structures, one for each file descriptor of interest. Each pollfd structure includes the following members: int fd The file descriptor int events The requested conditions int revents The reported conditions nfds The number of pollfd structures in the fds array. timeout The maximum length of time (in milliseconds) to wait for one of the specified events to occur.
2 – Description
This function provides applications with a mechanism for multiplexing input/output over a set of file descriptors. For each member of the array pointed to by fds, poll() examines the given file descriptor for the events specified in events. The number of pollfd structures in the fds array is specified by nfds. The poll() function identifies those file descriptors on which an application can read or write data, or on which certain events have occurred. The fds argument specifies the file descriptors to be examined and the events of interest for each file descriptor. It is a pointer to an array with one member for each open file descriptor of interest. The array's members are pollfd structures within which fd specifies an open file descriptor, and events and revents are bitmasks constructed by OR-ing a combination of the following event flags: o POLLIN Normal data may be received without blocking. o POLLRDNORM Same as POLLIN. o POLLRDBAND Out-of-band data may be received without blocking. o POLLPRI Same as POLLRDBAND o POLLOUT Normal data may be written without blocking. o POLLWRNORM Same as POLLOUT. o POLLWRBAND Out-of-band data may be written without blocking. If the value of fd is less than 0, events is ignored and revents is set to 0 in that entry on return from poll(). In each pollfd structure, poll() clears the revents member except that where the application requested a report on a condition by setting one of the bits of events listed above, poll() sets the corresponding bit in revents if the requested condition is true. If none of the defined events have occurred on any selected file descriptor, poll() waits at least timeout milliseconds for an event to occur on any of the selected file descriptors. If the value of timeout is 0, poll() returns immediately. If the value of timeout is -1, poll() blocks until a specified event occurs or until the call is interrupted. The poll() function is not affected by the O_NONBLOCK flag. On OpenVMS, the poll() function supports sockets only. NOTE HP recommends using the select() function for optimal performance. The poll() function is provided to ease the porting of existing applications from other platforms.
3 – Return Values
positive value Upon successful completion, the total number of file descriptors selected (that is, file descriptors for which the revents member is nonzero). 0 Successful completion. The call timed out and no file descriptors were selected. -1 The poll() function failed. The errno is set to indicate the error.
4 – Errors
EAGAIN The allocation of internal data structures failed but a subsequent request may succeed. EINTR A signal was caught during the poll() function.