This article describes how to limit the number of concurrent connections to a server with echoserver that are familiar to you.
The code for this article is shown in http://code.google.com/p/muduo/source/browse/trunk/examples/maxconnection/
The sixth article in the "Muduo Network programming Example series" was originally "Pingpong program for testing the bandwidth of two machines", and the Pingpong protocol program is in "Muduo and boost ASIO throughput comparisons" and "Muduo and Libevent2 swallowing Spit Volume Contrast "two articles are introduced, so I write another one that has a little meaning."
The "Concurrent connections" in this article refers to the number of client connections that a server program can support at the same time, the connection is initiated by the client, and the service side passively accepts (accept) connections. (If you want to limit the connections that the application initiates, the problem is much simpler, after all, the initiative and the decision are in the program itself.) )
Why do you want to limit the number of concurrent connections?
On the one hand, we do not want the service program to overload, on the other hand, because file descriptor is a scarce resource, if the file descriptor exhaustion, it is tricky (and "malloc failure/new () throw std::bad_alloc" almost the same tricky).
In the article "the Engineering development method of distributed Systems", I talked about the Libev author's proposal for a response to "accept () the file descriptor run out" approach.