1 .\" $NetBSD: poll.2,v 1.3 1996/09/07 21:53:08 mycroft Exp $
2 .\" $FreeBSD: src/lib/libc/sys/poll.2,v 1.4.2.3 2001/12/14 18:34:01 ru Exp $
3 .\" $DragonFly: src/lib/libc/sys/poll.2,v 1.5 2007/05/13 18:33:56 swildner Exp $
5 .\" Copyright (c) 1996 Charles M. Hannum. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by Charles M. Hannum.
18 .\" 4. The name of the author may not be used to endorse or promote products
19 .\" derived from this software without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 .Nd synchronous I/O multiplexing
44 .Fn poll "struct pollfd *fds" "unsigned int nfds" "int timeout"
47 examines a set of file descriptors to see if some of them are ready for
51 argument is a pointer to an array of pollfd structures as defined in
55 argument determines the size of the
60 int fd; /* file descriptor */
61 short events; /* events to look for */
62 short revents; /* events returned */
69 .Bl -tag -width XXXrevents
71 File descriptor to poll. If fd is equal to -1 then
73 is cleared (set to zero), and that pollfd is not checked.
75 Events to poll for. (See below.)
77 Events which may occur. (See below.)
84 have the following bits:
85 .Bl -tag -width XXXPOLLWRNORM
87 Data other than high priority data may be read without blocking.
89 Normal data may be read without blocking.
91 Data with a non-zero priority may be read without blocking.
93 High priority data may be read without blocking.
96 Normal data may be written without blocking.
98 Data with a non-zero priority may be written without blocking.
100 An exceptional condition has occurred on the device or socket. This
101 flag is always checked, even if not present in the
105 The device or socket has been disconnected. This flag is always
106 checked, even if not present in the
112 should never be present in the
114 bitmask at the same time.
116 The file descriptor is not open. This flag is always checked, even
117 if not present in the
124 is neither zero nor INFTIM (-1), it specifies a maximum interval to
125 wait for any file descriptor to become ready, in milliseconds. If
127 is INFTIM (-1), the poll blocks indefinitely. If
131 will return without blocking.
134 returns the number of descriptors that are ready for I/O, or -1 if an
135 error occurred. If the time limit expires,
140 returns with an error,
141 including one due to an interrupted call,
144 array will be unmodified.
146 This implementation differs from the historical one in that a given
147 file descriptor may not cause
149 to return with an error. In cases where this would have happened in
150 the historical implementation (e.g. trying to poll a
152 descriptor), this implementation instead copies the
156 bitmask. Attempting to perform I/O on this descriptor will then
157 return an error. This behaviour is believed to be more useful.
165 points outside the process's allocated address space.
167 A signal was delivered before the time limit expired and
168 before any of the selected events occurred.
170 The specified time limit is negative.
183 function call appeared in
185 This manual page and the core of the implementation was taken from
188 The distinction between some of the fields in the
192 bitmasks is really not useful without STREAMS. The fields are
193 defined for compatibility with existing software.