⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 select.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>pselect</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="pselect"></a> <a name="tag_03_485"></a><!-- pselect --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_485_01"></a>NAME</h4><blockquote>pselect, select - synchronous I/O multiplexing</blockquote><h4><a name="tag_03_485_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include &lt;<a href="../basedefs/sys/select.h.html">sys/select.h</a>&gt;<br><br> int pselect(int</tt> <i>nfds</i><tt>, fd_set *restrict</tt> <i>readfds</i><tt>,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fd_set *restrict</tt> <i>writefds</i><tt>, fd_set *restrict</tt> <i>errorfds</i><tt>,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const struct timespec *restrict</tt> <i>timeout</i><tt>,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const sigset_t *restrict</tt> <i>sigmask</i><tt>);<br> int select(int</tt> <i>nfds</i><tt>, fd_set *restrict</tt> <i>readfds</i><tt>,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fd_set *restrict</tt> <i>writefds</i><tt>, fd_set *restrict</tt> <i>errorfds</i><tt>,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct timeval *restrict</tt> <i>timeout</i><tt>);<br> void FD_CLR(int</tt> <i>fd</i><tt>, fd_set *</tt><i>fdset</i><tt>);<br> int FD_ISSET(int</tt> <i>fd</i><tt>, fd_set *</tt><i>fdset</i><tt>);<br> void FD_SET(int</tt> <i>fd</i><tt>, fd_set *</tt><i>fdset</i><tt>);<br> void FD_ZERO(fd_set *</tt><i>fdset</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_485_03"></a>DESCRIPTION</h4><blockquote><p>The <i>pselect</i>() function shall examine the file descriptor sets whose addresses are passed in the <i>readfds</i>,<i>writefds</i>, and <i>errorfds</i> parameters to see whether some of their descriptors are ready for reading, are ready forwriting, or have an exceptional condition pending, respectively.</p><p>The <i>select</i>() function shall be equivalent to the <i>pselect</i>() function, except as follows:</p><ul><li><p>For the <i>select</i>() function, the timeout period is given in seconds and microseconds in an argument of type <b>structtimeval</b>, whereas for the <i>pselect</i>() function the timeout period is given in seconds and nanoseconds in an argument oftype <b>struct timespec</b>.</p></li><li><p>The <i>select</i>() function has no <i>sigmask</i> argument; it shall behave as <i>pselect</i>() does when <i>sigmask</i> is anull pointer.</p></li><li><p>Upon successful completion, the <i>select</i>() function may modify the object pointed to by the <i>timeout</i> argument.</p></li></ul><p>The <i>pselect</i>() and <i>select</i>() functions shall support regular files, terminal and pseudo-terminal devices, <sup>[<ahref="javascript:open_code('XSR')">XSR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">&nbsp;STREAMS-based files, <img src="../images/opt-end.gif" alt="[Option End]" border="0"> FIFOs, pipes, and sockets. The behaviorof <i>pselect</i>() and <i>select</i>() on file descriptors that refer to other types of file is unspecified.</p><p>The <i>nfds</i> argument specifies the range of descriptors to be tested. The first <i>nfds</i> descriptors shall be checked ineach set; that is, the descriptors from zero through <i>nfds</i>-1 in the descriptor sets shall be examined.</p><p>If the <i>readfds</i> argument is not a null pointer, it points to an object of type <b>fd_set</b> that on input specifies thefile descriptors to be checked for being ready to read, and on output indicates which file descriptors are ready to read.</p><p>If the <i>writefds</i> argument is not a null pointer, it points to an object of type <b>fd_set</b> that on input specifies thefile descriptors to be checked for being ready to write, and on output indicates which file descriptors are ready to write.</p><p>If the <i>errorfds</i> argument is not a null pointer, it points to an object of type <b>fd_set</b> that on input specifies thefile descriptors to be checked for error conditions pending, and on output indicates which file descriptors have error conditionspending.</p><p>Upon successful completion, the <i>pselect</i>() or <i>select</i>() function shall modify the objects pointed to by the<i>readfds</i>, <i>writefds</i>, and <i>errorfds</i> arguments to indicate which file descriptors are ready for reading, ready forwriting, or have an error condition pending, respectively, and shall return the total number of ready descriptors in all the outputsets. For each file descriptor less than <i>nfds</i>, the corresponding bit shall be set on successful completion if it was set oninput and the associated condition is true for that file descriptor.</p><p>If none of the selected descriptors are ready for the requested operation, the <i>pselect</i>() or <i>select</i>() functionshall block until at least one of the requested operations becomes ready, until the <i>timeout</i> occurs, or until interrupted bya signal. The <i>timeout</i> parameter controls how long the <i>pselect</i>() or <i>select</i>() function shall take before timingout. If the <i>timeout</i> parameter is not a null pointer, it specifies a maximum interval to wait for the selection to complete.If the specified time interval expires without any requested operation becoming ready, the function shall return. If the<i>timeout</i> parameter is a null pointer, then the call to <i>pselect</i>() or <i>select</i>() shall block indefinitely until atleast one descriptor meets the specified criteria. To effect a poll, the <i>timeout</i> parameter should not be a null pointer, andshould point to a zero-valued <b>timespec</b> structure.</p><p>The use of a timeout does not affect any pending timers set up by <a href="../functions/alarm.html"><i>alarm</i>()</a>, <a href="../functions/ualarm.html"><i>ualarm</i>()</a>, or <a href="../functions/setitimer.html"><i>setitimer</i>()</a>.</p><p>Implementations may place limitations on the maximum timeout interval supported. All implementations shall support a maximumtimeout interval of at least 31 days. If the <i>timeout</i> argument specifies a timeout interval greater than theimplementation-defined maximum value, the maximum value shall be used as the actual timeout value. Implementations may also placelimitations on the granularity of timeout intervals. If the requested timeout interval requires a finer granularity than theimplementation supports, the actual timeout interval shall be rounded up to the next supported value.</p><p>If <i>sigmask</i> is not a null pointer, then the <i>pselect</i>() function shall replace the signal mask of the process by theset of signals pointed to by <i>sigmask</i> before examining the descriptors, and shall restore the signal mask of the processbefore returning.</p><p>A descriptor shall be considered ready for reading when a call to an input function with O_NONBLOCK clear would not block,whether or not the function would transfer data successfully. (The function might return data, an end-of-file indication, or anerror other than one indicating that it is blocked, and in each of these cases the descriptor shall be considered ready forreading.)</p><p>A descriptor shall be considered ready for writing when a call to an output function with O_NONBLOCK clear would not block,whether or not the function would transfer data successfully.</p><p>If a socket has a pending error, it shall be considered to have an exceptional condition pending. Otherwise, what constitutes anexceptional condition is file type-specific. For a file descriptor for use with a socket, it is protocol-specific except as notedbelow. For other file types it is implementation-defined. If the operation is meaningless for a particular file type,<i>pselect</i>() or <i>select</i>() shall indicate that the descriptor is ready for read or write operations, and shall indicatethat the descriptor has no exceptional condition pending.</p><p>If a descriptor refers to a socket, the implied input function is the <a href="../functions/recvmsg.html"><i>recvmsg</i>()</a>function with parameters requesting normal and ancillary data, such that the presence of either type shall cause the socket to bemarked as readable. The presence of out-of-band data shall be checked if the socket option SO_OOBINLINE has been enabled, asout-of-band data is enqueued with normal data. If the socket is currently listening, then it shall be marked as readable if anincoming connection request has been received, and a call to the <a href="../functions/accept.html"><i>accept</i>()</a> functionshall complete without blocking.</p><p>If a descriptor refers to a socket, the implied output function is the <a href="../functions/sendmsg.html"><i>sendmsg</i>()</a>function supplying an amount of normal data equal to the current value of the SO_SNDLOWAT option for the socket. If a non-blockingcall to the <a href="../functions/connect.html"><i>connect</i>()</a> function has been made for a socket, and the connectionattempt has either succeeded or failed leaving a pending error, the socket shall be marked as writable.</p><p>A socket shall be considered to have an exceptional condition pending if a receive operation with O_NONBLOCK clear for the openfile description and with the MSG_OOB flag set would return out-of-band data without blocking. (It is protocol-specific whether theMSG_OOB flag would be used to read out-of-band data.) A socket shall also be considered to have an exceptional condition pending ifan out-of-band data mark is present in the receive queue. Other circumstances under which a socket may be considered to have anexceptional condition pending are protocol-specific and implementation-defined.</p><p>If the <i>readfds</i>, <i>writefds</i>, and <i>errorfds</i> arguments are all null pointers and the <i>timeout</i> argument isnot a null pointer, the <i>pselect</i>() or <i>select</i>() function shall block for the time specified, or until interrupted by asignal. If the <i>readfds</i>, <i>writefds</i>, and <i>errorfds</i> arguments are all null pointers and the <i>timeout</i> argumentis a null pointer, the <i>pselect</i>() or <i>select</i>() function shall block until interrupted by a signal.</p><p>File descriptors associated with regular files shall always select true for ready to read, ready to write, and errorconditions.</p><p>On failure, the objects pointed to by the <i>readfds</i>, <i>writefds</i>, and <i>errorfds</i> arguments shall not be modified.If the timeout interval expires without the specified condition being true for any of the specified file descriptors, the objectspointed to by the <i>readfds</i>, <i>writefds</i>, and <i>errorfds</i> arguments shall have all bits set to 0.</p><p>File descriptor masks of type <b>fd_set</b> can be initialized and tested with <i>FD_CLR</i>(), <i>FD_ISSET</i>(),<i>FD_SET</i>(), and <i>FD_ZERO</i>(). It is unspecified whether each of these is a macro or a function. If a macro definition issuppressed in order to access an actual function, or a program defines an external identifier with any of these names, the behavioris undefined.</p><p><i>FD_CLR</i>(<i>fd</i>, <i>fdsetp</i>) shall remove the file descriptor <i>fd</i> from the set pointed to by <i>fdsetp</i>. If<i>fd</i> is not a member of this set, there shall be no effect on the set, nor will an error be returned.</p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -