1.select函数
The select function returns the total number of socket handles that are ready and contained in the structures, zero if the time limit expired, or SOCKET_ERROR if an error occurred. If the return value is SOCKET_ERROR, can be used to retrieve a specific error code.
In summary, a socket will be identified in a particular set when select returns if:
readfds:
- If has been called and a connection is pending, will succeed.
- Data is available for reading (includes OOB data if SO_OOBINLINE is enabled).
- Connection has been closed/reset/terminated.
writefds:
- If processing a call (nonblocking), connection has succeeded.
- Data can be sent.
exceptfds:
- If processing a connect call (nonblocking), connection attempt failed.
- OOB data is available for reading (only if SO_OOBINLINE is disabled).
int select( _In_ int nfds, _Inout_ fd_set *readfds,//检测可读性的 _Inout_ fd_set *writefds,//检测可写性的 _Inout_ fd_set *exceptfds,//检测存在错误的 _In_ const struct timeval *timeout //select函数等待的最长时间,阻塞模式时设为0);
typedef struct fd_set { u_int fd_count; //集合中的数量 SOCKET fd_array[FD_SETSIZE];} fd_set; ....................