1 .\" $NetBSD: poll.2,v 1.3 1996/09/07 21:53:08 mycroft Exp $
4 .\" Copyright (c) 1996 Charles M. Hannum. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by Charles M. Hannum.
17 .\" 4. The name of the author may not be used to endorse or promote products
18 .\" derived from this software without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 .Nd synchronous I/O multiplexing
42 .Fn poll "struct pollfd fds[]" "nfds_t nfds" "int timeout"
45 .Fa "struct pollfd fds[]"
47 .Fa "const struct timespec * restrict timeout"
48 .Fa "const sigset_t * restrict newsigmask"
54 examines a set of file descriptors to see if some of them are ready for
58 argument is a pointer to an array of pollfd structures as defined in
63 argument determines the size of the
68 int fd; /* file descriptor */
69 short events; /* events to look for */
70 short revents; /* events returned */
77 .Bl -tag -width XXXrevents
79 File descriptor to poll.
80 If fd is equal to -1 then
82 is cleared (set to zero), and that pollfd is not checked.
87 Events which may occur.
95 have the following bits:
96 .Bl -tag -width XXXPOLLWRNORM
98 Data other than high priority data may be read without blocking.
100 Normal data may be read without blocking.
102 Data with a non-zero priority may be read without blocking.
104 High priority data may be read without blocking.
107 Normal data may be written without blocking.
109 Data with a non-zero priority may be written without blocking.
111 An exceptional condition has occurred on the device or socket.
113 flag is always checked, even if not present in the
117 The device or socket has been disconnected.
119 checked, even if not present in the
126 should never be present in the
128 bitmask at the same time.
130 The file descriptor is not open,
131 or in capability mode the file descriptor has insufficient rights.
132 This flag is always checked, even
133 if not present in the
140 is neither zero nor INFTIM (-1), it specifies a maximum interval to
141 wait for any file descriptor to become ready, in milliseconds.
144 is INFTIM (-1), the poll blocks indefinitely.
149 will return without blocking.
155 is used to safely wait until either a set of file descriptors becomes
156 ready or until a signal is caught.
161 arguments are identical to the analogous arguments of
168 .Vt "const struct timespec"
171 (shown below) rather than the
175 A null pointer may be passed to indicate that
177 should wait indefinitely.
180 specifies a signal mask which is set while waiting for input.
183 returns, the original signal mask is restored.
186 time_t tv_sec; /* seconds */
187 long tv_nsec; /* and nanoseconds */
194 returns the number of descriptors that are ready for I/O, or -1 if an
196 If the time limit expires,
201 returns with an error,
202 including one due to an interrupted system call,
205 array will be unmodified.
207 This implementation differs from the historical one in that a given
208 file descriptor may not cause
210 to return with an error.
211 In cases where this would have happened in
212 the historical implementation (e.g.\& trying to poll a
214 descriptor), this implementation instead copies the
219 Attempting to perform I/O on this descriptor will then
221 This behaviour is believed to be more useful.
231 points outside the process's allocated address space.
233 A signal was delivered before the time limit expired and
234 before any of the selected events occurred.
236 The specified time limit is invalid.
237 One of its components is negative or too large.
239 The number of pollfd structures specified by
241 exceeds the system tunable
242 .Va kern.maxfilesperproc
263 is not specified by POSIX.
269 This manual page and the core of the implementation was taken from
273 function first appeared in
276 The distinction between some of the fields in the
280 bitmasks is really not useful without STREAMS.
282 defined for compatibility with existing software.