I have a simple fcgi server written in c++ - for now it's single threaded. I saw the main loop for example like
accept_connections();
handle_data();`
handle_connections();
but what if I want to respond to each client simultaneously? Because if I understand this, server first accepts new connections and iterate over them and proccess each. But this can be not good because of for example a upload (while one client uploads, others have to wait.) or by DoS like slowloris. How can server do multiple clients at one time ? I saw one server it was single-threaded - and did it.
How to do it ?
I solved it earlier but i want to answer my question.
Solution I made:
I wrote custom fastcgi handler. I also used libev for network threads, buffered and direct output and automatic waking and disabling write event. Debugging with valgrind. Compiler clang.
Reactions to other answers:
I didnt want to use thread per connection because it has some cost in spawning and also if there are lots of threads, there is also a slowdown and higher memory usage.
And I didnt use boost asio because I dislike frameworks and asynchronous IO was not one that i was looking for.