poll.h File

Purpose

Defines the structures and flags used by the poll subroutine.

Description

The /usr/include/sys/poll.h file defines several structures used by the poll subroutine. An array of pollfd or pollmsg structures or a pollist structure specify the file descriptors or pointers and message queues for which the poll subroutine checks the I/O status. This file also defines the returned events flags, error returned events flags, device-type flags and input flags used in polling operations.

During a polling operation on both file descriptors and message queues, the ListPointer parameter points to a pollist structure, which can specify either file descriptors or pointers and message queues. The program must define the pollist structure in the following form:

struct pollist {
   struct pollfd fdlist[f];
   struct pollmsg msglist[m];
};

The pollfd structure and the pollmsg structure in the pollist structure perform the following functions:

Item Description
pollfd[f] This structure defines an array of file descriptors or file pointers. The f variable specifies the number of elements in the array.
pollmsg[m] This structure defines an array of message queue identifiers. The m variable specifies the number of elements in the array.

A POLLIST macro is also defined in the poll.h file to define the pollist structure. The format of the macro is:

POLLIST(f, m) Declarator . . . ;

The Declarator parameter is the name of the variable that is declared as having this type.

The pollfd and pollmsg structures defined in the poll.h file contain the following fields:

Item Description
fd Specifies a valid file descriptor or file pointer to the poll subroutine. If the value of this field is negative, this element is skipped.
msgid Specifies a valid message queue ID to the poll subroutine. If the value of this field is negative, this element is skipped.
events The events being tracked. This is any combination of the following flags:
POLLIN
Input is present on the file or message queue.
POLLOUT
The file or message queue is capable of accepting output.
POLLPRI
An exceptional condition is present on the file or message queue.
revents Returned events. This field specifies the events that have occurred. This can be any combination of the events requested by the events field. This field can also contain one of the following flags:
POLLNVAL
The value specified by the fd field or the msgid field is neither a valid file descriptor or pointer nor the identifier of an accessible message queue.
POLLERR
An error condition arose on the specified file or message queue.