File: select.2

package info (click to toggle)
manpages-ja 0.4.0.0.20000115-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 8,760 kB
  • ctags: 3
  • sloc: sh: 6,269; perl: 155; makefile: 55
file content (209 lines) | stat: -rw-r--r-- 5,933 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" This manpage is copyright (C) 1992 Drew Eckhardt,
.\"                 copyright (C) 1995 Michael Shields.
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one
.\" 
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein.  The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\" 
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
.\" Modified 1995-05-18 by Jim Van Zandt <jrv@vanzandt.mv.com>
.\" Sun Feb 11 14:07:00 MET 1996  Martin Schulze  <joey@linux.de>
.\"	* layout slightly modified
.\"
.\" Modified Mon Oct 21 23:05:29 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
.\"
.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
.\"         all rights reserved.
.\" Translated Sun Feb 23 22:43:33 JST 1997
.\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Modified Mon May  5 19:44:46 JST 1997
.\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\"
.\"WORD:	synchronous		Ʊ
.\"WORD:	multiplexing		¿Ų
.\"WORD:	descriptor		ǥץ
.\"WORD:	macro			ޥ
.\"WORD:	block			(block)
.\"WORD:	block			ػ(block)
.\"WORD:	signal			ʥ
.\"WORD:	timeout			ڤ(timeout)
.\"WORD:	portable		ܿΤ
.\"
.TH SELECT 2 "February 11, 1996" "Linux 1.2" "Linux Programmer's Manual"
.SH ̾
select, FD_CLR, FD_ISSET, FD_SET, FD_ZERO \- ¿Ų줿 I/O ƱȤ
.SH 
.B #include <sys/time.h>
.br
.B #include <sys/types.h>
.br
.B #include <unistd.h>
.sp
\fBint select(int \fIn\fB, fd_set *\fIreadfds\fB,
fd_set *\fIwritefds\fB, fd_set *\fIexceptfds\fB,
struct timeval *\fItimeout\fB);
.sp
.BI "FD_CLR(int " fd ", fd_set *" set );
.br
.BI "FD_ISSET(int " fd ", fd_set *" set );
.br
.BI "FD_SET(int " fd ", fd_set *" set );
.br
.BI "FD_ZERO(fd_set *" set );
.fi
.SH 
.B select
ϤĤΥե롦ǥץ(file descriptor)ξ֤
ѲΤԤġ
.PP
ĤΩǥץνƻ뤹롣
.I readfds
˥ꥹȤ줿Τɤ߹ߤǽɤƻ뤹롣
.I writefds
˥ꥹȤ줿ΤϤˤ˽񤭹ߤǽɤƻ뤹롣
.I exceptfds
ˤΤ㳰δƻԤʤλˡºݤˤɤ
ǥץξ֤Ѳ˽礬ѹ롣
.PP
뤿˻ͤĤΥޥ(macro)󶡤롣
.B FD_ZERO
Ͻõ(clear)롣
.B FD_SET

.B FD_CLR
Ͻ˥ǥץäꤹ롣
.B FD_ISSET
Ͻ˥ǥץ뤫ɤĴ٤; 
.B select
λǤ롣
.PP
.I n
ϻĤνˤǥץκͤ 1 ­Ρ
.PP
.I timeout

.B select
֤äƤޤǤηв֤ξ¡ϥˤ뤳ȤǤ
ξ
.B select
Ϥ֤äƤ롣⤷
.I timeout
 NULL (ڤ(timeout)̵)
ꤵȡ
.B select
̵¤(block)롣
.SH ֤
.B select 
ϥǥץ˴ޤޤƤǥ꥿ο֤
ζ̣ݤ˻ڤˤʤäϥˤʤ뤳Ȥ⤢롣
顼ʤ -1 ֤
.I errno
Ŭڤͤꤵ; 
.I timeout
̤Ȥʤ롢顼θϤƤϿǤʤ
.SH 顼
.TP
.B EBADF
Τɤ줫̵ʥեǥץͿ줿
.TP
.B EINTR 
ػ(block)Ƥʤʥ(signal)
.TP
.B EINVAL 
.I n
Ǥ롣
.TP
.B ENOMEM
.B select
ơ֥˥꡼Ƥ뤳ȤǤʤä
.SH 
.B select
ƤӽФɤˤϻĤνƤ˶ꤷ
.I n
˥
.I timeout
 NULL Ǥʤͤꤷܿ(portable)Τˡñ̰ʲ
꡼(sleep)¸ƤΤ롣
.PP
Linux Ǥϡ
.I timeout
(sleep)Ƥʤ֤̤ȿǤ褦˽줿
¾ΤۤȤɤΥץơǤϤΤ褦ˤʤäƤʤ

.I timeout
ɤ߼ Linux Υɤ¾Υڥ졼ƥ󥰡ƥذܿ
 롼פ timval ¤Τ˺ƻѤʣ 
.BR select
ԤʤäƤ륳ɤ Linux ذܿξ򵯤
.B select
֤äƤ
.I timeout
̤Ǥȹͤ٤Ǥ롣
.SH 
.nf
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

int
main(void)
{
    fd_set rfds;
    struct timeval tv;
    int retval;

    /* Watch stdin (fd 0) to see when it has input. */
    FD_ZERO(&rfds);
    FD_SET(0, &rfds);
    /* Wait up to five seconds. */
    tv.tv_sec = 5;
    tv.tv_usec = 0;

    retval = select(1, &rfds, NULL, NULL, &tv);
    /* Don't rely on the value of tv now! */

    if (retval)
        printf("Data is available now.\\n");
        /* FD_ISSET(0, &rfds) will be true. */
    else
        printf("No data within five seconds.\\n");

    exit(0);
}
.fi

.SH 
4.4BSD (
.B select
ؿ 4.2BSD Ǻǽ˸줿) ̤ BSD Υåؤ򥵥ݡȤ
BSD ʳΥƥ(System V Ѽޤ)ؤΰܿޤϤ줫ΰܿ
Ǥ롣 System V ѼŵŪ timeout ѿꤹ
ΤФơBSDѼǤꤷʤȤդ뤳ȡ
.SH Ϣ
.BR accept (2),
.BR connect (2),
.BR poll (2),
.BR read (2),
.BR recv (2),
.BR send (2),
.BR write (2)