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