For example, when you want to test a socket for readability, you must add it t
o the readfds set and wait for the select function to complete. When the selec
t call completes, you have to determine if your socket is still part of the re
adfds set. If so, the socket is readable��you can begin to retrieve data from 
it. Any two of the three parameters (readfds, writefds, exceptfds) can be null
 values (at least one must not be null), and any non-null set must contain at 
least one socket handle; otherwise, the select function won't have anything to
 wait for. The final parameter, timeout, is a pointer to a timeval structure t
hat determines how long the select function will wait for I/O to complete. If 
timeout is a null pointer, select will block indefinitely until at least one d
escriptor meets the specified criteria. The timeval structure is defined as

struct timeval 
{
    long tv_sec; 
    long tv_usec;
};
The tv_sec field indicates how long to wait in seconds; the tv_usec field indi
cates how long to wait in milliseconds. The timeout value {0, 0} indicates sel
ect will return immediately, allowing an application to poll on the select ope
ration. This should be avoided for performance reasons. When select completes 
successfully, it returns the total number of socket handles that have I/O oper
ations pending in the fd_set structures. If the timeval limit expires, it retu
rns 0. If select fails for any reason, it returns SOCKET_ERROR.

--

�� ��源:��泉������ http://bbs.sdu.edu.cn [FROM: 202.194.32.132]