We all know about the select efficiency, but the correctness of the SELECT statement is rarely discussed.
In Linux, fd_set is 1024
Bitmap. Each bit represents an FD value, which is also the cause of low efficiency.
Performance issues are not mentioned, and correctness issues are worth more attention.
Because this is
A 1024-Bit Bitmap. Therefore, when the FD value in the process is greater than or equal to 1024, the system may cross the border and cause a crash. For serversProgram, FD >=1024
It is easy to achieve, as long as the number of connections + the number of opened files is large enough.
When there are so many connections, it is estimated that no one is using select to wait for all connections, but usually
The wait_readable implemented by select is easily ignored.
For example:
Inline static int
Wait_readable (INT filedes, struct timeval * timeout)
{
Fd_set
Rset;
Fd_zero (& rset );
Fd_set (filedes, & rset );
Return select (filedes + 1, & rset, null, null, timeout );
}
This
SampleCodeSecurity is not guaranteed if it is used in the repository.
For this purpose, we recommend that you use poll instead.