The select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O.
Syntax
int select( __in int nfds, __inout fd_set *readfds, __inout fd_set *writefds, __inout fd_set *exceptfds, __in const struct timeval *timeout );
Parameters
-
nfds [in]
-
Ignored. The nfds parameter is included only for compatibility with Berkeley sockets.
readfds [in, out]
-
An optional pointer to a set of sockets to be checked for readability.
writefds [in, out]
-
An optional pointer to a set of sockets to be checked for writability.
exceptfds [in, out]
-
An optional pointer to a set of sockets to be checked for errors.
timeout [in]
-
The maximum time for select to wait, provided in the form of a TIMEVAL structure. Set the timeout parameter to null for blocking operations.
Return value
The select function returns the total number of socket handles that are ready and contained in the fd_set structures, zero if the time limit expired, or SOCKET_ERROR if an error occurred. If the return value is SOCKET_ERROR, WSAGetLastError can be used to retrieve a specific error code.
1.如果超时返回 0
2.返回fd_set 中准备好的socket个数(不包括零)
3.如果没有准备好的返回 -1
本文详细介绍了select函数的功能与用法,该函数用于确定一个或多个套接字的状态,以便进行同步I/O操作。文章解释了各个参数的意义,如nfds、readfds、writefds等,并说明了如何设置超时时间。此外,还阐述了select函数的返回值含义。
1046

被折叠的 条评论
为什么被折叠?



