STREAMS-UX Programmer's Guide (February 2007)
STREAMS Mechanism and System Calls
Polling Streams
Chapter 2
36
• The wait period behavior of the timeout values
• Reporting the POLLERR, POLLHUP, and POLLNVAL events
Retrieving registered poll conditions for a file descriptor:
User applications may query /dev/poll for the registration status of specific file
descriptors via the DP_ISPOLLED ioctl (2) command as follows:
struct pollfd pfd;
int ispolled;
pfd.fd = fd1;
ispolled = ioctl(evpfd, DP_ISPOLLED, &pfd);
If file descriptor fd1 is registered with /dev/poll, the ioctl (2) function call will return 1,
and the events attribute in the pollfd structure will be set to the events registered for this
file descriptor.
If the file descriptor is not registered or open, ioctl (2) will return 0.
Closing an event port:
An event port is closed with the close (2) system call that specifies the event port file
descriptor as follows:
int close(evpfd);
All registered file descriptors are automatically de-registered.
select(2)
Externally, the select (2) system call is analogous to poll (2), but the input parameters are structured
differently. The user must specify three sets of file descriptors to test for read, write, and exception
conditions as follows:
Synopsis
#include <sys/stropts.h>
#include <sys/time.h>
int select (int nfds, int *readfds, int *writefds, int *exceptfds, const struct timeval *timeout);
Arguments
nfds Number of file descriptors to be checked.
readfds Pointer to a bitmask representing a file descriptors to be checked for read-to-read
writefds Pointer to a bitmask representing a set of file descriptors to be checked for ready-to-write
exceptfds Pointer to a bitmask representing a set of file descriptors to be checked for exception
conditions
timeout Pointer to a timeout value (in microseconds) for which the select (2) call will block. A zero
indicates no timeout, i.e., the select (2) will block indefinitely until at least one event on at
least one file descriptor is detected.
Return Values
The select (2) returns the number of file descriptors found with an event (read, write, or exception). It also
modifies the bitmasks to represent only those file descriptors where an event has been detected.