Feb 23, 2010 at 3:16pm UTC
Hello All,
The linux call 'select' takes first argument as maxfds+1. Does this have any significance. Why is that 'maxfds+1'?
Thanks in advance
nkumar
Feb 23, 2010 at 3:31pm UTC
select, as you might know, gets the sub-set of file descriptors that are SET either for read/write. So maxfds + 1, specifies in which range from 0 should it search for set of file descriptors that are ready for either read/write.
Hope this helps !
Feb 23, 2010 at 4:42pm UTC
In other words:
Look at the file descriptors you put in the three FD_SETs, pick the highest numbered one, and add one to it.
So if you are selecting on the FD_SET {1, 2, 4, 5, 7, 9 }, then set the first parameter to 9 + 1 = 10.
Feb 24, 2010 at 4:04am UTC
So is it because the range start from 0 we need to set the first argument as maxfds+1?
Feb 24, 2010 at 4:43am UTC
If you see the source code of sys_select , you can find the core work related to this 'maxfds+1' is in function core_sys_select.
It prepare a bit-map for select, which need the kmalloc size.