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.