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