Reputation: 1043
Whenever I see a select
call in C, I see it written as:
select(sock_fd + 1, &fdset, NULL, NULL, &tv)
or something similar. What is the meaning behind incrementing the file descriptor?
Upvotes: 2
Views: 832
Reputation: 409176
From the POSIX specification of select
:
The
nfds
argument specifies the range of descriptors to be tested. The firstnfds
descriptors shall be checked in each set; that is, the descriptors from zero throughnfds-1
in the descriptor sets shall be examined.
That is, you give the size of the set, where each descriptor is an index.
Descriptors sets are basically implemented as arrays, and sock_fd
(in your case) is an index into that array, while sock_fd + 1
is the size of the array to check.
Upvotes: 6