HP-UX Reference (11i v1 00/12) - 2 System Calls (vol 5)

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man2/!!!intro.2
________________________________________________________________
___ ___
p
poll(2) poll(2)
POLLMSG A M_SIG or M_PCSIG message specifying SIGPOLL has reached the front of
the stream head read queue.
The conditions indicated by POLLNORM and POLLOUT are true if and only if at least one byte of data can
be read or written without blocking. The exception is regular files, which always poll true for POLLNORM
and POLLOUT. Also, streams return POLLNORM in revents even if the available message is of zero
length.
The condition flags POLLERR, POLLHUP, and POLLNVAL are always set in revents if the conditions
they indicate are true for the specified file descriptor, whether or not these flags are set in events.
For each call to poll(), the set of reportable conditions for each file descriptor consists of those conditions
that are always reported, together with any further conditions for which flags are set in events. If any
reportable condition is true for any file descriptor, poll() returns with flags set in revents for each
true condition for that file descriptor.
If no reportable condition is true for any of the file descriptors, poll() waits up to timeout milliseconds
for a reportable condition to become true. If, in that time interval, a reportable condition becomes true for
any of the file descriptors, poll() reports the condition in the file descriptor’s associated revents
member and returns. If no reportable condition becomes true,
poll() returns without setting any
revents bit masks.
If the timeout parameter is a value of 1, poll() does not return until at least one specified event has
occurred. If the value of the timeout parameter is 0, poll() does not wait for an event to occur but
returns immediately, even if no specified event has occurred. The behavior of poll() is not affected by
whether the
O_NONBLOCK flag is set on any of the specified file descriptors.
RETURN VALUES
Upon successful completion, poll() returns a nonnegative value. If the call returns 0, poll() has
timed out and has not set any of the
revents bit masks. A positive value indicates the number of file
descriptors for which poll() has set the revents bit mask. If poll() fails, it returns 1 and sets
errno to indicate the error.
ERRORS
poll() fails if any of the following conditions are encountered:
[EAGAIN] Allocation of internal data structures failed. A later call to poll() may complete
successfully.
[EINTR] A signal was delivered before any of the selected for conditions occurred or before the
time limit expired.
[EINVAL] timeout is a negative number other than 1.
[EFAULT] The fds parameter in conjunction with the nfds parameter addresses a location out-
side of the allocated address space of the process. Reliable detection of this error is
implementation-dependent.
EXAMPLES
Wait for input on file descriptor 0:
#include <poll.h>
struct pollfd fds;
fds.fd = 0;
fds.events = POLLNORM;
poll(&fds, 1, -1);
Wait for input on ifd1 and ifd2, output on ofd, giving up after 10 seconds:
#include <poll.h>
struct pollfd fds[3];
int ifd1, ifd2, ofd, count;
fds[0].fd = ifd1;
fds[0].events = POLLNORM;
fds[1].fd = ifd2;
fds[1].events = POLLNORM;
fds[2].fd = ofd;
Section 2214 2 HP-UX Release 11i: December 2000
___
___