|
|
1.1 root 1: .\" Copyright (c) 1983 The Regents of the University of California.
2: .\" All rights reserved.
3: .\"
4: .\" Redistribution and use in source and binary forms are permitted provided
5: .\" that: (1) source distributions retain this entire copyright notice and
6: .\" comment, and (2) distributions including binaries display the following
7: .\" acknowledgement: ``This product includes software developed by the
8: .\" University of California, Berkeley and its contributors'' in the
9: .\" documentation or other materials provided with the distribution and in
10: .\" all advertising materials mentioning features or use of this software.
11: .\" Neither the name of the University nor the names of its contributors may
12: .\" be used to endorse or promote products derived from this software without
13: .\" specific prior written permission.
14: .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
15: .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
16: .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17: .\"
18: .\" @(#)select.2 6.7 (Berkeley) 6/23/90
19: .\"
20: .TH SELECT 2 "June 23, 1990"
21: .UC 5
22: .SH NAME
23: select \- synchronous I/O multiplexing
24: .SH SYNOPSIS
25: .nf
26: .ft B
27: #include <sys/types.h>
28: #include <sys/time.h>
29: .PP
30: .ft B
31: nfound = select(nfds, readfds, writefds, exceptfds, timeout)
32: int nfound, nfds;
33: fd_set *readfds, *writefds, *exceptfds;
34: struct timeval *timeout;
35: .PP
36: .ft B
37: FD_SET(fd, &fdset)
38: FD_CLR(fd, &fdset)
39: FD_ISSET(fd, &fdset)
40: FD_ZERO(&fdset)
41: int fd;
42: fd_set fdset;
43: .fi
44: .SH DESCRIPTION
45: .I Select
46: examines the I/O descriptor sets whose addresses are passed in
47: .IR readfds ,
48: .IR writefds ,
49: and
50: .I exceptfds
51: to see if some of their descriptors
52: are ready for reading, are ready for writing, or have an exceptional
53: condition pending, respectively.
54: The first
55: .I nfds
56: descriptors are checked in each set;
57: i.e. the descriptors from 0 through
58: .IR nfds -1
59: in the descriptor sets are examined.
60: On return,
61: .I select
62: replaces the given descriptor sets
63: with subsets consisting of those descriptors that are ready
64: for the requested operation.
65: The total number of ready descriptors in all the sets is returned in
66: .IR nfound .
67: .PP
68: The descriptor sets are stored as bit fields in arrays of integers.
69: The following macros are provided for manipulating such descriptor sets:
70: .I "FD_ZERO(&fdset)"
71: initializes a descriptor set
72: .I fdset
73: to the null set.
74: .I "FD_SET(fd, &fdset)"
75: includes a particular descriptor
76: .I fd
77: in
78: .IR fdset .
79: .I "FD_CLR(fd, &fdset)"
80: removes
81: .I fd
82: from
83: .IR fdset .
84: .I "FD_ISSET(fd, &fdset)"
85: is nonzero if
86: .I fd
87: is a member of
88: .IR fdset ,
89: zero otherwise.
90: The behavior of these macros is undefined if
91: a descriptor value is less than zero or greater than or equal to
92: .IR FD_SETSIZE ,
93: which is normally at least equal
94: to the maximum number of descriptors supported by the system.
95: .PP
96: If
97: .I timeout
98: is a non-zero pointer, it specifies a maximum interval to wait for the
99: selection to complete. If
100: .I timeout
101: is a zero pointer, the select blocks indefinitely. To affect a poll, the
102: .I timeout
103: argument should be non-zero, pointing to a zero-valued timeval structure.
104: .PP
105: Any of
106: .IR readfds ,
107: .IR writefds ,
108: and
109: .I exceptfds
110: may be given as zero pointers if no descriptors are of interest.
111: .SH "RETURN VALUE
112: .I Select
113: returns the number of ready descriptors that are contained in
114: the descriptor sets,
115: or \-1 if an error occurred.
116: If the time limit expires then
117: .I select
118: returns 0.
119: If
120: .I select
121: returns with an error,
122: including one due to an interrupted call,
123: the descriptor sets will be unmodified.
124: .SH "ERRORS
125: An error return from \fIselect\fP indicates:
126: .TP 15
127: [EBADF]
128: One of the descriptor sets specified an invalid descriptor.
129: .TP 15
130: [EINTR]
131: A signal was delivered before the time limit expired and
132: before any of the selected events occurred.
133: .TP 15
134: [EINVAL]
135: The specified time limit is invalid. One of its components is
136: negative or too large.
137: .SH SEE ALSO
138: accept(2), connect(2), read(2), write(2), recv(2), send(2), getdtablesize(2)
139: .SH BUGS
140: Although the provision of
141: .IR getdtablesize (2)
142: was intended to allow user programs to be written independent
143: of the kernel limit on the number of open files, the dimension
144: of a sufficiently large bit field for select remains a problem.
145: The default size FD_SETSIZE (currently 256) is somewhat larger than
146: the current kernel limit to the number of open files.
147: However, in order to accommodate programs which might potentially
148: use a larger number of open files with select, it is possible
149: to increase this size within a program by providing
150: a larger definition of FD_SETSIZE before the inclusion of <sys/types.h>.
151: .PP
152: .I Select
153: should probably return the time remaining from the original timeout,
154: if any, by modifying the time value in place.
155: This may be implemented in future versions of the system.
156: Thus, it is unwise to assume that the timeout value will be unmodified
157: by the
158: .I select
159: call.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.