Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Framework for a server application (preferably, using BOOST C++)

Tags:

c++

boost

I am thinking of writing a server application - along the lines of mySQL or Apache.

The main requirements are:

  1. Clients will communicate with the server via TCP/IP (sockets)
  2. The server will spawn a new child process to handle requests (ala Apache)

Ideally, I would like to use the BOOST libraries rather than attempt to reinvent my own. There must be code somewhere that does most of what I am trying to do - so I can use it (or atleast part of it as my starting point) can anyone point me to a useful link?

In the (hopefully unlikely) event that there is no code I can use as a starting point, can someone point out the most appropriate BOOST libraries to use - and a general guideline on how to proceeed.

My main worry is how to know when one of the children has crashed. AFAIK, there are two ways of doing this:

  1. Using heartbeats between the parent and children (this quickly becomes messy, and introduces more things that could go wrong)
  2. Somehow wrap the spawning of the process with a timeout parameter - but this is a dumb approach, because if a child is carrying out time intensive work, the parent may incorrectly think that the child has died

What is the best practises of making the parent aware that a child has died?

[Edit]

BTW, I am developing/running/deploying on Linux

like image 882
skyeagle Avatar asked May 29 '26 07:05

skyeagle


2 Answers

On what platform (Windows/Linux/both)? Processes on Windows are considered more heavy-weight than on Linux, so you may indeed consider threads.

Also, I think it is better (like Apache does) not to spawn a process for each request but to have a process pool, so you save the cost of creating a process, especially on Windows.

If you are on Linux, can waitpid() be useful for you? You can use it in the non-blocking mode to check recurrently with some interval whether one of the child processes terminated

like image 153
davka Avatar answered Jun 01 '26 00:06

davka


I can say for sure that Pion is your only stable option.
I have never used it but I intend to, and the API looks very clean.

As for the Boost libraries you would need:

  • Boost.Asio
  • Boost.Threading
  • Boost.Spirit (or something similar to parse the HTTP protocol)
  • Boost.IPC
like image 20
the_drow Avatar answered May 31 '26 23:05

the_drow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!