?? select.2
字號:
.\" @(#)select.2 1.37 90/02/01 SMI; from UCB 4.2.\" Copyright (c) 1983 Regents of the University of California..\" All rights reserved. The Berkeley software License Agreement.\" specifies the terms and conditions for redistribution..\".TH select 2.SH Nameselect \- synchronous I/O multiplexing.SH Syntax.nf#include <sys/types.h>#include <sys/time.h>int select (\fInfds\fP, \fIreadfds\fP, \fIwritefds\fP, \fIexceptfds\fP, \fItimeout\fP)int \fInfsd\fP;fd_set \fI*readfds\fP, \fI*writefds\fP, \fI*exceptfds\fP;struct timeval *\fItimeout\fP;FD_SET (\fIfd, fdset\fP)FD_CLR (\fIfd, fdset\fP)FD_ISSET (\fIfd, fdset\fP)FD_ZERO (\fIfdset\fP)int \fIfd\fP;fd_set \fI*fdset\fP;.fi.SH Description.NXR "select system call".NXR "I/O multiplexing"The.PN select system call examines the I/O descriptor sets whose addressesare passed in \fIreadfds\fP, \fIwritefds\fP, and \fIexceptfds\fP to see ifsome of their descriptors are ready for reading, ready forwriting, or have an exceptional condition pending. The \fInfds\fPparameter isthe number of bits to be checked in each bit mask thatrepresent a file descriptor; the descriptors from 0 through\fInfds\fP-1 in the descriptor sets are examined. Typically\fInfds\fP has the value returned by .MS getdtablesize 2for the maximumnumber of file descriptors. On return, .PN selectreplacesthe given descriptor sets with subsets consisting of thosedescriptors that are ready for the requested operation. Thetotal number of ready descriptors in all the sets isreturned..PPThe descriptor sets are stored as bit fields in arrays ofintegers. The following macros are provided for manipulating such descriptor sets: FD_ZERO(\fIfds\fPdescriptor set \fIfdset\fP to the null set. FD_SET(\fIfd\fP, \fIfdset\fP)includes a particular descriptor \fIfd\fP in \fIfdset\fP. FD_CLR(\fIfd\fP,\fIfdset\fP) removes \fIfd\fP from \fIfdset\fP. FD_ISSET(\fIfd\fP, \fIfdset\fP) isnonzero if \fIfd\fP is a member of \fIfdset\fP, zero otherwise. Thebehavior of these macros is undefined if a descriptor valueis less than zero or greater than or equal to FD_SETSIZE,which is equal to the maximum number ofdescriptors that can be supported by the system..PPIf \fItimeout\fP is not a NULL pointer, it specifies a maximuminterval to wait for the selection to complete. If \fItimeout\fPis a NULL pointer, the select blocks indefinitely. Toeffect a poll, the \fItimeout\fP argument should be a non-NULLpointer, pointing to a zero-valued timeval structure..PPAny of \fIreadfds\fP, \fIwritefds\fP, and \fIexceptfds\fP may be given as NULLpointers if no descriptors are of interest..PPSelecting true for reading on a socket descriptor upon whicha .PN listen call has been performed indicates that a subsequent .PN acceptcall on that descriptor will not block..SH RestrictionsThe.PN selectcall may indicate that adescriptor is ready for writing when in fact an attempt towrite would block. This can happen if system resourcesnecessary for a write are exhausted or otherwise unavailable. If an application deems it critical that writes to afile descriptor not block, it should set the descriptor fornon-blocking I/O using the F_SETFL request to the.PN fcntlcall..SH Return ValuesThe .PN selectcall returns a non-negative value on success. A positive value indicates the number of ready descriptors in thedescriptor sets. A 0 indicates that the time limit referredto by \fItimeout\fP expired. On failure, .PN selectreturns -1,sets errno to indicate the error, and the descriptor setsare not changed..SH Diagnostics.TP 12[EBADF]One of the descriptor sets specified an invalid descriptor..TP[EFAULT]One of the pointers given in the call referred to a non-existent portion of the process' address space..TP[EINTR]A signal was delivered before any of the selected events occurred, or before the time limit expired..TP[EINVAL]A component of the pointed-to time limit is outside the acceptable range; t_sec must be between 0 and 10^8, inclusive. t_usec must be greater than or equal to 0, and less than 10^6..SH See Alsoaccept(2), connect(2), fcntl(2), gettimeofday(2), listen(2), read(2), recv(2), send(2), write(2), getdtablesize(2)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -