select - should I use FD_SETSIZE or max fd
Hello group,
The man pages say that the first parameter to select (nfds) should be "an integer one more than the maximum of any file descriptor in any of the sets", but I often see the code that uses FD_SETSIZE like this:
Code:
ret = select(FD_SETSIZE, ...);
instead of calculated max value like this:
Code:
int nfds = 0;
...
nfds = max(nfds, fd1);
nfds = max(nfds, fd2);
..
ret = select(nfds, ...);
Does this code (with FD_SETSIZE) work, or does it just accidentally work?
example with max(): http://www.linuxmanpages.com/man2/select_tut.2.php
example with FD_SETSIZE: http://www.delorie.com/gnu/docs/glibc/libc_248.html
Which one is correct?
Thanks,
Tvrtko