1 .\" $NetBSD: poll.2,v 1.3 1996/09/07 21:53:08 mycroft Exp $
3 .\" Copyright (c) 1996 Charles M. Hannum. All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\" must display the following acknowledgement:
15 .\" This product includes software developed by Charles M. Hannum.
16 .\" 4. The name of the author may not be used to endorse or promote products
17 .\" derived from this software without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 .Nd synchronous I/O multiplexing
41 .Fn poll "struct pollfd fds[]" "nfds_t nfds" "int timeout"
44 .Fa "struct pollfd fds[]"
46 .Fa "const struct timespec * restrict timeout"
47 .Fa "const sigset_t * restrict newsigmask"
53 examines a set of file descriptors to see if some of them are ready for
57 argument is a pointer to an array of pollfd structures as defined in
62 argument determines the size of the
67 int fd; /* file descriptor */
68 short events; /* events to look for */
69 short revents; /* events returned */
76 .Bl -tag -width XXXrevents
78 File descriptor to poll.
79 If fd is equal to -1 then
81 is cleared (set to zero), and that pollfd is not checked.
86 Events which may occur.
94 have the following bits:
95 .Bl -tag -width XXXPOLLWRNORM
97 Data other than high priority data may be read without blocking.
99 Normal data may be read without blocking.
101 Data with a non-zero priority may be read without blocking.
103 High priority data may be read without blocking.
106 Normal data may be written without blocking.
108 Data with a non-zero priority may be written without blocking.
110 An exceptional condition has occurred on the device or socket.
112 flag is always checked, even if not present in the
116 The device or socket has been disconnected.
118 checked, even if not present in the
125 should never be present in the
127 bitmask at the same time.
129 Remote peer closed connection, or shut down writing.
133 must be present in the
135 bitmask to be reported.
136 Applies only to stream sockets.
138 The file descriptor is not open,
139 or in capability mode the file descriptor has insufficient rights.
140 This flag is always checked, even
141 if not present in the
148 is neither zero nor INFTIM (-1), it specifies a maximum interval to
149 wait for any file descriptor to become ready, in milliseconds.
152 is INFTIM (-1), the poll blocks indefinitely.
157 will return without blocking.
163 is used to safely wait until either a set of file descriptors becomes
164 ready or until a signal is caught.
169 arguments are identical to the analogous arguments of
176 .Vt "const struct timespec"
179 (shown below) rather than the
183 A null pointer may be passed to indicate that
185 should wait indefinitely.
188 specifies a signal mask which is set while waiting for input.
191 returns, the original signal mask is restored.
194 time_t tv_sec; /* seconds */
195 long tv_nsec; /* and nanoseconds */
202 returns the number of descriptors that are ready for I/O, or -1 if an
204 If the time limit expires,
209 returns with an error,
210 including one due to an interrupted system call,
213 array will be unmodified.
215 This implementation differs from the historical one in that a given
216 file descriptor may not cause
218 to return with an error.
219 In cases where this would have happened in
220 the historical implementation (e.g.\& trying to poll a
222 descriptor), this implementation instead copies the
227 Attempting to perform I/O on this descriptor will then
229 This behaviour is believed to be more useful.
239 points outside the process's allocated address space.
241 A signal was delivered before the time limit expired and
242 before any of the selected events occurred.
244 The specified time limit is invalid.
245 One of its components is negative or too large.
247 The number of pollfd structures specified by
249 exceeds the system tunable
250 .Va kern.maxfilesperproc
271 is not specified by POSIX.
274 flag is not specified by POSIX, but is compatible with Linux and illumos.
280 This manual page and the core of the implementation was taken from
284 function first appeared in
287 The distinction between some of the fields in the
291 bitmasks is really not useful without STREAMS.
293 defined for compatibility with existing software.