Added clean close method

Hi dhbaird,
I've added the close handshake. Let me know if all works!

By the way it now appears necessary to integrate a trick to break the infinite "poll & dispatch" loop when the closing procedure comes to end.

Have a good day :)