|
select is used by an application to receive notifications of events that occur on one or more sockets of interest.
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
The nfds parameter is included only for compatibility with Berkeley sockets.
NOTE: select cannot monitor more than the MAX_SOCKET amount (64 sockets) per unique nfds. Attempts to monitor more than 64 sockets will result in an exception.
readfds
The address of the descriptor set that contains a set of sockets for which the application wishes to be notified when any of them becomes readable.
writefds
The address of the descriptor set that contains a set of sockets for which the application wishes to be notified when any of them becomes writeable.
exceptfds
The address of the descriptor set that contains a set of sockets for which the application wishes to be notified when any of them has a pending exception condition. The only exception condition that can create a notification is when out-of-band data is available on a socket.
timeout
The address of a struct timeval which specifies how long the application is willing to block on the select call while waiting for a notification..
Return Values
0 if a timeout occurs and none of the selected events has occurred on any of the selected sockets, or
A positive integer which is the sum of the number of sockets in each fd_set for which events have occurred, or
SOCKET_ERROR if the function fails
Use WSAGetLastError to retrieve a specific error code.
Remarks
An assumption cannot be made that the first socket descriptor returned to a particular thread or task in a system has the value 1, or that all socket descriptors created by a thread in a system will be incrementally increasing, beginning with 1.
If there are multiple threads in the system that creates sockets, then the value returned by socket must be treated essentially as a random positive integer.