I need to write a server that's perhaps closest to an ALG (application-level gateway) in organization: it has pairs of TCP sockets, and takes data from one socket and writes it back onto the matching socket, and vice versa.
The state associated with each socket is very lightweight, and once the associations are set up there is no processing other than moving bits around.
I thought I would do this as a thread pool that dispatches on data being readable on the entire universe of sockets.
A thread gets activated by a "read-ready" on a socket, figures out what the matching writable socket is, takes the min() of the amount of readable data and the available space on the writable socket, reads that much, writes that much, and then puts itself back into the pool.
Something akin to how Apache works, in that any thread can service any connection request, and there is no explicit or implicit affinity.
Can someone point me at a server that does this?