turn/ttorrent — pull request #70 by maxaf (2013-10-27 16:16:53+00:00)
Title: Use a Selector in IncomingThread in order to rectify excessive CPU use

Instead of abusing `SocketChannel.read` in a tight loop, use a `Selector` to tell us when a peer incoming channel is ready to read.

This fixes excessive CPU usage when running a peer over a slow link. In that case, an `IncomingThread` would spend >90% of its time repeatedly calling `SocketChannel.read`. Observed CPU use was in excess of 350% on a quad-core MacBook Air.

My gut feeling is that `OutgoingThread` might benefit from a similar change, but I have yet to observe any need for it.