]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/poll.2
xnu-792.tar.gz
[apple/xnu.git] / bsd / man / man2 / poll.2
CommitLineData
91447636
A
1.\"
2.\" Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
3.\"
4.\" @APPLE_LICENSE_HEADER_START@
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
11.\" file.
12.\"
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
19.\" limitations under the License.
20.\"
21.\" @APPLE_LICENSE_HEADER_END@
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
60.Fn poll "struct pollfd *fds" "nfds_t nfds" "int timeout"
61.Sh DESCRIPTION
62.Fn Poll
63examines a set of file descriptors to see if some of them are ready for
64I/O or if certain events have occurred on them.
65The
66.Fa fds
67argument is a pointer to an array of pollfd structures as defined in
68.Aq Pa poll.h
69(shown below). The
70.Fa nfds
71argument determines the size of the
72.Fa fds
73array.
74.Bd -literal
75struct pollfd {
76 int fd; /* file descriptor */
77 short events; /* events to look for */
78 short revents; /* events returned */
79};
80.Ed
81.Pp
82The fields of
83.Fa struct pollfd
84are as follows:
85.Bl -tag -width XXXrevents
86.It fd
87File descriptor to poll.
88.It events
89Events to poll for. (See below.)
90.It revents
91Events which may occur or have occurred. (See below.)
92.El
93.Pp
94The event bitmasks in
95.Fa events
96and
97.Fa revents
98have the following bits:
99.Bl -tag -width XXXPOLLWRNORM
100.It POLLIN
101Data other than high priority data may be read without blocking.
102This is equivalent to ( POLLRDNORM | POLLRDBAND ).
103.It POLLRDNORM
104Normal data may be read without blocking.
105.It POLLRDBAND
106Priority data may be read without blocking.
107.It POLLPRI
108High priority data may be read without blocking.
109.It POLLOUT
110.It POLLWRNORM
111Normal data may be written without blocking.
112.It POLLWRBAND
113Priority data may be written without blocking.
114.It POLLERR
115An exceptional condition has occurred on the device or socket. This
116flag is output only, and ignored if present in the input
117.Fa events
118bitmask.
119.It POLLHUP
120The device or socket has been disconnected. This flag is output only,
121and ignored if present in the input
122.Fa events
123bitmask. Note that
124POLLHUP
125and
126POLLOUT
127are mutually exclusive and should never be present in the
128.Fa revents
129bitmask at the same time.
130.It POLLNVAL
131The file descriptor is not open. This flag is output only, and ignored if present in the input
132.Fa events
133bitmask.
134.El
135.Pp
136The distinction between normal, priority, and high-priority data is file type
137or device specific.
138.Pp
139If
140.Fa timeout
141is greater than zero, it specifies a maximum interval to
142wait for any file descriptor to become ready, in milliseconds. If
143.Fa timeout
144is zero, then
145.Fn poll
146will return without blocking. If the value of
147.Fa timeout
148is -1, the poll blocks indefinitely.
149.Sh RETURN VALUES
150.Fn Poll
151returns the number of descriptors that are ready for I/O, or -1 if an
152error occured. If the time limit expires,
153.Fn poll
154returns 0.
155If
156.Fn poll
157returns with an error,
158including one due to an interrupted call,
159the
160.Fa fds
161array will be unmodified.
162.Sh ERRORS
163An error return from
164.Fn poll
165indicates:
166.Bl -tag -width Er
167.It Bq Er EFAULT
168.Fa Fds
169points outside the process's allocated address space.
170.It Bq Er EINTR
171A signal was delivered before the time limit expired and
172before any of the selected events occurred.
173.It Bq Er EINVAL
174The
175.Fa nfds
176argument is greater than OPEN_MAX, or the
177.Fa timeout
178argument is less than -1.
179.El
180.Sh BUGS
181The
182.Fn poll
183system call currently does not support devices.
184.Sh SEE ALSO
185.Xr accept 2 ,
186.Xr connect 2 ,
187.Xr kevent 2 ,
188.Xr read 2 ,
189.Xr recv 2 ,
190.Xr select 2 ,
191.Xr send 2 ,
192.Xr write 2
193.Sh HISTORY
194The
195.Fn poll
196function call appeared in
197.At V .
198