If you do not plan to score many new connections per second, consider starting from inetd. Otherwise...
Download the OpenSSH source code. They put a lot of work into privilege sharing just right, it is portable, and it has been carefully studied for security more than anything else.
Adapt it to your needs, you can probably throw away most of it. Of course, agree to the license agreement. Follow upcoming patches with a good SCC.
Do not worry about the performance of forking processes and threads until you have evidence that this is a real problem. Apache has visited over the years and years on the busiest sites with a simple simple model for each client.
If you are truly ambitious, you can use some kind of non-blocking asynchronous I / O model. I like Boost.Asio, but I'm heavy in C ++.
Make sure your code handles the signals correctly. HUP to reload the configuration. TIME until the end of grace.
Do not try to write your own log file. Use only syslog or just write to stderr, which can be redirected to syslog. This is a real pain when trying to configure logrotate on home servers, which all log in a bit differently.
source share