poll.7 (2010 09)

p
poll(7) poll(7)
struct pollfd pfd[2];
int err;
pfd[0].fd = fd1;
pfd[0].events = POLLIN;
pfd[1].fd = fd2;
pfd[1].events = (POLLIN | POLLRDBAND);
err = write(evpfd, pfd, sizeof(pfd));
Polling File Descriptors
Polling an event port’s interest set is initiated by calling
ioctl() specifying the DP_POLL
request .
The ioctl arg parameter is a pointer to a
dvpoll structure, defined in <sys/devpoll.h>
.Itcontains
the following members:
struct dvpoll {
pollfd_t *dp_fds; /* pollfd[] to be used */
nfds_t dp_nfds; /* number of pollfd entries */
int dp_timeout; /* milliseconds or -1 */
}
dp_fds is a pointer to an array of pollfd structures. dp_nfds is the maximum number of
pollfd
structures to be returned in that array. dp_timeout is the maximum time, in milliseconds, to wait for
at least one of the registered poll conditions to be met in the event port.
When one or more registered poll conditions are met for any of the registered file descriptors,
ioctl()
stores the valid poll conditions in the revents of each pollfd structure in the array, one array ele-
ment for each active file descriptor. The return value of ioctl() is the number of valid
pollfd struc-
tures.
If no poll conditions are met and if
dp_timeout is -1, ioctl() sleeps until a poll condition is met on
any of the registered file descriptors. If dp_timeout is non-negative,
ioctl() returns after
dp_timeout milliseconds expires or when a poll condition is met. If the time limit expires, the
ioctl()
return value is 0.
Retrieving Registered Poll Conditions for a File Descriptor
The registered poll conditions for a given file descriptor in an interest set can be determined by calling
ioctl() with the DP_ISPOLLED request . For example, for file descriptor fd1:
struct pollfd pfd;
int ispolled;
pfd.fd = fd1;
ispolled = ioctl(evpfd, DP_ISPOLLED, &pfd);
If the file descriptor is registered with the event port, the
ioctl() return value is
1, and the registered
poll conditions are returned in the
events member of the pollfd structure.
The
ioctl() return value is 0 if the file descriptor is not registered or is not open.
Closing an Event Port
An event port is closed with the
close() system call specifying the event port file descriptor. All file
descriptors registered with that event port are automatically deregistered from that event port.
RETURN VALUES
open() returns the event port file descriptor. If the open() system call fails, it returns -1, and errno
is set to the error condition.
write() returns the number of bytes in the array of the pollfd structure that was passed in buf.If
the write() returns -1, errno is set to the error condition.
ioctl(DP_POLL) returns the number of file descriptors for which one or more poll conditions are met.
ioctl(DP_POLL) returns 0 if a timeout occurred before any poll conditions were satisfied for any of
the registered file descriptors.
ioctl(DP_ISPOLLED) returns 1 if the file descriptor specified in the pollfd structure is registered.
ioctl(DP_ISPOLLED) returns 0 if the file descriptor is not registered or is closed.
2 Hewlett-Packard Company 2 HP-UX 11i Version 3: September 2010