I/O port multiplexing cycle Server Model in linux

Source: Internet
Author: User
I/O port multiplexing in linux the cyclic Server Model-general Linux technology-Linux technology and application information. The following is a detailed description. Only look at the large font of this user.

I used a server model in the book and wrote a test program myself. I did a brute force test and found a problem.
The general structure of the server is as follows:
Create two threads in the main function
Thread 1: accept in while (1), save the obtained sockfd to the array, and continue accept
Thread 2: while (1) throws valid sockfd in the array into the character set, select the readable socket, write information on the socket, close the descriptor, the position in the array becomes invalid again.


The general process of my test program is as follows:
While (1) creates a socket, fills in the server address, port, and so on, and then connects, writes, reads, and closes. While (1) 100ms once


The problem is:
When the test program while (1) runs for 1019 times, that is to say, after the server receives, connects, reads, and writes, and closes so many times, the server crashes and queries a lot, linux resources are not released. If I use ulimit-n to change the maximum number of file descriptors on the server, the number of operations exceeds 1019, but the subsequent operations are very slow.
, Do not know how to solve this problem.
Forget your expert advice. The attachment contains two programs.

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.