1 .\" $NetBSD: poll.2,v 1.28 2010/03/22 19:30:55 joerg Exp $
3 .\" Copyright (c) 1998, 2005 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Charles M. Hannum.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
35 .Nd synchronous I/O multiplexing
41 .Fn poll "struct pollfd *fds" "nfds_t nfds" "int timeout"
46 .Fn pollts "struct pollfd * restrict fds" "nfds_t nfds" "const struct timespec * restrict ts" "const sigset_t * restrict sigmask"
51 examine a set of file descriptors to see if some of them are ready for
55 argument is a pointer to an array of pollfd structures as defined in
60 argument determines the size of the
65 int fd; /* file descriptor */
66 short events; /* events to look for */
67 short revents; /* events returned */
74 .Bl -tag -width XXXrevents
76 File descriptor to poll.
79 is negative, the file descriptor is ignored and
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.
105 Normal data may be written without blocking.
110 Data with a non-zero priority may be written without blocking.
112 An exceptional condition has occurred on the device or socket.
113 This 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.
129 If the remote end of a socket is closed,
136 The file descriptor is not open.
137 This flag is always checked, even
138 if not present in the
145 is neither zero nor INFTIM (\-1), it specifies a maximum interval to
146 wait for any file descriptor to become ready, in milliseconds.
149 is INFTIM (\-1), the poll blocks indefinitely.
154 will return without blocking.
158 is a non-null pointer, it references a timespec structure which specifies a
159 maximum interval to wait for any file descriptor to become ready.
167 is a non-null pointer, referencing a zero-valued timespec structure, then
169 will return without blocking.
173 is a non-null pointer, then the
175 function shall replace the signal mask of the caller by the set of
176 signals pointed to by
178 before examining the descriptors, and shall restore the signal mask
179 of the caller before returning.
182 returns the number of descriptors that are ready for I/O, or \-1 if an
184 If the time limit expires,
189 returns with an error,
190 including one due to an interrupted call,
193 array will be unmodified.
195 This implementation differs from the historical one in that a given
196 file descriptor may not cause
198 to return with an error.
199 In cases where this would have happened in the historical implementation
200 (e.g. trying to poll a
202 descriptor), this implementation instead copies the
207 Attempting to perform I/O on this descriptor will then return an error.
208 This behaviour is believed to be more useful.
216 points outside the process's allocated address space.
218 A signal was delivered before the time limit expired and
219 before any of the selected events occurred.
221 The specified time limit is negative.
238 function first appeared in
241 The distinction between some of the fields in the
245 bitmasks is really not useful without STREAMS.
246 The fields are defined for compatibility with existing software.