|
Description
The poll() function provides the user with a mechanism for multiplexing the input/output via a set of file descriptors which refer to open files.
More general information on this function is available in the manual "C Library Functions for POSIX Applications".
poll() identifies the descriptors on which
the program can receive messages,
the program can send messages or
specific events have occurred.
The fds parameter defines the descriptors to be tested and the events which are of interest for each descriptor. fds points to an array with one member for each open descriptor.
The pollfd structure is declared as follows:
struct pollfd { int fd; /* file descriptor */ short events; /* requested events */ short revents; /* reported events */ };
The member fd designates a socket file descriptor. The members events (events to be queried for the socket) and revents (events returned for the socket) are bit masks constructed by ORing any combination of the event indicators described below.
POLLIN
Data can be read non-blocking, or a connection request can be accepted non-blocking with accept().
POLLOUT
Data can be written non-blocking.
POLLRDNORM
Like POLLIN.
POLLWRNORM
Like POLLOUT.
POLLERR
An error was reported for the socket.
This option is only valid in the revents bit mask, it is not used in the events bit mask.
POLLHUP
A hangup event (disconnection) has occurred. POLLHUP and POLLOUT are mutually exclusive. If a hangup has occurred, a socket can never be written to. However, POLLHUP and POLLIN are not mutually exclusive.
This option is only valid in the revents bit mask, it is not used in the events bit mask.
POLLNVAL
The specified fd value does not belong to an open file.
This option is only valid in the revents bit mask, it is not used in the events bit mask.
For each member of the vector to which fds points, poll() tests the specified file descriptor fd for the event(s) specified in events. The number of file descriptors to be tested is specified by nfds.
If the file descriptor fd is less than 0, then events is ignored and the revents bit mask is set to zero in this entry when poll() returns.
The results of the poll() call are stored in revents. Bits are set in the revents bit mask to indicate which of the requested events are true. If no events are true, none of the bits in revents are set when the poll() call returns. The bits POLLHUP, POLLERR and POLLNVAL are always set in revents if the conditions indicated by them are true. This is also the case if these bits were not set in the events bit mask.
If none of the events occurs at any of the specified file descriptors, poll() waits at least timeout milliseconds for the occurrence of at least one event at one of the specified file descriptors.
poll() returns immediately if the value of timeout is 0. If the value of timeout is INFTIM (or -1), poll() blocks until an event occurs or the call is interrupted.
poll() is not affected by the O_NDELAY and O_NONBLOCK switches.
Return value
0:
Indicates that the time for the call has expired and no file descriptors were selected.
>0:
A positive number indicates the total number of currently selected file descriptors, i.e. file descriptors for which the revents bit mask is not zero.
-1:
If errors occur. errno is set to indicate the error.
Errors
EAGAIN
The assignment of the internal data structures failed, but the request should be retried.
EFAULT
A parameter refers to an address outside the assigned address range.
EINTR
A signal was caught during the poll() call.
EINVAL
The nfds parameter is less than zero or greater than OPEN_MAX.