Safest design (c++)?

Discussion in 'Programming/Scripts' started by Liac, Feb 19, 2008.

  1. Liac

    Liac New Member

    Hi there :)

    I'm relatively new to Linux programming and that is why I need your advice.

    Imagine that you are coding a server (in C++ under Linux), that listens for connection attempts, accepts them, and handles each request and sends a response (similar to an HTTP server).

    Now, imagine some malicious user found a way to crash your program every time it sends a specific request. Obviously this issue will have to be fixed, but until the admin discovers it, I want my server to be as resistant as possible against this type of attack.

    So my previous design was to put the server (that listens and accepts connection) AND the routines (that handle each request) into ONE executable and create a thread for every new request.

    This has the disadvantage that one single exception/error crashes the whole program (right?)--all threads and all currently handled requests will be gone, which is bad if someone else tries to communicate with my server right at this moment.

    Now my question: What is the best and safest design to solve that problem?

    - Create a new process for every request? If so, how can you transfer the socket and other information to the new process, communicate with that process, etc?

    - Or is there a way to put it all in one process and let an error crash ONLY the current thread, not the whole program?

    I avoided the possibility to create multiple executables so far, but if that is the best way, I'll do that.

    Thanks in advance for your advice :)

Share This Page