poll.7 (2010 09)

p
poll(7) poll(7)
NAME
poll - monitor I/O conditions on multiple file descriptors
SYNOPSIS
#include <sys/devpoll.h> #include <fcntl.h>
int open("/dev/poll", O_RDWR);
int write(int filedes, const struct pollfd *buf, size_t nbyte);
int ioctl(int filedes, DP_POLL, struct dvpoll *arg);
int ioctl(int filedes, DP_ISPOLLED, struct pollfd *arg);
DESCRIPTION
/dev/poll provides an interface to the event port driver allowing a user to synchronously monitor a
specific set of conditions associated with a registered set of file descriptors. Poll conditions include the
ability to read or write data without blocking and certain exceptional conditions.
Access to
/dev/poll is provided through the
open(), write(), and ioctl() system calls.
The
/dev/poll event port provides functionality comparable to the
select(2) and poll(2)
system
calls and supports the following types of file descriptors: network (
AF_INET) and Unix Domain
(
AF_UNIX) sockets, named FIFO files and pipes, XTI endpoints, and STREAMS devices.
General operations supported by the event port driver are:
-- Opening an event port.
-- Registering and deregistering file descriptors on an event port.
-- Polling registered file descriptors on an event port.
-- Retrieving registered poll conditions for a file descriptor.
-- Closing an event port.
Opening An Event Port
Each open of the /dev/poll device enables an event port from which a different set of file descriptors
can be polled. The file descriptor returned by the open() system call represents the event port. Users
wishing to monitor multiple sets of file descriptors should open the /dev/poll device multiple times.
For example:
int evpfd;
evpfd = open("/dev/poll", O_RDWR);
Only the process that performed the open() on /dev/poll can perform general event port operations.
Specifically, any event port file descriptor inherited by a child from its parent or that is received from
another process using the Unix Domain Sockets access rights can only be closed. (See sendmsg in the
send(2) man page or the STREAMS I_FDINSERT ioctl request in the streamio (7) man page.)
Registering and Deregistering File Descriptors
An interest set of file descriptors and poll conditions is registered with an event port by using the
write() system call. By writing an array of pollfd structures to an event port the user can register
multiple file descriptors in one write() service call. The pollfd structure and related poll conditions
are defined in <poll.h>, (included by <sys/devpoll.h>). Other flags are defined in the
<sys/devpoll.h> file. See the poll (2) man page for the definition of the poll conditions.
To register a file descriptor, the
fd field is set to the file descriptor to be registered, and the events field
is set to one or more poll conditions, such as POLLIN. Multiple poll conditions can be ORed together. A
given file descriptor can be registered with multiple event ports. Re-registering a file descriptor with the
same event port will cause the the specified poll conditions to join the previous conditions for the given
file descriptor.
To deregister,
fd is set to the file descriptor to be deregistered, and events is set to POLLREMOVE.
POLLREMOVE is defined in <sys/devpoll.h>. POLLREMOVE must not be ORed together with any
other poll conditions.
When a polled file descriptor is closed, it is automatically deregistered.
Continuing our example, the following registers two file descriptors on the opened event port,
fd1 and
fd2:
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (6 pages)