What does "select" do when nfds is 0?

int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); 

The first parameter is select , nfds should be the maximum file descriptor plus 1, which should be at least 1.
But I saw some codes set nfds to 0, is this use legal?
In addition, the return value of select set to EINVAL when nfds negative, or timeout contains an invalid value. Again, it does not indicate what happened when nfds is 0.

+4
source share
3 answers

As an alternative to sleep you can use select. I believe this is achieved by defining all parameters as 0 / NULL except for the timeout. Consult with

Why use select () instead of sleep ()?

+6
source

This man page says that

Some select () code calls with all three sets empty, nfds zero and a non-NULL timeout as a fairly portable way to sleep accurate to the second.

+5
source

Waits for the specified timeout, and then returns 0 or returns earlier than EINTR . If you think about it, it makes sense and actually what the documentation says, even if it does not say it explicitly. The same thing happens if all sets are NULL or do not have bits less than nfds set in them.

+3
source

Source: https://habr.com/ru/post/1482899/


All Articles