Deal with shutdowns more safely

I found that if I called Quit, sometimes the Disconnect would happen whilst a callback was in progress and a write end up being sent to the now closed channel, causing the app to panic.

This patch adds in two more channels to kill the read and write loops early so that the above scenario can't happen, which the disconnect now triggers before closing the channels.