I'm trying to implement a network library with sfml 1.6.
This library provides a client/server model where a client can connect to a server and send and receive message between the server, and a server can accept multiple clients' connections and communicate with them.
My problem is for the server.
I want to process the client connections in a non-blocking mode, so in the "update" function of the server it only launches two thread for each connection (one for sending message, one for receiving) and checks for their completion.
I also want to have two message buffers for each client connection, so the server can push message into the sending buffer and the receiving threads will push messages into the receiving buffer. These buffers are critical sections and should be protected by mutexes.
Since the number of clients are undetermined and should be scalable, I cant just define a global mutex (or several glabal mutexes) as in the tutorial because I can never know the number of mutex I need.
Is there a way of dealing with this kind of situation where the number of resources that need to be protected might change dynamically during runtime ?
Or my server model is wrong and I should use some other way to implement non-blocking here ?