poll.7 (2010 09)

p
poll(7) poll(7)
If ioctl() returns -1, errno is set to the error condition.
ERRORS
The following errors are returned by the event port driver.
If open() fails, errno is set to one of the following values.
[EACCES] The minor number of the device file name passed to
open() is not 0.
[EAGAIN] Allocation of internal data structures failed due to a temporary condition. Calling
open() again might succeed.
[EMFILE] The maximum number of file descriptors allowed for the process is already open.
[ENFILE] The maximum number of files allowed for the system is already open.
[ENXIO] Some of the requisite file types are not supported by the
/dev/poll driver. See
the WARNINGS section below.
If
write() or ioctl() fails, errno is set to one of the following values.
[EACCES] The calling process did not open the event port.
[EBADF] The filedes argument passed to
write()
is not an open file descriptor.
[EFAULT] An attempt was made to access a
pollfd
structure whose location is outside the
process address space.
[EINTR] A signal interrupted the
ioctl(DP_POLL)
system call.
[EINVAL] The nbyte argument passed to
write() is less than
0.
[ENODEV] The filedes argument passed to
write() is not an event port file descriptor.
EXAMPLES
The following examples show how to use the
/dev/poll driver to poll for events on network socket file
descriptors.
To register a TCP socket file descriptor (
sd) so that ioctl(DP_POLL)
will notify the application when a
new connection is established or when input data is available:
struct pollfd regpfd;
int err;
regpfd.fd = sd;
regpfd.events = POLLIN;
err = write(evpfd, &regpfd, sizeof(regpfd));
POLLRDBAND should be ORed with POLLIN if the application needs to distinguish the arrival of out-of-
band data.
To wait for events on one or more registered sockets, up to 100 connections:
struct pollfd pollpfd[100];
struct dvpoll dvp;
int npoll;
dvp.dp_fds = pollpfd;
dvp.dp_nfds = 100;
dvp.dp_timeout = -1;
npoll = ioctl(evpfd, DP_POLL, &dvp);
If a non-blocking write to a socket is incomplete, the following can be used to register the socket so that
ioctl(DP_POLL) will notify the application when the socket is writable again later. Typically, the
socket is already registered to receive input notifications. The following will add the POLLOUT
notification.
struct pollfd regpfd;
int err;
regpfd.fd = sd;
regpfd.events = POLLOUT;
err = write(evpfd, &regpfd, sizeof(regpfd));
HP-UX 11i Version 3: September 2010 3 Hewlett-Packard Company 3