Question Details

No question body available.

Tags

c sockets posix-select

Answers (2)

Accepted Answer Available
Accepted Answer
April 11, 2025 Score: 4 Rep: 789,525 Quality: Expert Completeness: 80%

Yes, this is correct behavior. POSIX says

select() blocks, up to the specified timeout interval, until the specified condition is true for at least one of the specified file descriptors.

If no FDs are specified, then "true for at least one of the specified file descriptors" will never be true, so it blocks until the timeout.

If the timeout argument is a null pointer, select() blocks until an event causes one of the masks to be returned with a valid (non-zero) value.
...
If the readfds, writefds, and errorfds arguments are all null pointers and the timeout argument is a null pointer, select() blocks until interrupted by a signal.

An empty FD set is effectively the same as passing a null pointer for that set.

April 11, 2025 Score: 4 Rep: 124,861 Quality: Medium Completeness: 80%

This is actually the behavior specified in POSIX (IEEE Std 1003.1-2024):

If none of the selected descriptors are ready for the requested operation, the pselect() or select() function shall block until at least one of the requested operations becomes ready, until the timeout occurs, or until interrupted by a signal. The timeout parameter controls how long the pselect() or select() function shall take before timing out. If the timeout parameter is not a null pointer, it specifies a maximum interval to wait for the selection to complete. If the specified time interval expires without any requested operation becoming ready, the function shall return. If the timeout parameter is a null pointer, then the call to pselect() or select() shall block indefinitely until at least one descriptor meets the specified criteria. To effect a poll, the timeout parameter should not be a null pointer, and should point to a zero-valued timespec structure.

With no file descriptors in any of the sets and no timeout, it must therefore block until interrupted.