Fix issue #183 (CPU 100% usage)

As per http://docs.python.org/2/howto/sockets.html#using-a-socket it's
possible that a socket recv() call returns 0 bytes if the remote closes
the connection. In that case, recv() does not obey settimeout(): it
just doesn't block and returns zero bytes immediately, which in this
case results in an infinite loop if the transmission was incomplete.
Merge pull request #277 from pgimeno/cpu100percentfix

Fix issue #183 (CPU 100% usage)
Merge pull request #275 from fuzzgun/master

Altered Makefile to avoid needing to chase changes
Better fix for issue #183

The former patch was too local; this one integrates better with the structure of the code.
Merge pull request #281 from pgimeno/cpu100percentfix

Better fix for issue #183