]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Hey Emacs! This file is -*- nroff -*- source. |
2 | .\" | |
3 | .\" Copyright (C) 1997 Andries Brouwer (aeb@cwi.nl) | |
e755a587 | 4 | .\" and Copyright (C) 2006, Michael Kerrisk <mtk-manpages@gmx.net> |
fea681da MK |
5 | .\" |
6 | .\" Permission is granted to make and distribute verbatim copies of this | |
7 | .\" manual provided the copyright notice and this permission notice are | |
8 | .\" preserved on all copies. | |
9 | .\" | |
10 | .\" Permission is granted to copy and distribute modified versions of this | |
11 | .\" manual under the conditions for verbatim copying, provided that the | |
12 | .\" entire resulting derived work is distributed under the terms of a | |
13 | .\" permission notice identical to this one. | |
c13182ef | 14 | .\" |
fea681da MK |
15 | .\" Since the Linux kernel and libraries are constantly changing, this |
16 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
17 | .\" responsibility for errors or omissions, or for damages resulting from | |
18 | .\" the use of the information contained herein. The author(s) may not | |
19 | .\" have taken the same level of care in the production of this manual, | |
20 | .\" which is licensed free of charge, as they might when working | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
fea681da MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
25 | .\" | |
26 | .\" Additions from Richard Gooch <rgooch@atnf.CSIRO.AU> and aeb, 971207 | |
e755a587 | 27 | .\" 2006-03-13, mtk, Added ppoll() + various other rewordings |
23cb3cb5 MK |
28 | .\" 2006-07-01, mtk, Added POLLRDHUP + various other wording and |
29 | .\" formatting changes. | |
4b9d4c1a | 30 | .\" |
24b3ed1d | 31 | .\" FIXME . 2.6.17 has a definition for POLLREMOVE, but this |
0c373d01 | 32 | .\" flag is not used in the code. Check later to see if it |
a7b9318d | 33 | .\" does get a use. 2.6.21 still shows no use. |
0c373d01 | 34 | .\" |
d9343c5c | 35 | .TH POLL 2 2006-03-13 "Linux" "Linux Programmer's Manual" |
fea681da | 36 | .SH NAME |
e755a587 | 37 | poll, ppoll \- wait for some event on a file descriptor |
fea681da | 38 | .SH SYNOPSIS |
e755a587 | 39 | .nf |
23cb3cb5 | 40 | .B #include <poll.h> |
fea681da | 41 | .sp |
e755a587 MK |
42 | .BI "int poll(struct pollfd *" fds ", nfds_t " nfds ", int " timeout ); |
43 | .sp | |
22ca838f | 44 | .B #define _GNU_SOURCE |
23cb3cb5 | 45 | .B #include <poll.h> |
22ca838f | 46 | .sp |
e755a587 MK |
47 | .BI "int ppoll(struct pollfd *" fds ", nfds_t " nfds ", " |
48 | .BI " const struct timespec *" timeout ", const sigset_t *" sigmask ); | |
49 | .fi | |
fea681da | 50 | .SH DESCRIPTION |
96296ef0 | 51 | .BR poll () |
e755a587 MK |
52 | performs a similar task to |
53 | .BR select (2): | |
54 | it waits for one of a set of file descriptors to become ready | |
55 | to perform I/O. | |
56 | ||
57 | The set of file descriptors to be monitored is specified in the | |
58 | .I fds | |
59 | argument, which is an array of | |
fea681da | 60 | .I nfds |
e755a587 | 61 | structures of the following form: |
fea681da | 62 | .nf |
96296ef0 MK |
63 | |
64 | struct pollfd { | |
e755a587 | 65 | int fd; /* file descriptor */ |
96296ef0 MK |
66 | short events; /* requested events */ |
67 | short revents; /* returned events */ | |
68 | }; | |
69 | ||
fea681da | 70 | .fi |
fea681da MK |
71 | The field |
72 | .I fd | |
73 | contains a file descriptor for an open file. | |
23cb3cb5 | 74 | |
fea681da MK |
75 | The field |
76 | .I events | |
77 | is an input parameter, a bitmask specifying the events the application | |
78 | is interested in. | |
23cb3cb5 | 79 | |
fea681da MK |
80 | The field |
81 | .I revents | |
82 | is an output parameter, filled by the kernel with the events that | |
e755a587 MK |
83 | actually occurred. |
84 | The bits returned in | |
85 | .I revents | |
c13182ef | 86 | can include any of those specified in |
e755a587 MK |
87 | .IR events , |
88 | or one of the values | |
89 | .BR POLLERR , | |
90 | .BR POLLHUP , | |
fea681da MK |
91 | or |
92 | .BR POLLNVAL . | |
93 | (These three bits are meaningless in the | |
94 | .I events | |
95 | field, and will be set in the | |
96 | .I revents | |
97 | field whenever the corresponding condition is true.) | |
23cb3cb5 | 98 | |
fea681da | 99 | If none of the events requested (and no error) has occurred for any |
e755a587 MK |
100 | of the file descriptors, then |
101 | .BR poll () | |
102 | blocks until one of the events occurs. | |
96296ef0 | 103 | |
c13182ef | 104 | The |
e755a587 MK |
105 | .I timeout |
106 | argument specifies an upper limit on the time for which | |
107 | .BR poll () | |
108 | will block, in milliseconds. | |
109 | Specifying a negative value in | |
110 | .I timeout | |
111 | means an infinite timeout. | |
23cb3cb5 MK |
112 | |
113 | The bits that may be set/returned in | |
114 | .I events | |
115 | and | |
116 | .I revents | |
c84371c6 | 117 | are defined in \fI<poll.h>\fP: |
23cb3cb5 MK |
118 | .RS |
119 | .TP | |
120 | .B POLLIN | |
121 | There is data to read. | |
122 | .TP | |
123 | .B POLLPRI | |
c13182ef | 124 | There is urgent data to read (e.g., out-of-band data on TCP socket; |
23cb3cb5 MK |
125 | pseudo-terminal master in packet mode has seen state change in slave). |
126 | .TP | |
127 | .B POLLOUT | |
128 | Writing now will not block. | |
129 | .TP | |
130 | .BR POLLRDHUP " (since Linux 2.6.17)" | |
c13182ef | 131 | Stream socket peer closed connection, |
23cb3cb5 | 132 | or shut down writing half of connection. |
c13182ef | 133 | The |
23cb3cb5 MK |
134 | .B _GNU_SOURCE |
135 | feature test macro must be defined in order to obtain this definition. | |
136 | .TP | |
137 | .B POLLERR | |
138 | Error condition (output only). | |
139 | .TP | |
140 | .B POLLHUP | |
141 | Hang up (output only). | |
142 | .TP | |
143 | .B POLLNVAL | |
c13182ef | 144 | Invalid request: |
23cb3cb5 MK |
145 | .I fd |
146 | not open (output only). | |
147 | .RE | |
148 | .PP | |
c13182ef | 149 | When compiling with |
23cb3cb5 | 150 | .B _XOPEN_SOURCE |
c13182ef | 151 | defined, one also has the following, |
23cb3cb5 MK |
152 | which convey no further information beyond the bits listed above: |
153 | .RS | |
154 | .TP | |
155 | .B POLLRDNORM | |
156 | Equivalent to | |
157 | .BR POLLIN . | |
158 | .TP | |
159 | .B POLLRDBAND | |
160 | Priority band data can be read (generally unused on Linux). | |
161 | .\" POLLRDBAND is used in the DECnet protocol. | |
162 | .TP | |
163 | .B POLLWRNORM | |
164 | Equivalent to | |
165 | .BR POLLOUT . | |
166 | .TP | |
167 | .B POLLWRBAND | |
168 | Priority data may be written. | |
169 | .RE | |
170 | .PP | |
c13182ef | 171 | Linux also knows about, but does not use |
23cb3cb5 | 172 | .BR POLLMSG . |
e755a587 | 173 | .SS ppoll() |
c13182ef | 174 | The relationship between |
e755a587 | 175 | .BR poll () |
c13182ef MK |
176 | and |
177 | .BR ppoll () | |
e755a587 | 178 | is analogous to the relationship between |
0bfa087b | 179 | .BR select (2) |
e755a587 | 180 | and |
0bfa087b | 181 | .BR pselect (2): |
e755a587 | 182 | like |
0bfa087b | 183 | .BR pselect (2), |
e755a587 MK |
184 | .BR ppoll () |
185 | allows an application to safely wait until either a file descriptor | |
186 | becomes ready or until a signal is caught. | |
187 | .PP | |
c13182ef | 188 | Other than the difference in the |
e755a587 | 189 | .I timeout |
c13182ef | 190 | argument, the following |
e755a587 MK |
191 | .BR ppoll () |
192 | call: | |
193 | .nf | |
194 | ||
195 | ready = ppoll(&fds, nfds, timeout, &sigmask); | |
196 | ||
197 | .fi | |
198 | is equivalent to | |
199 | .I atomically | |
200 | executing the following calls: | |
201 | .nf | |
202 | ||
203 | sigset_t origmask; | |
204 | ||
205 | sigprocmask(SIG_SETMASK, &sigmask, &origmask); | |
00877d8f | 206 | ready = poll(&fds, nfds, timeout); |
e755a587 MK |
207 | sigprocmask(SIG_SETMASK, &origmask, NULL); |
208 | .fi | |
209 | .PP | |
210 | See the description of | |
211 | .BR pselect (2) | |
212 | for an explanation of why | |
213 | .BR ppoll () | |
214 | is necessary. | |
215 | ||
216 | The | |
217 | .I timeout | |
c13182ef | 218 | argument specifies an upper limit on the amount of time that |
e755a587 MK |
219 | .BR ppoll () |
220 | will block. | |
221 | This argument is a pointer to a structure of the following form: | |
222 | .in +0.25i | |
223 | .nf | |
224 | ||
225 | struct timespec { | |
226 | long tv_sec; /* seconds */ | |
227 | long tv_nsec; /* nanoseconds */ | |
228 | }; | |
229 | .fi | |
230 | .in -0.25i | |
231 | ||
232 | If | |
233 | .I timeout | |
c13182ef | 234 | is specified as NULL, then |
e755a587 MK |
235 | .BR ppoll () |
236 | can block indefinitely. | |
fea681da | 237 | .SH "RETURN VALUE" |
96296ef0 MK |
238 | On success, a positive number is returned; this is |
239 | the number of structures which have non-zero | |
fea681da MK |
240 | .I revents |
241 | fields (in other words, those descriptors with events or errors reported). | |
242 | A value of 0 indicates that the call timed out and no file | |
c13182ef MK |
243 | descriptors were ready. |
244 | On error, \-1 is returned, and | |
fea681da MK |
245 | .I errno |
246 | is set appropriately. | |
247 | .SH ERRORS | |
248 | .TP | |
249 | .B EBADF | |
250 | An invalid file descriptor was given in one of the sets. | |
251 | .TP | |
252 | .B EFAULT | |
253 | The array given as argument was not contained in the calling program's | |
254 | address space. | |
255 | .TP | |
256 | .B EINTR | |
257 | A signal occurred before any requested event. | |
258 | .TP | |
259 | .B EINVAL | |
260 | The | |
261 | .I nfds | |
682edefb MK |
262 | value exceeds the |
263 | .B RLIMIT_NOFILE | |
264 | value. | |
fea681da MK |
265 | .TP |
266 | .B ENOMEM | |
267 | There was no space to allocate file descriptor tables. | |
e755a587 | 268 | .SH VERSIONS |
b5cc2ffb | 269 | The |
c13182ef | 270 | .BR poll () |
b5cc2ffb | 271 | system call was introduced in Linux 2.1.23. |
c13182ef | 272 | The |
4d52e8f8 | 273 | .BR poll () |
b5cc2ffb | 274 | library call was introduced in libc 5.4.28 |
0bfa087b | 275 | (and provides emulation using select(2) if your kernel does not |
c13182ef | 276 | have a |
1e321034 MK |
277 | .BR poll () |
278 | system call). | |
e755a587 MK |
279 | |
280 | The | |
281 | .BR ppoll () | |
282 | system call was added to Linux in kernel 2.6.16. | |
283 | The | |
284 | .BR ppoll () | |
285 | library call was added in glibc 2.4. | |
a1d5f77c MK |
286 | .SH "CONFORMING TO" |
287 | .BR poll () | |
288 | conforms to POSIX.1-2001. | |
289 | .BR ppoll () | |
290 | is Linux specific. | |
291 | .\" NetBSD 3.0 has a pollts() which is like Linux ppoll(). | |
e755a587 | 292 | .SH NOTES |
c1164764 MK |
293 | Some implementations define the non-standard constant |
294 | .B INFTIM | |
295 | with the value \-1 for use as a | |
296 | .IR timeout . | |
297 | This constant is not provided in glibc. | |
4fb31341 MK |
298 | .SS "Linux Notes" |
299 | The Linux | |
300 | .BR ppoll () | |
301 | system call modifies its | |
302 | .I timeout | |
303 | argument. | |
d9bfdb9c | 304 | However, the glibc wrapper function hides this behavior |
4fb31341 MK |
305 | by using a local variable for the timeout argument that |
306 | is passed to the system call. | |
307 | Thus, the glibc | |
308 | .BR ppoll () | |
309 | function does not modify its | |
310 | .I timeout | |
311 | argument. | |
a1d5f77c MK |
312 | .SH BUGS |
313 | See the discussion of spurious readiness notifications under the | |
314 | BUGS section of | |
315 | .BR select (2). | |
fea681da MK |
316 | .SH "SEE ALSO" |
317 | .BR select (2), | |
50e5322c | 318 | .BR select_tut (2), |
a8e7c990 | 319 | .BR feature_test_macros (7) |