1 .\" Copyright (c) 1983, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)select.2 8.2 (Berkeley) 3/25/94
40 .Nd synchronous I/O multiplexing
42 .Fd #include <sys/types.h>
43 .Fd #include <sys/time.h>
44 .Fd #include <unistd.h>
46 .Fn select "int nfds" "fd_set *readfds" "fd_set *writefds" "fd_set *exceptfds" "struct timeval *timeout"
49 .Fn FD_ISSET fd &fdset
53 examines the I/O descriptor sets whose addresses are passed in
58 to see if some of their descriptors
59 are ready for reading, are ready for writing, or have an exceptional
60 condition pending, respectively.
61 The only exceptional condition detectable is out-of-band
62 data received on a socket.
65 descriptors are checked in each set;
66 i.e., the descriptors from 0 through
68 in the descriptor sets are examined.
71 replaces the given descriptor sets
72 with subsets consisting of those descriptors that are ready
73 for the requested operation.
75 returns the total number of ready descriptors in all the sets.
77 The descriptor sets are stored as bit fields in arrays of integers.
78 The following macros are provided for manipulating such descriptor sets:
80 initializes a descriptor set
84 includes a particular descriptor
93 .Fn FD_ISSET fd &fdset
99 The behavior of these macros is undefined if
100 a descriptor value is less than zero or greater than or equal to
102 which is normally at least equal
103 to the maximum number of descriptors supported by the system.
107 is a non-nil pointer, it specifies the maximum interval to wait for the
108 selection to complete. System activity can lengthen the interval by
109 an indeterminate amount.
113 is a nil pointer, the select blocks indefinitely.
115 To effect a poll, the
117 argument should be non-nil, pointing to a zero-valued timeval structure.
124 may be given as nil pointers if no descriptors are of interest.
127 returns the number of ready descriptors that are contained in
129 or -1 if an error occurred.
130 If the time limit expires,
135 returns with an error,
136 including one due to an interrupted call,
137 the descriptor sets will be unmodified.
144 One of the descriptor sets specified an invalid descriptor.
146 A signal was delivered before the time limit expired and
147 before any of the selected events occurred.
149 The specified time limit is invalid. One of its components is
150 negative or too large.
158 .Xr getdtablesize 2 ,
169 In order to accommodate programs which might potentially
170 use a larger number of open files with
173 to increase this size by having the program define
175 before the inclusion of any header which includes
180 is greater than the number of open files,
182 is not guaranteed to examine the unused file descriptors. For historical
185 will always examine the first 256 descriptors.
188 should probably return the time remaining from the original timeout,
189 if any, by modifying the time value in place.
190 This may be implemented in future versions of the system.
191 Thus, it is unwise to assume that the timeout value will be unmodified
198 function call appeared in