Handle close control messages properly

This is essentially the same as the previous pull request.  Note that the test suite won't compile without the newQCGen change from the subprotocol pull request, and I have only run the javascript tests on the merge of these two pulls.