See Simple threaded chat server. The sweet things about threads, is that all threads can share the same filehandles thru the fileno, which can be passed thru shared variables.So... you can have your main thread do the accept on the connections, and hand them off to a set of threads, by passing the fileno to it. See where the thread itself can remove itself from a select list at the comment #remove multi-echo-clients from echo list.
But yes, it all basically works good together, threads and tcp.
| [reply] |
You can't pass objects between threads, so putting the TCP connection into the Thread::Queue will not work. But as the TCP connection is not reall y needed in the worker thread, you can store the TCP connection in a shared hash or keep it completely in the client and just send some ID with the request. When you get the ID back, you know which socket connection the answer belongs to.
| [reply] |