iAddrLen is not a length. It is a badly named variable.
It is a Socket descriptor, but they use it as an indirect counter of number of sockets.
A SOCKET is just an integer.
Select can be used to look if one can read or write to sockets.
This implementation of select has 5 parameters
Number of sockets in the arrays (in total)
An array of sockets available for reads
An array of sockets available for writes
An array of sockets which should be checked for errors.
And a timeout
What they are actually doing is finding the SOCKET with the highest number.
I think the socket numbers may be consecutive.
So it is indirectly a counter, where the first socket starts with 0.
Hence the +1.
The INVALIDSOCKET is probably -1 if I remember correctly.
In this case, for three sockets. The parameter should be 3.
But nothing bad will happen if it is bigger.
According to the MSDN API, the first parameter is ignored.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms740141(v=vs.85).aspx[
^]
FDSET just assigns the array.
A call to select sets the appropriate flags in the array.
What you should concentrate on is the FD_SET FD_ISSET
Select is a way to multitask over an array of sockets.
You can keep the number of working threads to a minimum with select.
If you call Select with timout equal to NULL, it means that it will be a non blocking call.
Very practical indeed.
In .Net you should probably not use this sort of mechanism.
You can probably register some kind of event to get a callback,
or use an asynchronous model with BeginReceive and EndReceive,
or use the new Async model which is available in Net 4.5