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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
|
.\" 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>
.\" Modified Thu Feb 24 01:41:09 CET 2000 by aeb
.\" Modified Thu Feb 9 22:32:09 CET 2001 by bert hubert <ahu@ds9a.nl>, aeb
.\" Modified Mon Nov 11 14:35:00 PST 2002 by Ben Woodard <ben@zork.net>
.\"
.\" 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 Sun Mar 12 16:22:57 JST 2000
.\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Updated & Modified Mon Jun 4 01:13:06 JST 2001
.\" by Yuichi SATO <ysato@h4.dion.ne.jp>
.\" Updated & Modified Sun Jul 1 09:58:38 JST 2001 by Yuichi SATO
.\" Updated & Modifedd Mon Jan 14 07:15:45 JST 2002 by Yuichi SATO
.\" Updated 2002-09-24 Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\" Updated 2003-01-19 Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\"
.\"WORD: synchronous Ʊ
.\"WORD: multiplexing ¿Ų
.\"WORD: file descriptor ե뵭һ
.\"WORD: descriptor һ
.\"WORD: macro ޥ
.\"WORD: block (block)
.\"WORD: block ػ(block)
.\"WORD: signal ʥ
.\"WORD: timeout ڤ(timeout)
.\"WORD: portable ܿΤ
.\"
.TH SELECT 2 2001-02-09 "Linux 2.4" "Linux Programmer's Manual"
.SH ̾
select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO \- ¿Ų줿 I/O ƱȤ
.SH
/* POSIX 1003.1-2001 ˽ */
.br
.B #include <sys/select.h>
.sp
/* εʤ˽ */
.br
.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
\fBint pselect(int \fIn\fB, fd_set *\fIreadfds\fB,
fd_set *\fIwritefds\fB, fd_set *\fIexceptfds\fB,
const struct timespec *\fItimeout\fB, const sigset_t *\fIsigmask\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
.B pselect
ξؿϡʣΥե뵭һ (file descriptor) ƻ뤷
ξ֤ѲΤԤġ
.PP
2 ĤδؿεǽƱǤ뤬ʲ 3 ۤʤ:
.TP
(i)
.B select
ؿϡॢȻ֤λ˹¤
.I struct timeval
(áޥñ)Ѥ롣
.B pselect
ؿǤϡ¤
.I struct timespec
(áʥñ)Ѥ롣
.TP
(ii)
.B select
ؿϡĤ֤
.I timeout
ѥ뤳Ȥ롣
.B pselect
ؿϡΥѥѹʤ
.TP
(iii)
.B select
ؿ
.I sigmask
ѥ
.I sigmask
NULL ꤷ
.B pselect
Ʊư롣
.PP
3 ĤΩһҽδƻԤ
.I readfds
˥ꥹȤ줿ΤˤĤƤϡɤ߹ߤǽɤƻ뤹
(Τˤȡ (block) ʤɤळȤǤ뤫Ĵ٤롣
ե뵭һҤեνü (end-of-file)
ɤ߹߲ǽ˴ޤޤ)
.I writefds
˥ꥹȤ줿ΤˤĤƤϡߤ˽ߤǽɤƻ뤹롣
.I exceptfds
ˤΤˤĤƤϡ㳰δƻԤʤλˡºݤˤɤ
һҤξ֤ѲˡƤѹ롣
.PP
뤿 4 ĤΥޥ (macro) Ƥ롣
.B FD_ZERO
Ͻõ (clear) 롣
.B FD_SET
.B FD_CLR
Ͻ˵һҤɲäꤹ롣
.B FD_ISSET
Ͻ˵һҤ뤫ɤĴ٤;
.B select
λ˻ȤǤ롣
.PP
.I n
3 Ĥνˤ뵭һҤκͤ 1 ΤǤ롣
.PP
.I timeout
.B select
֤äƤޤǤηв֤ξ¤Ǥ롣 0 ˤ뤳ȤǤ
ξ
.B select
Ϥ֤äƤ롣
(ˡϥݡ (polling) ԤΤǤ롣)
.I timeout
NULL (ॢȤʤ)
ꤵȡ
.B select
̵¤ (block) 롣
.PP
.I sigmask
ϡʥޥ
.RB ( sigprocmask (2)
) ؤΥݥǤ롣
.I sigmask
NULL Ǥʤ硢
.B pselect
.I sigmask
ؤƤ륷ʥޥǸߤΥʥޥ֤Ƥ顢
`select' ؿ¹Ԥ
λ˥ʥޥΥʥޥ᤹
.PP
ֲ餫Υ٥
(ʥե뵭һҤξѲ) ԤȤˤϡ
֤뤿 atomic ʥƥȤɬפˤʤפȤΤ
.B pselect
ιͤǤ롣
(ʥϥɥ餬ե饰ꤷΤȤ롣
ΤȤե饰ΥƥȤ³
.BR select ()
ƤӽФȡ
ʥ뤬ƥȤľ夫ĸƤӽФľϤ
.BR select ()
ϱʵפ˥ϥƤޤ⤷ʤ
.B pselect
Ȥȡޤʥػ (block) ơäƤ륷ʥ
˾ߤ
.I sigmask
.BR pselect ()
ƤӽФȤǡ뤳ȤǤ롣)
Ԥ Linux ˤ
.IR pselect ()
ƥॳ뤬ʤΤǡ
ߤ glibc2 롼ˤϤζ礬ǽޤޤޤˤʤäƤ롣
.SS ॢ
δؿ˴ޤޤִϢι¤Τϡ
.I <sys/time.h>
ƤꡢΤ褦ˤʤäƤ롣
.RS
.nf
struct timeval {
long tv_sec; /* */
long tv_usec; /* ޥ */
};
.fi
.RE
.RS
.nf
struct timespec {
long tv_sec; /* */
long tv_nsec; /* ʥ */
};
.fi
.RE
(âPOSIX 1003.1-2001 ǤˤĤƤϲΡաפ)
.PP
ñ̰ʲ٤ǥפ¸
ܿ (portable) ι⤤ˡȤơ
3 ĤνƤ
.I n
0
.I timeout
NULL Ǥʤͤꤷ
.B select
ƤӽФȤˡȤäƤ륳ɤ⤢롣
.PP
Linux Ǥϡ
.B select
ؿ
.I timeout
ѹĤ֤ȿǤ褦ˤʤäƤ롣
¾ΤۤȤɤμǤϤΤ褦ˤʤäƤʤ
Τᡢ
.I timeout
Ȥ Linux Υɤ¾Υڥ졼ƥƥذܿ
ȡ롼פ timeval ¤ΤˤΤޤѤ
.B select
ʣԤʤäƤ륳ɤ Linux ذܿˡ꤬롣
.B select
֤äƤ
.I timeout
̤Ǥȹͤ٤Ǥ롣
.\" .PP
.\" BSD ǤϥॢȤäƤ⡢
.\" ե뵭һҥӥåȤѤʤפʹȤ롣
.\" Linux SUSv2 ˽äƤꡢ
.\" ॢȤκݤˤϥӥåȥޥ 0 ˤפȤΤϳΤ˻¤Ǥ롣
.SH ֤
硢
.B select
.B pselect
ϵһҽ˴ޤޤƤ뵭һҤο֤
ⵯ餺˻ڤˤʤä硢
һҤο 0 ˤʤ뤳Ȥ⤢롣
顼ʤ \-1 ֤
.I errno
Ŭڤͤꤵ;
.I timeout
̤ȤʤΤǡ顼äϤƤꤷƤϤʤʤ
.SH 顼
.TP
.B EBADF
Τɤ줫̵ʥե뵭һҤͿ줿
.TP
.B EINTR
ػ (block) Ƥʤʥ (signal)
.TP
.B EINVAL
.I n
顢ޤ
.I timeout
äƤͤǤ롣
.TP
.B ENOMEM
.B select
ơ֥˥Ƥ뤳ȤǤʤä
.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;
/* stdin (fd 0) ƻ뤷Ϥäɽ롣*/
FD_ZERO(&rfds);
FD_SET(0, &rfds);
/* 5 ôִƻ뤹롣*/
tv.tv_sec = 5;
tv.tv_usec = 0;
retval = select(1, &rfds, NULL, NULL, &tv);
/* λǤ tv ͤꤷƤϤʤʤ*/
if (retval == -1)
perror("select()");
else if (retval)
printf("ǡǤޤ\\n");
/* FD_ISSET(0, &rfds) true ˤʤ롣*/
else
printf("5 ð˥ǡϤޤǤ\\n");
return 0;
}
.fi
.SH
4.4BSD
.RB ( select
ؿ 4.2BSD Ǻǽо줷)
BSD åؤΥݡȤƤ BSD ƥ
(System V Ϥޤ) Ȥδ֤Ǥܿ롣 System V ϤǤ
timeout ѿ exit ˥åȤ뤬
BSD ϤǤϤǤʤΤդ뤳ȡ
.PP
.B pselect
ؿ IEEE Std 1003.1g-2000 (POSIX.1g)
POSIX 1003.1-2001 ΰƤ롣
δؿ glibc2.1 ʹߤˤ롣
glibc2.0 ˤƱ̾δؿ뤬
.I sigmask
ѥȤʤ
.SH
fd_set ϸꥵΥХåեǤ롣
FD_SETSIZE ʾͤ
.I fd
Ф FD_CLR FD_SET ¹Ԥ硢
ɤΤ褦ư뤫Ƥʤ
ޤ POSIX Ǥ
.I fd
ͭʥե뵭һҤǤʤФʤʤ
˴ؤơΤʤξǤ timeval ¤Τ 2 ĤΥեɤ
(嵭Τ褦)ξȤ long Ǥꡢ¤Τ
.I <sys/time.h>
Ƥ롣
POSIX 1003.1-2001 βǤϡʲΤ褦ˤʤäƤ롣
.RS
.nf
struct timeval {
time_t tv_sec; /* */
suseconds_t tv_usec; /* ޥ */
};
.fi
.RE
ι¤Τ
.I <sys/select.h>
Ƥꡢǡ time_t suseconds_t
.I <sys/types.h>
Ƥ롣
.LP
ץȥפ˴ؤƤϡΤʤξ
.B select
Ȥϡ
.I <time.h>
롼ɤФ褤
POSIX 1003.1-2001 δĶ
.B select
.B pselect
Ȥϡ
.I <sys/select.h>
롼ɤФ褤
إåե
.I <sys/select.h>
libc4 libc5 ˤϤʤglibc 2.0 ʹߤ¸ߤ롣
Ȥ glibc 2.0 Ǥ
.B pselect
ΥץȥפְäƤ롣
glibc 2.1-2.2.1 Ǥ
.B _GNU_SOURCE
Ƥˡ
.B pselect
롣
glibc 2.2.2-2.2.4 Ǥ
.B _XOPEN_SOURCE
Ƥơͤ 600 ʾǤ
.B pselect
롣
POSIX 1003.1-2001 ʹߤǤϡǥեȤǥץȥפ롣
.SH Ϣ
ͻȻν줿塼ȥꥢȤơ
.BR select_tut (2)
롣
.LP
طꤽʤΤƤ:
.BR accept (2),
.BR connect (2),
.BR poll (2),
.BR read (2),
.BR recv (2),
.BR send (2),
.BR sigprocmask (2),
.BR write (2)
|