The iterative server is primitive, its prototype can be described as:
while(1) { new_fd = server accept client connection (new_fd = accept(listenfd, XX, XX)) Logic processing on this new_fd to the client Sending a message to close new_fd } That is, the process is to handle the connection sent by each client one by one. For example, if a client sends a connection, it will always occupy it as long as it has not completed its task. The server's process closes the socket until the server finishes processing. Concurrent server is the most frequently used: 1 while(1) 2 { 3 new_fd = server accept client connection 4 if (is a child process) 5 { 6 First turn off listening fd //because the child process does not need to listen, it only Responsible for processing logical concurrent messages to the client 7 Processing logic to send messages 8 Close new_fd 9 Close process 10 } 11 Close new_fd 12 } So every time a client, the server clones itself to process the request, so the main process is always listening And will not be blocked, I want to talk about the focus is not here, the focus is the code line 12! 1. Don't think that fork will generate two new socket descriptors when a child process comes out. In fact, the child process and the parent process share linten_fd and new_fd. When the parent process closes new_fd (code line 12) it just puts The access count value of this new_fd is reduced by one. Since the access count value is also > 0 (because there is still a client's new_fd attached), it does not disconnect from the client. 2. If we don't write the 12th line, the first thing, because the assignable socket descriptor is limited, if it is not released after the allocation, it can not be recycled, that is, there is always a day when the descriptor is exhausted. . Second, after the task of connecting to the client is handed over to the child process, the parent process can continue to listen and accept the next connection, but if the parent process does not close its connection with the client, it means that the connection is always there! Equivalent to every customer, this parent process has even a client and the connection is constant, you should know the consequences.
This article describes the solution when encountering is not in the sudoers file during Linux use. W
A summaryIn order to manage all server accounts and passwords in the enterprise, you can use the Wi
That day, my colleague showed me an operation step on my computer, using an env command, well, I adm
under RedHat Enterprise Linux server 5.4 First, system environment operating system: RedHat Enterp
LINUX vim replaces string instructions
Tips for flexible use of expect scripts under Linux
Linux df command parameters detailed
Linux Virtual Machine VMware vSphere Installation Tutorial
How to access Windows partitions under Linux
The array cannot be unmounted and the VCS dual-machine switching fails.
Under Linux, the CPU usage of C language is
CentOS installed essential - basic settings and missing files
What if the computer can't connect to WiFi? Win7 wireless network connection method
What player does the MKV file play with? What is the format of MKV in detail
Win7 system can not shut down the solution
IE browser automatically close how to solve
Three ways to return the Win8.1 system from any location on the computer to the desktop
Win8 comes with anti-virus software Defender to prevent the modification of the hosts file solution
Win8 broadband connection prompt error 741 how to do?
Don't try again! A few tricks to make your Win8 run barrier-free (1)
How can I not display the Win10 hot folder and recently used files?
2016 red envelope calendar collection, life calendar to help you easily grab the red envelope