]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/sys/poll.2
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / lib / libc / sys / poll.2
1 .\"     $NetBSD: poll.2,v 1.3 1996/09/07 21:53:08 mycroft Exp $
2 .\" $FreeBSD$
3 .\"
4 .\" Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
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.
19 .\"
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.
30 .\"
31 .Dd July 8, 2002
32 .Dt POLL 2
33 .Os
34 .Sh NAME
35 .Nm poll
36 .Nd synchronous I/O multiplexing
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In poll.h
41 .Ft int
42 .Fn poll "struct pollfd fds[]" "nfds_t nfds" "int timeout"
43 .Sh DESCRIPTION
44 The
45 .Fn poll
46 system call
47 examines a set of file descriptors to see if some of them are ready for
48 I/O.
49 The
50 .Fa fds
51 argument is a pointer to an array of pollfd structures as defined in
52 .In poll.h
53 (shown below).
54 The
55 .Fa nfds
56 argument determines the size of the
57 .Fa fds
58 array.
59 .Bd -literal
60 struct pollfd {
61     int    fd;       /* file descriptor */
62     short  events;   /* events to look for */
63     short  revents;  /* events returned */
64 };
65 .Ed
66 .Pp
67 The fields of
68 .Fa struct pollfd
69 are as follows:
70 .Bl -tag -width XXXrevents
71 .It fd
72 File descriptor to poll.
73 If fd is equal to -1 then
74 .Fa revents
75 is cleared (set to zero), and that pollfd is not checked.
76 .It events
77 Events to poll for.
78 (See below.)
79 .It revents
80 Events which may occur.
81 (See below.)
82 .El
83 .Pp
84 The event bitmasks in
85 .Fa events
86 and
87 .Fa revents
88 have the following bits:
89 .Bl -tag -width XXXPOLLWRNORM
90 .It POLLIN
91 Data other than high priority data may be read without blocking.
92 .It POLLRDNORM
93 Normal data may be read without blocking.
94 .It POLLRDBAND
95 Data with a non-zero priority may be read without blocking.
96 .It POLLPRI
97 High priority data may be read without blocking.
98 .It POLLOUT
99 .It POLLWRNORM
100 Normal data may be written without blocking.
101 .It POLLWRBAND
102 Data with a non-zero priority may be written without blocking.
103 .It POLLERR
104 An exceptional condition has occurred on the device or socket.
105 This
106 flag is always checked, even if not present in the
107 .Fa events
108 bitmask.
109 .It POLLHUP
110 The device or socket has been disconnected.
111 This flag is always
112 checked, even if not present in the
113 .Fa events
114 bitmask.
115 Note that
116 POLLHUP
117 and
118 POLLOUT
119 should never be present in the
120 .Fa revents
121 bitmask at the same time.
122 .It POLLNVAL
123 The file descriptor is not open.
124 This flag is always checked, even
125 if not present in the
126 .Fa events
127 bitmask.
128 .El
129 .Pp
130 If
131 .Fa timeout
132 is neither zero nor INFTIM (-1), it specifies a maximum interval to
133 wait for any file descriptor to become ready, in milliseconds.
134 If
135 .Fa timeout
136 is INFTIM (-1), the poll blocks indefinitely.
137 If
138 .Fa timeout
139 is zero, then
140 .Fn poll
141 will return without blocking.
142 .Sh RETURN VALUES
143 The
144 .Fn poll
145 system call
146 returns the number of descriptors that are ready for I/O, or -1 if an
147 error occurred.
148 If the time limit expires,
149 .Fn poll
150 returns 0.
151 If
152 .Fn poll
153 returns with an error,
154 including one due to an interrupted system call,
155 the
156 .Fa fds
157 array will be unmodified.
158 .Sh COMPATIBILITY
159 This implementation differs from the historical one in that a given
160 file descriptor may not cause
161 .Fn poll
162 to return with an error.
163 In cases where this would have happened in
164 the historical implementation (e.g.\& trying to poll a
165 .Xr revoke 2 Ns ed
166 descriptor), this implementation instead copies the
167 .Fa events
168 bitmask to the
169 .Fa revents
170 bitmask.
171 Attempting to perform I/O on this descriptor will then
172 return an error.
173 This behaviour is believed to be more useful.
174 .Sh ERRORS
175 An error return from
176 .Fn poll
177 indicates:
178 .Bl -tag -width Er
179 .It Bq Er EFAULT
180 The
181 .Fa fds
182 argument
183 points outside the process's allocated address space.
184 .It Bq Er EINTR
185 A signal was delivered before the time limit expired and
186 before any of the selected events occurred.
187 .It Bq Er EINVAL
188 The specified time limit is negative.
189 .El
190 .Sh SEE ALSO
191 .Xr accept 2 ,
192 .Xr connect 2 ,
193 .Xr kqueue 2 ,
194 .Xr read 2 ,
195 .Xr recv 2 ,
196 .Xr select 2 ,
197 .Xr send 2 ,
198 .Xr write 2
199 .Sh HISTORY
200 The
201 .Fn poll
202 function appeared in
203 .At V .
204 This manual page and the core of the implementation was taken from
205 .Nx .
206 .Sh BUGS
207 The distinction between some of the fields in the
208 .Fa events
209 and
210 .Fa revents
211 bitmasks is really not useful without STREAMS.
212 The fields are
213 defined for compatibility with existing software.