Fixed cancelling of downloads

Throwing an exception back to the set_writefunction handler seemed to be
causing some nasty problems.