]>
Commit | Line | Data |
---|---|---|
91447636 A |
1 | .\" |
2 | .\" Copyright (c) 2005 Apple Computer, Inc. All rights reserved. | |
3 | .\" | |
6601e61a | 4 | .\" @APPLE_LICENSE_HEADER_START@ |
8f6c56a5 A |
5 | .\" |
6 | .\" This file contains Original Code and/or Modifications of Original Code | |
7 | .\" as defined in and that are subject to the Apple Public Source License | |
8 | .\" Version 2.0 (the 'License'). You may not use this file except in | |
9 | .\" compliance with the License. Please obtain a copy of the License at | |
10 | .\" http://www.opensource.apple.com/apsl/ and read it before using this | |
91447636 A |
11 | .\" file. |
12 | .\" | |
8f6c56a5 A |
13 | .\" The Original Code and all software distributed under the License are |
14 | .\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | .\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | .\" Please see the License for the specific language governing rights and | |
91447636 A |
19 | .\" limitations under the License. |
20 | .\" | |
6601e61a | 21 | .\" @APPLE_LICENSE_HEADER_END@ |
91447636 A |
22 | .\" |
23 | .\" | |
24 | .\" Copyright (c) 1996 Charles M. Hannum. All rights reserved. | |
25 | .\" | |
26 | .\" Redistribution and use in source and binary forms, with or without | |
27 | .\" modification, are permitted provided that the following conditions | |
28 | .\" are met: | |
29 | .\" 1. Redistributions of source code must retain the above copyright | |
30 | .\" notice, this list of conditions and the following disclaimer. | |
31 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
32 | .\" notice, this list of conditions and the following disclaimer in the | |
33 | .\" documentation and/or other materials provided with the distribution. | |
34 | .\" 3. All advertising materials mentioning features or use of this software | |
35 | .\" must display the following acknowledgement: | |
36 | .\" This product includes software developed by Charles M. Hannum. | |
37 | .\" 4. The name of the author may not be used to endorse or promote products | |
38 | .\" derived from this software without specific prior written permission. | |
39 | .\" | |
40 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
41 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
42 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
43 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
44 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
45 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
46 | .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
47 | .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
48 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
49 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
50 | .\" | |
51 | .Dd February 27, 2005 | |
52 | .Dt POLL 2 | |
53 | .Os | |
54 | .Sh NAME | |
55 | .Nm poll | |
56 | .Nd synchronous I/O multiplexing | |
57 | .Sh SYNOPSIS | |
58 | .In poll.h | |
59 | .Ft int | |
2d21ac55 A |
60 | .Fo poll |
61 | .Fa "struct pollfd fds[]" | |
62 | .Fa "nfds_t nfds" | |
63 | .Fa "int timeout" | |
64 | .Fc | |
91447636 A |
65 | .Sh DESCRIPTION |
66 | .Fn Poll | |
2d21ac55 A |
67 | examines a set of file descriptors |
68 | to see if some of them are ready for I/O | |
69 | or if certain events have occurred on them. | |
91447636 A |
70 | The |
71 | .Fa fds | |
2d21ac55 A |
72 | argument is a pointer to an array of pollfd structures, |
73 | as defined in | |
91447636 A |
74 | .Aq Pa poll.h |
75 | (shown below). The | |
76 | .Fa nfds | |
2d21ac55 | 77 | argument specifies the size of the |
91447636 A |
78 | .Fa fds |
79 | array. | |
80 | .Bd -literal | |
81 | struct pollfd { | |
82 | int fd; /* file descriptor */ | |
83 | short events; /* events to look for */ | |
84 | short revents; /* events returned */ | |
85 | }; | |
86 | .Ed | |
87 | .Pp | |
88 | The fields of | |
89 | .Fa struct pollfd | |
90 | are as follows: | |
2d21ac55 | 91 | .Bl -tag -width XXXPOLLWRNORM |
91447636 A |
92 | .It fd |
93 | File descriptor to poll. | |
94 | .It events | |
95 | Events to poll for. (See below.) | |
96 | .It revents | |
97 | Events which may occur or have occurred. (See below.) | |
98 | .El | |
99 | .Pp | |
100 | The event bitmasks in | |
101 | .Fa events | |
102 | and | |
103 | .Fa revents | |
104 | have the following bits: | |
105 | .Bl -tag -width XXXPOLLWRNORM | |
2d21ac55 | 106 | .\" =========== |
91447636 | 107 | .It POLLERR |
2d21ac55 A |
108 | An exceptional condition has occurred on the device or socket. |
109 | This flag is output only, and ignored if present in the input | |
91447636 A |
110 | .Fa events |
111 | bitmask. | |
2d21ac55 | 112 | .\" =========== |
91447636 | 113 | .It POLLHUP |
2d21ac55 A |
114 | The device or socket has been disconnected. |
115 | This flag is output only, | |
91447636 A |
116 | and ignored if present in the input |
117 | .Fa events | |
2d21ac55 A |
118 | bitmask. |
119 | Note that POLLHUP and POLLOUT | |
91447636 A |
120 | are mutually exclusive and should never be present in the |
121 | .Fa revents | |
122 | bitmask at the same time. | |
2d21ac55 A |
123 | .\" =========== |
124 | .It POLLIN | |
125 | Data other than high priority data may be read without blocking. | |
126 | This is equivalent to ( POLLRDNORM | POLLRDBAND ). | |
127 | .\" =========== | |
91447636 | 128 | .It POLLNVAL |
2d21ac55 A |
129 | The file descriptor is not open. |
130 | This flag is output only, and ignored if present in the input | |
91447636 A |
131 | .Fa events |
132 | bitmask. | |
2d21ac55 A |
133 | .\" =========== |
134 | .It POLLOUT | |
135 | Normal data may be written without blocking. | |
136 | This is equivalent to POLLWRNORM. | |
137 | .\" =========== | |
138 | .It POLLPRI | |
139 | High priority data may be read without blocking. | |
140 | .\" =========== | |
141 | .It POLLRDBAND | |
142 | Priority data may be read without blocking. | |
143 | .\" =========== | |
144 | .It POLLRDNORM | |
145 | Normal data may be read without blocking. | |
146 | .\" =========== | |
147 | .It POLLWRBAND | |
148 | Priority data may be written without blocking. | |
149 | .\" =========== | |
150 | .It POLLWRNORM | |
151 | Normal data may be written without blocking. | |
91447636 A |
152 | .El |
153 | .Pp | |
2d21ac55 A |
154 | The distinction between normal, priority, and high-priority data |
155 | is specific to particular file types or devices. | |
91447636 A |
156 | .Pp |
157 | If | |
158 | .Fa timeout | |
2d21ac55 A |
159 | is greater than zero, |
160 | it specifies a maximum interval (in milliseconds) | |
161 | to wait for any file descriptor to become ready. | |
162 | If | |
91447636 A |
163 | .Fa timeout |
164 | is zero, then | |
165 | .Fn poll | |
166 | will return without blocking. If the value of | |
167 | .Fa timeout | |
168 | is -1, the poll blocks indefinitely. | |
169 | .Sh RETURN VALUES | |
170 | .Fn Poll | |
2d21ac55 A |
171 | returns the number of descriptors that are ready for I/O, |
172 | or -1 if an error occurred. | |
173 | If the time limit expires, | |
91447636 A |
174 | .Fn poll |
175 | returns 0. | |
176 | If | |
177 | .Fn poll | |
178 | returns with an error, | |
179 | including one due to an interrupted call, | |
180 | the | |
181 | .Fa fds | |
2d21ac55 A |
182 | array will be unmodified and the global variable |
183 | .Va errno | |
184 | will be set to indicate the error. | |
91447636 | 185 | .Sh ERRORS |
2d21ac55 A |
186 | .Fn Poll |
187 | will fail if: | |
91447636 | 188 | .Bl -tag -width Er |
2d21ac55 A |
189 | .\" =========== |
190 | .It Bq Er EAGAIN | |
191 | Allocation of internal data structures fails. | |
192 | A subsequent request may succeed. | |
193 | .\" =========== | |
91447636 A |
194 | .It Bq Er EFAULT |
195 | .Fa Fds | |
196 | points outside the process's allocated address space. | |
2d21ac55 | 197 | .\" =========== |
91447636 | 198 | .It Bq Er EINTR |
2d21ac55 A |
199 | A signal is delivered before the time limit expires |
200 | and before any of the selected events occurs. | |
201 | .\" =========== | |
91447636 A |
202 | .It Bq Er EINVAL |
203 | The | |
204 | .Fa nfds | |
2d21ac55 | 205 | argument is greater than OPEN_MAX or the |
91447636 A |
206 | .Fa timeout |
207 | argument is less than -1. | |
208 | .El | |
209 | .Sh BUGS | |
210 | The | |
211 | .Fn poll | |
212 | system call currently does not support devices. | |
213 | .Sh SEE ALSO | |
214 | .Xr accept 2 , | |
215 | .Xr connect 2 , | |
216 | .Xr kevent 2 , | |
217 | .Xr read 2 , | |
218 | .Xr recv 2 , | |
219 | .Xr select 2 , | |
220 | .Xr send 2 , | |
221 | .Xr write 2 | |
222 | .Sh HISTORY | |
223 | The | |
224 | .Fn poll | |
225 | function call appeared in | |
226 | .At V . |