Skip to content
Advertisement

Meaning of adding 1 on socket file descriptor in select function when using linux socket

What is the meaning of adding 1 on socket file descriptor when using in select function?

I create socket file descriptor like below,

JavaScript

and use it in select function like below,

JavaScript

What is the meaning of +1 in select function? It even does not work when I remove the calculation adding the value.

Thanks in advance.

Advertisement

Answer

RTFM! The first parameter of select is the number of file descriptors to considere:

The nfds argument specifies the range of descriptors to be tested. The first nfds descriptors shall be checked in each set; that is, the descriptors from zero through nfds-1 in the descriptor sets shall be examined.

Here is an example of use:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement