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. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" @(#)select.2 8.2 (Berkeley) 3/25/94
29 .\" $FreeBSD: src/lib/libc/sys/select.2,v 1.14.2.5 2001/12/14 18:34:01 ru Exp $
36 .Nd synchronous I/O multiplexing
42 .Fn select "int nfds" "fd_set * restrict readfds" "fd_set * restrict writefds" "fd_set * restrict exceptfds" "struct timeval * restrict timeout"
45 .Fn FD_ISSET fd &fdset
49 examines the I/O descriptor sets whose addresses are passed in
54 to see if some of their descriptors
55 are ready for reading, are ready for writing, or have an exceptional
56 condition pending, respectively.
57 The only exceptional condition detectable is out-of-band
58 data received on a socket.
61 descriptors are checked in each set;
62 i.e., the descriptors from 0 through
64 in the descriptor sets are examined.
67 replaces the given descriptor sets
68 with subsets consisting of those descriptors that are ready
69 for the requested operation.
71 returns the total number of ready descriptors in all the sets.
73 The descriptor sets are stored as bit fields in arrays of integers.
74 The following macros are provided for manipulating such descriptor sets:
76 initializes a descriptor set
80 includes a particular descriptor
89 .Fn FD_ISSET fd &fdset
95 The behavior of these macros is undefined if
96 a descriptor value is less than zero or greater than or equal to
98 which is normally at least equal
99 to the maximum number of descriptors supported by the system.
103 is non-NULL, it specifies the maximum interval to wait for the
104 selection to complete. System activity can lengthen the interval by
105 an indeterminate amount.
109 is a null pointer, the select blocks indefinitely.
111 To effect a poll, the
113 argument should be non-NULL, pointing to a zero-valued timeval structure.
120 may be given as null pointers if no descriptors are of interest.
122 Even if no descriptors are of interest, the timeout works as described,
123 effectively putting the process into an interruptible sleep for the
127 is NULL, the process will block until a signal is received.
130 returns the number of ready descriptors that are contained in
132 or -1 if an error occurred.
133 If the time limit expires,
138 returns with an error,
139 including one due to an interrupted call,
140 the descriptor sets will be unmodified.
147 One of the descriptor sets specified an invalid descriptor.
149 A signal was delivered before the time limit expired and
150 before any of the selected events occurred.
152 The specified time limit is invalid. One of its components is
153 negative or too large.
161 .Xr getdtablesize 2 ,
172 In order to accommodate programs which might potentially
173 use a larger number of open files with
176 to increase this size by having the program define
178 before the inclusion of any header which includes
183 is greater than the number of open files,
185 is not guaranteed to examine the unused file descriptors. For historical
188 will always examine the first 256 descriptors.
192 function call appeared in
196 allows systems to modify the original timeout in place.
197 Thus, it is unwise to assume that the timeout value will be unmodified