I'm currently writing an HTTP server in C so that I'll learn about C, network programming and HTTP. I've implemented most of the simple stuff, but I'm only handling one connection at a time. Currently, I'm thinking about how to efficiently add multitasking to my project. Here are some of the options I thought about:
- Use one thread per connection. Simple but can't handle many connections.
- Use non-blocking API calls only and handle everything in one thread. Sounds interesting but using
select()
s and such excessively is said to be quite slow. - Some other multithreading model, e.g. something complex like lighttpd uses. (Probably) the best solution, but (probably) too difficult to implement.
Any thoughts on this?