STREAMS-UX Programmer's Guide (February 2007)
STREAMS Mechanism and System Calls
Polling Streams
Chapter 2
35
int evpfd;
evpfd = open(“/dev/poll”, O_RDWR);
NOTE The /dev/poll device can be used for write (2) and ioctl (2) operations only by the processes
that opened the device. Although file descriptors are generally inherited by forked processes,
the event port file descriptor behaves differently. Specifically, a child process inheriting an
event port file descriptor can only perform the close (2) operation on it.
Registering and deregistering file descriptors on an event port:
The relevant file descriptors and corresponding events of interest are registered with
/dev/poll using the write (2) call. This write (2) call is a standard UNIX File System write
operation, and not a STREAMS write (2).
NOTE /dev/poll is not a STREAMS device.
int write(int evpfd, const struct pollfd *buf, size_t nbyte);
The write (2) operation automatically registers all non-negative file descriptors in the
pollfd structure with /dev/poll. User applications can de-register file descriptors by
setting the corresponding events attribute of that file descriptor to POLLREMOVE.
POLLREMOVE is a special pseudo-event (defined for de-registration purposes) that must be
the only event present in the events bitmask.
A registered file descriptor is automatically de-registered from /dev/poll by a close (2)
operation.
Polling file descriptors:
User applications may poll an event port via the DP_POLL ioctl (2) command as follows:
int ioctl(int evpfd, DP_POLL, struct dvpoll *arg);
The
arg
parameter points to the following dvpoll structure:
struct dvpoll
{
pollfd_t *dp_fds; /* pollfd[ ] to be used */
nfds_t dp_nfds; /* number of pollfd entries */
int dp_timeout; /* milliseconds or -1 */
};
dp_fds Pointer to an array of pollfd structures.
dp_nfds Maximum number of pollfd structures in the array.
dp_timeout Maximum time, in milliseconds..
The kernel copies only the affected pollfd structures back into dvpoll.
NOTE In all other respects, e.g., the setting of
revents
in the relevant pollfd
structures, the return value of ioctl (2), the wait period behavior of timeout
values, and the reporting of the 3 events (POLLERR, POLLHUP and POLLNVAL),
the DP_POLL ioctl (2) command operates exactly like the corresponding poll
(2) system call for the following:
•Setting
revents
in the relevant pollfd structure
• The return value of ioctl (2)