STREAMS-UX Programmer's Guide (February 2007)
STREAMS Mechanism and System Calls
Polling Streams
Chapter 2
32
Polling Streams
Polling, (sometimes referred to as Synchronous Polling) is a mechanism by which a STREAMS application
can query one or more file descriptors (stream head read-queues) for specific events. An event can be the
arrival of specific message types, the status of a stream to accept certain message types, or the occurrence of
specific error conditions.
Two variations of the polling mechanisms supported by STREAMS on HP-UX are as follows:
• poll (2) system call
• /dev/poll device
The poll(2) System Call
The poll (2) system call monitors I/O conditions on multiple file descriptors.
Synopsis
#include <sys/poll.h>
int poll(struct pollfd fds[ ], nfds_t nfds, int timeout);
Arguments
fds[ ] Array of struct pollfd, one per file descriptor to be polled. The pollfd structure is
defined in <sys/poll.h> as follows:
struct pollfd
{
int fd; /* file descriptor */
short events; /* requested events */
short revents; /* returned events */
};
fd File descriptor to be polled for one or more events
events Bitwise-OR of events to be polled for a file descriptor. The application can
poll different fd’s for a different set of events. As a result, the value of
events can differ from file descriptor to file descriptor.
revents Return parameter containing a bitwise-OR of events that have occurred
on that file descriptor.
nfds Number of file descriptors to be polled.
timeout Number of milliseconds for which poll (2) waits for an event if no events are pending. A
negative value indicates that poll (2) waits indefinitely until at least one event is detected.