Constructing a server daemon / questions on handling clients

Hi All,

I'm interested in the best way to serve multiple clients from a server process.

Now, our server is going to serve data on a custom protocol and it is going to get / process that data from a number of possible back-ends including files (text or xml) and MySQL/some other database. Then, it's going to respond to possibly multiple users.

My linux programming book suggests two methods: fork() in the main while loop of the server so that each client ends up with a thread to handle its request and checking file descriptors for new connection requests.

I'd like my server to be able to respond to multiple lookup requests and possibly multiple updates; there is some scope for the database being read-write, from multiple clients. So, what's the best way to attack this problem? As suggested above, or a different way? I understand there is an issue if two threads attempt to open the same resource (database or whatever) with write privileges (one should fail). I thought about creating a transaction queue for writes with a separate thread processing this. The single thread process doesn't have this problem, of course, but then if intensive work is being done per client (possible) surely the speed at which clients are served becomes a problem.

This is likely to be using AF_INET sockets i.e. over the net.

Basically I'm not sure how to proceed; any thoughts / comments are most welcome. I'd rather not just write the code then have to change it because I didn't ask first.

Thanks in advance,

Dragonfly

P.S. Not a homework problem (I am a student), my degree is in Mathematics!

Hint: check out select(2)

Hello,

Thanks for that... it looks like the method my programming book suggests as the most efficient method, all done on one process. I assume then that multiple clients will be able to connect without any issues.

Thanks again,

Dragonfly