Keepalives may help in situations where RST packets are being blocked by a firewall or otherwise do not arrive. The C code uses select on all reads so it should never block, but add keepalives just in case. Suggested by Ronan Dunklau.