Server programs do not use the select function, and may crash due to a cross-border operation.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.