I wonder how system assign socket number in C. Is that random assignment or incrementally (first client has socket number 1, second client has socket number 2 , ...).
1 Answer
On UNIX systems, socket assignment is done like with other calls that return a new file descriptor. As long as the system has resources to create the socket, the lowest available file descriptor is used for the new socket. Otherwise, an error is returned instead.
-
And note that 'lowest available' is per-process, not global. On Windows, socket handles are pointers. Commented Feb 23, 2014 at 0:39
-
@EJP Microsoft seems to disagree with you: msdn.microsoft.com/en-us/library/windows/desktop/… Commented Feb 23, 2014 at 2:02
-
@JeremyFriesner There is no disagreement that I can see. MS aren't giving their secrets away but if you look at the value of a SOCKET you will see for yourself that it is clearly a pointer, like all other handles in Windows. They play with the upper bits a bit for various purposes. Commented Feb 23, 2014 at 2:37