Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:41:38+00:00 2026-06-11T23:41:38+00:00

I have a simple fcgi server written in c++ – for now it’s single

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:41:39+00:00Added an answer on June 11, 2026 at 11:41 pm

    I solved it earlier but i want to answer my question.

    Solution I made:

    • 1 acceptor thread – (accept() for new incoming connections in
      blocking behavior) and assigning connections to network threads with load balancing
    • N network threads where N = (1 thread per 1000 clients) with nonblocking behavior:
      • initialize
      • while server is running
        • set timeout watcher (for disabling blocking in event loop)
        • run event loop
        • stop timeout watcher
        • add new sockets from acceptor thread
        • iterate over connections run Update(), try to flush output, check for close, etc. if Update() return -1, erase connection from list
      • end while
      • release and close all connections and free all allocated memory
      • return
    • Worker Threads with posix semaphores waiting for jobs (thread pool as management)
    • (Optional) Background Thread with low priority for scheduling and checking, deleting for example tokens, sessions, etc. Lots of sleeping.

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have simple regular expression: ^123$ Matches are for example 123 1234 etc. How
I have simple node js http server. var http = require(http); http.createServer(function(request, response) {
I have simple multiple selection input <input multiple=true type=file name=image_name[] /> Now i would
I have simple example: function File(name) { this.name = name this.text = null }
i have simple form that uploads image to server and returns php string containing
i have simple html5 video player like this <video id=video controls=true src=video.webm></video> If the
I have simple client/server SSL code which worked fine on Python 3.2. However, I
I have Simple web client written on Java and I have to count the
I have simple jQuery UI autocomplete, which was working and now it's not. The
I have simple models with generic relations from this example at the Django Project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.