Add close option to allow sending of all messages before closing
This is useful in error conditions when you want to send a message
and then close the connection.