12209d3c8SRichard Lowe.\" 2*66492cf0SYuri Pankov.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for 3*66492cf0SYuri Pankov.\" permission to reproduce portions of its copyrighted documentation. 4*66492cf0SYuri Pankov.\" Original documentation from The Open Group can be obtained online at 5*66492cf0SYuri Pankov.\" http://www.opengroup.org/bookstore/. 6*66492cf0SYuri Pankov.\" 7*66492cf0SYuri Pankov.\" The Institute of Electrical and Electronics Engineers and The Open 8*66492cf0SYuri Pankov.\" Group, have given us permission to reprint portions of their 9*66492cf0SYuri Pankov.\" documentation. 10*66492cf0SYuri Pankov.\" 11*66492cf0SYuri Pankov.\" In the following statement, the phrase ``this text'' refers to portions 12*66492cf0SYuri Pankov.\" of the system documentation. 13*66492cf0SYuri Pankov.\" 14*66492cf0SYuri Pankov.\" Portions of this text are reprinted and reproduced in electronic form 15*66492cf0SYuri Pankov.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, 16*66492cf0SYuri Pankov.\" Standard for Information Technology -- Portable Operating System 17*66492cf0SYuri Pankov.\" Interface (POSIX), The Open Group Base Specifications Issue 6, 18*66492cf0SYuri Pankov.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics 19*66492cf0SYuri Pankov.\" Engineers, Inc and The Open Group. In the event of any discrepancy 20*66492cf0SYuri Pankov.\" between these versions and the original IEEE and The Open Group 21*66492cf0SYuri Pankov.\" Standard, the original IEEE and The Open Group Standard is the referee 22*66492cf0SYuri Pankov.\" document. The original Standard can be obtained online at 23*66492cf0SYuri Pankov.\" http://www.opengroup.org/unix/online.html. 242209d3c8SRichard Lowe.\" 25c10c16deSRichard Lowe.\" This notice shall appear on any product containing this material. 262209d3c8SRichard Lowe.\" 272209d3c8SRichard Lowe.\" The contents of this file are subject to the terms of the 282209d3c8SRichard Lowe.\" Common Development and Distribution License (the "License"). 292209d3c8SRichard Lowe.\" You may not use this file except in compliance with the License. 302209d3c8SRichard Lowe.\" 312209d3c8SRichard Lowe.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 322209d3c8SRichard Lowe.\" or http://www.opensolaris.org/os/licensing. 332209d3c8SRichard Lowe.\" See the License for the specific language governing permissions 342209d3c8SRichard Lowe.\" and limitations under the License. 352209d3c8SRichard Lowe.\" 362209d3c8SRichard Lowe.\" When distributing Covered Code, include this CDDL HEADER in each 372209d3c8SRichard Lowe.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 382209d3c8SRichard Lowe.\" If applicable, add the following below this CDDL HEADER, with the 392209d3c8SRichard Lowe.\" fields enclosed by brackets "[]" replaced with your own identifying 402209d3c8SRichard Lowe.\" information: Portions Copyright [yyyy] [name of copyright owner] 412209d3c8SRichard Lowe.\" 42*66492cf0SYuri Pankov.\" 43*66492cf0SYuri Pankov.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. 44*66492cf0SYuri Pankov.\" Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved. 452209d3c8SRichard Lowe.\" 462209d3c8SRichard Lowe.Dd "Dec 28, 2016" 472209d3c8SRichard Lowe.Dt SELECT 3C 482209d3c8SRichard Lowe.Os 492209d3c8SRichard Lowe.Sh NAME 502209d3c8SRichard Lowe.Nm select , 512209d3c8SRichard Lowe.Nm pselect , 522209d3c8SRichard Lowe.Nm FD_SET , 532209d3c8SRichard Lowe.Nm FD_CLR , 542209d3c8SRichard Lowe.Nm FD_ISSET , 552209d3c8SRichard Lowe.Nm FD_ZERO 562209d3c8SRichard Lowe.Nd synchronous I/O multiplexing 572209d3c8SRichard Lowe.Sh SYNOPSIS 582209d3c8SRichard Lowe.In sys/time.h 592209d3c8SRichard Lowe.Ft int 602209d3c8SRichard Lowe.Fo select 612209d3c8SRichard Lowe.Fa "int nfds" 622209d3c8SRichard Lowe.Fa "fd_set *restrict readfds" 632209d3c8SRichard Lowe.Fa "fd_set *restrict writefds" 642209d3c8SRichard Lowe.Fa "fd_set *restrict errorfds" 652209d3c8SRichard Lowe.Fa "struct timeval *restrict timeout" 662209d3c8SRichard Lowe.Fc 672209d3c8SRichard Lowe.Ft int 682209d3c8SRichard Lowe.Fo pselect 692209d3c8SRichard Lowe.Fa "int nfds" 702209d3c8SRichard Lowe.Fa "fd_set *restrict readfds" 712209d3c8SRichard Lowe.Fa "fd_set *restrict writefds" 722209d3c8SRichard Lowe.Fa "fd_set *restrict errorfds" 732209d3c8SRichard Lowe.Fa "const struct timespec *restrict timeout" 742209d3c8SRichard Lowe.Fa "const sigset_t *restrict sigmask" 752209d3c8SRichard Lowe.Fc 762209d3c8SRichard Lowe.Ft void 772209d3c8SRichard Lowe.Fo FD_SET 782209d3c8SRichard Lowe.Fa "int fd" 792209d3c8SRichard Lowe.Fa "fd_set *fdset" 802209d3c8SRichard Lowe.Fc 812209d3c8SRichard Lowe.Ft void 822209d3c8SRichard Lowe.Fo FD_CLR 832209d3c8SRichard Lowe.Fa "int fd" 842209d3c8SRichard Lowe.Fa "fd_set *fdset" 852209d3c8SRichard Lowe.Fc 862209d3c8SRichard Lowe.Ft int 872209d3c8SRichard Lowe.Fo FD_ISSET 882209d3c8SRichard Lowe.Fa "int fd" 892209d3c8SRichard Lowe.Fa "fd_set *fd_set" 902209d3c8SRichard Lowe.Fc 912209d3c8SRichard Lowe.Ft void 922209d3c8SRichard Lowe.Fo FD_ZERO 932209d3c8SRichard Lowe.Fa "fd_set *fdset" 942209d3c8SRichard Lowe.Fc 952209d3c8SRichard Lowe.Sh DESCRIPTION 962209d3c8SRichard LoweThe 972209d3c8SRichard Lowe.Fn pselect 982209d3c8SRichard Lowefunction examines the file descriptor sets whose addresses 992209d3c8SRichard Loweare passed in the 1002209d3c8SRichard Lowe.Fa readfds , 1012209d3c8SRichard Lowe.Fa writefds , 1022209d3c8SRichard Loweand 1032209d3c8SRichard Lowe.Fa errorfds 1042209d3c8SRichard Loweparameters to see if some of their descriptors are ready for reading, 1052209d3c8SRichard Loweare ready for writing, or have an exceptional condition pending, 1062209d3c8SRichard Lowerespectively. 1072209d3c8SRichard Lowe.Pp 1082209d3c8SRichard LoweThe 1092209d3c8SRichard Lowe.Fn select 1102209d3c8SRichard Lowefunction is equivalent to the 1112209d3c8SRichard Lowe.Fn pselect 1122209d3c8SRichard Lowefunction, except as follows: 1132209d3c8SRichard Lowe.Bl -bullet 1142209d3c8SRichard Lowe.It 1152209d3c8SRichard LoweFor the 1162209d3c8SRichard Lowe.Fn select 1172209d3c8SRichard Lowefunction, the timeout period is given in seconds and 1182209d3c8SRichard Lowemicroseconds in an argument of type 1192209d3c8SRichard Lowe.Vt struct timeval , 1202209d3c8SRichard Lowewhereas for the 1212209d3c8SRichard Lowe.Fn pselect 1222209d3c8SRichard Lowefunction the timeout period is given in seconds and nanoseconds 1232209d3c8SRichard Lowein an argument of type 1242209d3c8SRichard Lowe.Vt struct timespec 1252209d3c8SRichard Lowe.It 1262209d3c8SRichard LoweThe 1272209d3c8SRichard Lowe.Fn select 1282209d3c8SRichard Lowefunction has no 1292209d3c8SRichard Lowe.Fa sigmask 13072d3dbb9SYuri Pankovargument. 13172d3dbb9SYuri PankovIt behaves as 1322209d3c8SRichard Lowe.Fn pselect 1332209d3c8SRichard Lowedoes when 1342209d3c8SRichard Lowe.Fa sigmask 1352209d3c8SRichard Loweis a null pointer. 1362209d3c8SRichard Lowe.It 1372209d3c8SRichard LoweUpon successful completion, the 1382209d3c8SRichard Lowe.Fn select 1392209d3c8SRichard Lowefunction might modify the object pointed to by the 1402209d3c8SRichard Lowe.Fa Itimeout 1412209d3c8SRichard Loweargument. 1422209d3c8SRichard Lowe.El 1432209d3c8SRichard Lowe.Pp 1442209d3c8SRichard LoweThe 1452209d3c8SRichard Lowe.Fn select 1462209d3c8SRichard Loweand 1472209d3c8SRichard Lowe.Fn pselect 14872d3dbb9SYuri Pankovfunctions support regular files, terminal and pseudo-terminal devices, 14972d3dbb9SYuri PankovSTREAMS-based files, FIFOs, pipes, and sockets. 15072d3dbb9SYuri PankovThe behavior of 1512209d3c8SRichard Lowe.Fn select 1522209d3c8SRichard Loweand 1532209d3c8SRichard Lowe.Fn pselect 1542209d3c8SRichard Loweon file descriptors that refer to other types of file is unspecified. 1552209d3c8SRichard Lowe.Pp 1562209d3c8SRichard LoweThe 1572209d3c8SRichard Lowe.Fa nfds 1582209d3c8SRichard Loweargument specifies the range of file descriptors to be tested. 1592209d3c8SRichard LoweThe first 1602209d3c8SRichard Lowe.Fa nfds 1612209d3c8SRichard Lowedescriptors are checked in each set; that is, the 1622209d3c8SRichard Lowedescriptors from zero through 1632209d3c8SRichard Lowe.Dq Li nfds - 1 1642209d3c8SRichard Lowein the descriptor sets are examined. 1652209d3c8SRichard Lowe.Pp 1662209d3c8SRichard LoweIf the 1672209d3c8SRichard Lowe.Fa readfs 1682209d3c8SRichard Loweargument is not a null pointer, it points to an object of 1692209d3c8SRichard Lowetype 1702209d3c8SRichard Lowe.Vt fd_set 1712209d3c8SRichard Lowethat on input specifies the file descriptors to be checked 172c10c16deSRichard Lowefor being ready to read, and on output indicates which file descriptors are 173c10c16deSRichard Loweready to read. 1742209d3c8SRichard Lowe.Pp 1752209d3c8SRichard LoweIf the 1762209d3c8SRichard Lowe.Fa writefs 1772209d3c8SRichard Loweargument is not a null pointer, it points to an object of 1782209d3c8SRichard Lowetype 1792209d3c8SRichard Lowe.Vt fd_set 1802209d3c8SRichard Lowethat on input specifies the file descriptors to be checked 181c10c16deSRichard Lowefor being ready to write, and on output indicates which file descriptors are 182c10c16deSRichard Loweready to write. 1832209d3c8SRichard Lowe.Pp 1842209d3c8SRichard LoweIf the 1852209d3c8SRichard Lowe.Fa errorfds 1862209d3c8SRichard Loweargument is not a null pointer, it points to an object of 1872209d3c8SRichard Lowetype 1882209d3c8SRichard Lowe.Vt fd_set 1892209d3c8SRichard Lowethat on input specifies the file descriptors to be checked 190c10c16deSRichard Lowefor error conditions pending, and on output indicates which file descriptors 191c10c16deSRichard Lowehave error conditions pending. 1922209d3c8SRichard Lowe.Pp 1932209d3c8SRichard LoweUpon successful completion, the objects pointed to by the 1942209d3c8SRichard Lowe.Fa readfs , 1952209d3c8SRichard Lowe.Fa writefs , 1962209d3c8SRichard Loweand 1972209d3c8SRichard Lowe.Fa errorfds 19872d3dbb9SYuri Pankovarguments are modified to indicate which file descriptors are ready for reading, 19972d3dbb9SYuri Pankovready for writing, or have an error condition pending, respectively, and return 20072d3dbb9SYuri Pankovthe total number of ready descriptors in all the output sets. 20172d3dbb9SYuri PankovFor each file descriptor less than 2022209d3c8SRichard Lowe.Fa nfds , 20372d3dbb9SYuri Pankovthe corresponding bit will be set on successful completion if it was set on 20472d3dbb9SYuri Pankovinput and the associated condition is true for that file descriptor. 2052209d3c8SRichard Lowe.Pp 206c10c16deSRichard LoweIf none of the selected descriptors are ready for the requested operation, the 2072209d3c8SRichard Lowe.Fn select 2082209d3c8SRichard Loweor 2092209d3c8SRichard Lowe.Fn pselect 2102209d3c8SRichard Lowefunction blocks until at least one of the 211c10c16deSRichard Lowerequested operations becomes ready, until the timeout occurs, or until 21272d3dbb9SYuri Pankovinterrupted by a signal. 21372d3dbb9SYuri PankovThe 2142209d3c8SRichard Lowe.Fa timeout 2152209d3c8SRichard Loweparameter controls how long the 2162209d3c8SRichard Lowe.Fn select 2172209d3c8SRichard Loweor 2182209d3c8SRichard Lowe.Fn pselect 21972d3dbb9SYuri Pankovfunction takes before timing out. 22072d3dbb9SYuri PankovIf the 2212209d3c8SRichard Lowe.Fa timeout 2222209d3c8SRichard Loweparameter is not a null pointer, it specifies a maximum interval 22372d3dbb9SYuri Pankovto wait for the selection to complete. 22472d3dbb9SYuri PankovIf the specified time interval expires without any requested operation becoming 22572d3dbb9SYuri Pankovready, the function returns. 22672d3dbb9SYuri PankovIf the 2272209d3c8SRichard Lowe.Fa timeout 2282209d3c8SRichard Loweparameter is a null pointer, then the call to 2292209d3c8SRichard Lowe.Fn select 2302209d3c8SRichard Loweor 2312209d3c8SRichard Lowe.Fn pselect 2322209d3c8SRichard Loweblocks indefinitely until at least one descriptor meets the 23372d3dbb9SYuri Pankovspecified criteria. 23472d3dbb9SYuri PankovTo effect a poll, the 2352209d3c8SRichard Lowe.Fa timeout 2362209d3c8SRichard Loweparameter should not be a null pointer, and should point to a zero-valued 2372209d3c8SRichard Lowe.Vt timespec 2382209d3c8SRichard Lowestructure. 2392209d3c8SRichard Lowe.Pp 2402209d3c8SRichard LoweThe use of a 2412209d3c8SRichard Lowe.Fa timeout 2422209d3c8SRichard Lowedoes not affect any pending timers set up by 2432209d3c8SRichard Lowe.Xr alarm 2 , 2442209d3c8SRichard Lowe.Xr ualarm 3C , 2452209d3c8SRichard Loweor 2462209d3c8SRichard Lowe.Xr setitimer 2 . 2472209d3c8SRichard Lowe.Pp 2482209d3c8SRichard LoweIf 2492209d3c8SRichard Lowe.Fa sigmask 2502209d3c8SRichard Loweis not a null pointer, then the 2512209d3c8SRichard Lowe.Fn pselect 2522209d3c8SRichard Lowefunction replaces the signal mask of the process by the set of signals pointed 2532209d3c8SRichard Loweto by 2542209d3c8SRichard Lowe.Fa sigmask 2552209d3c8SRichard Lowebefore examining the descriptors, and restores the signal mask of 256c10c16deSRichard Lowethe process before returning. 2572209d3c8SRichard Lowe.Pp 258c10c16deSRichard LoweA descriptor is considered ready for reading when a call to an input function 2592209d3c8SRichard Lowewith 2602209d3c8SRichard Lowe.Dv O_NONBLOCK 2612209d3c8SRichard Loweclear would not block, whether or not the function would 26272d3dbb9SYuri Pankovtransfer data successfully. 26372d3dbb9SYuri Pankov(The function might return data, an end-of-file indication, or an error other 26472d3dbb9SYuri Pankovthan one indicating that it is blocked, and in each of these cases the 26572d3dbb9SYuri Pankovdescriptor will be considered ready for reading.) 2662209d3c8SRichard Lowe.Pp 267c10c16deSRichard LoweA descriptor is considered ready for writing when a call to an output function 2682209d3c8SRichard Lowewith 2692209d3c8SRichard Lowe.Dv O_NONBLOCK 2702209d3c8SRichard Loweclear would not block, whether or not the function would 271c10c16deSRichard Lowetransfer data successfully. 2722209d3c8SRichard Lowe.Pp 273c10c16deSRichard LoweIf a socket has a pending error, it is considered to have an exceptional 27472d3dbb9SYuri Pankovcondition pending. 27572d3dbb9SYuri PankovOtherwise, what constitutes an exceptional condition is file type-specific. 27672d3dbb9SYuri PankovFor a file descriptor for use with a socket, it is protocol-specific except as 27772d3dbb9SYuri Pankovnoted below. 27872d3dbb9SYuri PankovFor other file types, if the operation is meaningless for a particular file 27972d3dbb9SYuri Pankovtype, 2802209d3c8SRichard Lowe.Fn select 2812209d3c8SRichard Loweor 2822209d3c8SRichard Lowe.Fn pselect 283c10c16deSRichard Loweindicates that the descriptor is ready for read or write operations and 284c10c16deSRichard Loweindicates that the descriptor has no exceptional condition pending. 2852209d3c8SRichard Lowe.Pp 286c10c16deSRichard LoweIf a descriptor refers to a socket, the implied input function is the 2872209d3c8SRichard Lowe.Xr recvmsg 3XNET 2882209d3c8SRichard Lowefunction with parameters requesting normal and ancillary 289c10c16deSRichard Lowedata, such that the presence of either type causes the socket to be marked as 29072d3dbb9SYuri Pankovreadable. 29172d3dbb9SYuri PankovThe presence of out-of-band data is checked if the socket option 2922209d3c8SRichard Lowe.Dv SO_OOBINLINE 2932209d3c8SRichard Lowehas been enabled, as out-of-band data is enqueued with 29472d3dbb9SYuri Pankovnormal data. 29572d3dbb9SYuri PankovIf the socket is currently listening, then it is marked as readable if an 29672d3dbb9SYuri Pankovincoming connection request has been received, and a call to the accept function 29772d3dbb9SYuri Pankovcompletes without blocking. 2982209d3c8SRichard Lowe.Pp 299c10c16deSRichard LoweIf a descriptor refers to a socket, the implied output function is the 3002209d3c8SRichard Lowe.Xr sendmsg 3XNET 3012209d3c8SRichard Lowefunction supplying an amount of normal data equal to the 3022209d3c8SRichard Lowecurrent value of the 3032209d3c8SRichard Lowe.Dv SO_SNDLOWAT 30472d3dbb9SYuri Pankovoption for the socket. 30572d3dbb9SYuri PankovIf a non-blocking call to the connect function has been made for a socket, and 30672d3dbb9SYuri Pankovthe connection attempt has either succeeded or failed leaving a pending error, 30772d3dbb9SYuri Pankovthe socket is marked as writable. 3082209d3c8SRichard Lowe.Pp 309c10c16deSRichard LoweA socket is considered to have an exceptional condition pending if a receive 3102209d3c8SRichard Loweoperation with 3112209d3c8SRichard Lowe.Dv O_NONBLOCK 3122209d3c8SRichard Loweclear for the open file description and with the 3132209d3c8SRichard Lowe.Dv MSG_OOB 31472d3dbb9SYuri Pankovflag set would return out-of-band data without blocking. 31572d3dbb9SYuri Pankov(It is protocol-specific whether the 3162209d3c8SRichard Lowe.Dv MSG_OOB 31772d3dbb9SYuri Pankovflag would be used to read out-of-band data.) 31872d3dbb9SYuri PankovA socket will also be considered to have an exceptional condition pending if an 31972d3dbb9SYuri Pankovout-of-band data mark is present in the receive queue. 3202209d3c8SRichard Lowe.Pp 321c10c16deSRichard LoweA file descriptor for a socket that is listening for connections will indicate 32272d3dbb9SYuri Pankovthat it is ready for reading, when connections are available. 32372d3dbb9SYuri PankovA file descriptor for a socket that is connecting asynchronously will indicate 32472d3dbb9SYuri Pankovthat it is ready for writing, when a connection has been established. 3252209d3c8SRichard Lowe.Pp 326c10c16deSRichard LoweSelecting true for reading on a socket descriptor upon which a 3272209d3c8SRichard Lowe.Xr listen 3XNET 3282209d3c8SRichard Lowecall has been performed indicates that a subsequent 3292209d3c8SRichard Lowe.Xr accept 3XNET 3302209d3c8SRichard Lowecall on that descriptor will not block. 3312209d3c8SRichard Lowe.Pp 3322209d3c8SRichard LoweIf the 3332209d3c8SRichard Lowe.Fa timeout 3342209d3c8SRichard Loweargument is not a null pointer, it points to an object of type 3352209d3c8SRichard Lowe.Vt struct timeval 3362209d3c8SRichard Lowethat specifies a maximum interval to wait for the 33772d3dbb9SYuri Pankovselection to complete. 33872d3dbb9SYuri PankovIf the 33972d3dbb9SYuri Pankov.Fa timeout 34072d3dbb9SYuri Pankovargument points to an object of type 3412209d3c8SRichard Lowe.Vt struct timeval 3422209d3c8SRichard Lowewhose members are 0, 3432209d3c8SRichard Lowe.Fn select 3442209d3c8SRichard Lowedoes not block. 3452209d3c8SRichard LoweIf the 3462209d3c8SRichard Lowe.Fa timeout 3472209d3c8SRichard Loweargument is a null pointer, 3482209d3c8SRichard Lowe.Fn select 3492209d3c8SRichard Loweblocks until an event causes one of the masks to be returned with a valid 35072d3dbb9SYuri Pankov(non-zero) value. 35172d3dbb9SYuri PankovIf the time limit expires before any event occurs that would cause one of the 35272d3dbb9SYuri Pankovmasks to be set to a non-zero value, 3532209d3c8SRichard Lowe.Fn select 3542209d3c8SRichard Lowecompletes successfully and returns 0. 3552209d3c8SRichard Lowe.Pp 3562209d3c8SRichard LoweIf the 3572209d3c8SRichard Lowe.Fa readfs , 3582209d3c8SRichard Lowe.Fa writefds , 3592209d3c8SRichard Loweand 3602209d3c8SRichard Lowe.Fa errorfds 3612209d3c8SRichard Lowearguments are all null pointers and the 3622209d3c8SRichard Lowe.Fa timeout 3632209d3c8SRichard Loweargument is not a null pointer, 3642209d3c8SRichard Lowe.Fn select 3652209d3c8SRichard Loweor 3662209d3c8SRichard Lowe.Fn pselect 3672209d3c8SRichard Loweblocks for the time specified, or until interrupted by a 36872d3dbb9SYuri Pankovsignal. 36972d3dbb9SYuri PankovIf the 3702209d3c8SRichard Lowe.Fa readfds , 3712209d3c8SRichard Lowe.Fa writefds , 3722209d3c8SRichard Loweand 3732209d3c8SRichard Lowe.Fa errorfds 3742209d3c8SRichard Lowearguments are all null pointers and the 3752209d3c8SRichard Lowe.Fa timeout 3762209d3c8SRichard Loweargument is a null pointer, 3772209d3c8SRichard Lowe.Fn select 3782209d3c8SRichard Loweblocks until interrupted by a signal. 3792209d3c8SRichard Lowe.Pp 380c10c16deSRichard LoweFile descriptors associated with regular files always select true for ready to 381c10c16deSRichard Loweread, ready to write, and error conditions. 3822209d3c8SRichard Lowe.Pp 3832209d3c8SRichard LoweOn failure, the objects pointed to by the 3842209d3c8SRichard Lowe.Fa readfds , 3852209d3c8SRichard Lowe.Fa writefds , 3862209d3c8SRichard Loweand 3872209d3c8SRichard Lowe.Fa errorfds 38872d3dbb9SYuri Pankovarguments are not modified. 38972d3dbb9SYuri PankovIf the timeout interval expires without the specified condition being true for 39072d3dbb9SYuri Pankovany of the specified file descriptors, the objects pointed to by the 3912209d3c8SRichard Lowe.Fa readfds , 3922209d3c8SRichard Lowe.Fa writefds , 3932209d3c8SRichard Loweand 3942209d3c8SRichard Lowe.Fa errorfds 3952209d3c8SRichard Lowearguments have all bits set to 0. 3962209d3c8SRichard Lowe.Pp 3972209d3c8SRichard LoweFile descriptor masks of type 3982209d3c8SRichard Lowe.Vt fd_set 3992209d3c8SRichard Lowecan be initialized and tested with the macros 4002209d3c8SRichard Lowe.Fn FD_CLR , 4012209d3c8SRichard Lowe.Fn FD_ISSET , 4022209d3c8SRichard Lowe.Fn FD_SET , 4032209d3c8SRichard Loweand 4042209d3c8SRichard Lowe.Fn FD_ZERO . 4052209d3c8SRichard Lowe.Bl -tag -width indent 4062209d3c8SRichard Lowe.It Fn FD_CLR "fd" "&fdset" 4072209d3c8SRichard LoweClears the bit for the file descriptor 4082209d3c8SRichard Lowe.Fa fd 4092209d3c8SRichard Lowein the file descriptor set 4102209d3c8SRichard Lowe.Fa fdset . 4112209d3c8SRichard Lowe.It Fn FD_ISSET "fd" "&fdset" 4122209d3c8SRichard LoweReturns a non-zero value if the bit for the file descriptor 4132209d3c8SRichard Lowe.Fa fd 4142209d3c8SRichard Loweis set in 4152209d3c8SRichard Lowethe file descriptor set pointed to by 4162209d3c8SRichard Lowe.Fa fdset , 4172209d3c8SRichard Loweand 0 otherwise. 4182209d3c8SRichard Lowe.It Fn FD_SET "fd" "&fdset" 4192209d3c8SRichard LoweSets the bit for the file descriptor 4202209d3c8SRichard Lowe.Fa fd 4212209d3c8SRichard Lowein the file descriptor set 4222209d3c8SRichard Lowe.Fa fdset 4232209d3c8SRichard Lowe.It Fn FD_ZERO "&fdset" 424c10c16deSRichard LoweInitializes the file descriptor set \fIfdset\fR to have zero bits for all file 425c10c16deSRichard Lowedescriptors. 4262209d3c8SRichard Lowe.El 4272209d3c8SRichard Lowe.Pp 4282209d3c8SRichard LoweThe behavior of these macros is undefined if the 4292209d3c8SRichard Lowe.Fa fd 4302209d3c8SRichard Loweargument is less than 0 or greater than or equal to 4312209d3c8SRichard Lowe.Dv FD_SETSIZE , 4322209d3c8SRichard Loweor if 4332209d3c8SRichard Lowe.Fa fd 4342209d3c8SRichard Loweis not a valid file descriptor, or if any of the arguments are expressions 4352209d3c8SRichard Lowewith side effects. 4362209d3c8SRichard Lowe.Sh RETURN VALUES 4372209d3c8SRichard LoweOn successful completion, 4382209d3c8SRichard Lowe.Fn select 4392209d3c8SRichard Loweand 4402209d3c8SRichard Lowe.Fn pselect 4412209d3c8SRichard Lowereturn the total 44272d3dbb9SYuri Pankovnumber of bits set in the bit masks. 44372d3dbb9SYuri PankovOtherwise, 4442209d3c8SRichard Lowe.Sy 1 4452209d3c8SRichard Loweis returned and 4462209d3c8SRichard Lowe.Dv errno 4472209d3c8SRichard Loweis set to indicate the error. 4482209d3c8SRichard Lowe.Pp 4492209d3c8SRichard LoweThe 4502209d3c8SRichard Lowe.Fn FD_CLR , 4512209d3c8SRichard Lowe.Fn FD_SET , 4522209d3c8SRichard Loweand 4532209d3c8SRichard Lowe.Fn FD_ZERO , 4542209d3c8SRichard Lowemacros return no value. 4552209d3c8SRichard LoweThe 4562209d3c8SRichard Lowe.Fn FD_ISSET 4572209d3c8SRichard Lowemacro returns a non-zero value if the bit for the file 4582209d3c8SRichard Lowedescriptor 4592209d3c8SRichard Lowe.Fa fd 4602209d3c8SRichard Loweis set in the file descriptor set pointed to by 4612209d3c8SRichard Lowe.Fa fdset , 4622209d3c8SRichard Loweand 4632209d3c8SRichard Lowe.Sy 0 4642209d3c8SRichard Loweotherwise. 4652209d3c8SRichard Lowe.Sh ERRORS 4662209d3c8SRichard LoweThe 4672209d3c8SRichard Lowe.Fn select 4682209d3c8SRichard Loweand 4692209d3c8SRichard Lowe.Fn pselect 4702209d3c8SRichard Lowefunctions will fail if: 4712209d3c8SRichard Lowe.Bl -tag -width indent 4722209d3c8SRichard Lowe.It Er EBADF 473c10c16deSRichard LoweOne or more of the file descriptor sets specified a file descriptor that is not 474c10c16deSRichard Lowea valid open file descriptor. 4752209d3c8SRichard Lowe.It Er EINTR 476c10c16deSRichard LoweThe function was interrupted before any of the selected events occurred and 477c10c16deSRichard Lowebefore the timeout interval expired. 4782209d3c8SRichard Lowe.Pp 4792209d3c8SRichard LoweIf 4802209d3c8SRichard Lowe.Dv SA_RESTART 4812209d3c8SRichard Lowehas been set for the interrupting signal, it is implementation-dependent whether 4822209d3c8SRichard Lowe.Fn select 4832209d3c8SRichard Lowerestarts or returns with 4842209d3c8SRichard Lowe.Dv EINTR 4852209d3c8SRichard Lowe.It Er EINVAL 486c10c16deSRichard LoweAn invalid timeout interval was specified. 4872209d3c8SRichard Lowe.It Er EINVAL 4882209d3c8SRichard LoweThe 4892209d3c8SRichard Lowe.Fa nfds 4902209d3c8SRichard Loweargument is less than 0 or greater than 4912209d3c8SRichard Lowe.Dv FD_SETSIZE . 4922209d3c8SRichard Lowe.It Er EINVAL 493c10c16deSRichard LoweOne of the specified file descriptors refers to a STREAM or multiplexer that is 494c10c16deSRichard Lowelinked (directly or indirectly) downstream from a multiplexer. 4952209d3c8SRichard Lowe.It Er EINVAL 496c10c16deSRichard LoweA component of the pointed-to time limit is outside the acceptable range: 4972209d3c8SRichard Lowe.Dv t_sec 4982209d3c8SRichard Lowemust be between 0 and 10^8, inclusive. 4992209d3c8SRichard Lowe.Dv t_usec 5002209d3c8SRichard Lowemust be greater than or equal to 0, and less than 10^6. 5012209d3c8SRichard Lowe.El 5022209d3c8SRichard Lowe.Sh USAGE 5032209d3c8SRichard LoweThe 5042209d3c8SRichard Lowe.Xr poll 2 5052209d3c8SRichard Lowefunction is preferred over this function. 5062209d3c8SRichard Lowe.Pp 507c10c16deSRichard LoweThe use of a timeout does not affect any pending timers set up by 5082209d3c8SRichard Lowe.Xr alarm 2 , 5092209d3c8SRichard Lowe.Xr ualarm 3C , 5102209d3c8SRichard Loweor 5112209d3c8SRichard Lowe.Xr setitimer 2 . 5122209d3c8SRichard Lowe.Pp 5132209d3c8SRichard LoweOn successful completion, the object pointed to by the 5142209d3c8SRichard Lowe.Fa timeout 5152209d3c8SRichard Loweargument may be modified. 5162209d3c8SRichard Lowe.Sh INTERFACE STABILITY 5172209d3c8SRichard Lowe.Sy Standard 5182209d3c8SRichard Lowe.Sh MT Level 5192209d3c8SRichard Lowe.Sy MT-Safe 5202209d3c8SRichard Lowe.Sh SEE ALSO 5212209d3c8SRichard Lowe.Xr alarm 2 , 5222209d3c8SRichard Lowe.Xr fcntl 2 , 5232209d3c8SRichard Lowe.Xr poll 2 , 5242209d3c8SRichard Lowe.Xr read 2 , 5252209d3c8SRichard Lowe.Xr setitimer 2 , 5262209d3c8SRichard Lowe.Xr write 2 , 5272209d3c8SRichard Lowe.Xr ualarm 3C , 5282209d3c8SRichard Lowe.Xr accept 3SOCKET , 5292209d3c8SRichard Lowe.Xr listen 3SOCKET , 5302209d3c8SRichard Lowe.Xr attributes 5 , 5312209d3c8SRichard Lowe.Xr standards 5 532