Created: 2014/04/26 18:46:14+0000

I've started working on a TCP proxy. I inherited the code for one at work which wasn't very good. We also had three different versions of it lying around. I spent a morning replacing them with a cleaner, single implementation. I wasn't very happy with it because it took the same approach to threading as the one it replaced. Spawn two threads for each proxied connection. So I decided to do an implementation that did not continuously spawn threads.

This meant using non-blocking I/O and a fixed number of threads. There are three threads, one for accepting connections, one for reading data and one for writing data. A queue is used to pass work from the reading thread to the writing thread. It works, it could work better. I have to use locks around the queue to ensure the batching is thread safe. I'll keep working on it.

You should take a look: