Some High Level Ideas from my side. : )
- Have a main thread in which you will be doing the "select" / "poll" call for all the connections.
- Have a thread pool of worker threads
- If for a particular connection, select indicates that there is data to read, then pass the socket + additional information to one of the free worker threads for receiving / sending data on that connection.
- Upon completion of the work, the worker thread returns to the free worker thread queue, which can be used again for another connection.
Hope this helps